Skip to content

Commit

Permalink
Merge pull request #4 from santiment/feature/Add_optimism_chart
Browse files Browse the repository at this point in the history
Add optimism helm chart
  • Loading branch information
ivan-genev authored Jul 26, 2022
2 parents 08f3c8b + a649ab2 commit feac2c3
Show file tree
Hide file tree
Showing 16 changed files with 820 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/optimism/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
13 changes: 13 additions & 0 deletions charts/optimism/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
description: Helm chart for optimism node
name: optimism
version: 0.0.1
appVersion: master
keywords:
- Optimism
- Ethereum L2 blockchain
home: https://www.optimism.io/
sources:
- https://github.com/ethereum-optimism/optimism
maintainers:
- name: Ivan Genev
2 changes: 2 additions & 0 deletions charts/optimism/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Optimism
=====
22 changes: 22 additions & 0 deletions charts/optimism/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.l2geth.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "optimism.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.l2geth.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "optimism.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "optimism.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.l2geth.service.port }}
{{- else if contains "ClusterIP" .Values.l2geth.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "optimism.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
5 changes: 5 additions & 0 deletions charts/optimism/templates/_helper_l2geth.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# l2geth configs go here
[Node.HTTPTimeouts]
ReadTimeout = 120000000000
WriteTimeout = 120000000000
IdleTimeout = 120000000000
37 changes: 37 additions & 0 deletions charts/optimism/templates/_helper_l2geth_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
set -exu

echo running "${0}"
if [[ -z $DATADIR ]]; then
echo "Must pass DATADIR"
exit 1
fi

GETH_CHAINDATA_DIR=$DATADIR/geth/chaindata
GETH_KEYSTORE_DIR=$DATADIR/keystore
if [ ! -d "$GETH_KEYSTORE_DIR" ]; then
echo "$GETH_KEYSTORE_DIR missing, running account import"
echo -n "$BLOCK_SIGNER_PRIVATE_KEY_PASSWORD" > "$DATADIR"/password
echo -n "$BLOCK_SIGNER_PRIVATE_KEY" > "$DATADIR"/block-signer-key
geth account import \
--datadir="$DATADIR" \
--password="$DATADIR"/password \
"$DATADIR"/block-signer-key
echo "get account import complete"
fi
if [ ! -d "$GETH_CHAINDATA_DIR" ]; then
echo "$GETH_CHAINDATA_DIR missing, running init"
geth init --datadir="$DATADIR" "$L2GETH_GENESIS_URL" "$L2GETH_GENESIS_HASH"
echo "geth init complete"
else
echo "$GETH_CHAINDATA_DIR exists, checking for hardfork."
echo "Chain config:"
geth dump-chain-cfg --datadir="$DATADIR"
if geth dump-chain-cfg --datadir="$DATADIR" | grep -q "\"berlinBlock\": $L2GETH_BERLIN_ACTIVATION_HEIGHT"; then
echo "Hardfork already activated."
else
echo "Hardfork not activated, running init."
geth init --datadir="$DATADIR" "$L2GETH_GENESIS_URL" "$L2GETH_GENESIS_HASH"
echo "geth hardfork activation complete"
fi
fi
29 changes: 29 additions & 0 deletions charts/optimism/templates/_helper_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
upstream {{ template "optimism.proxyname" . }} {
server localhost:{{ .Values.l2geth.service.rpc.port }};
}

{{- if .Values.proxy.logFormat }}
log_format rpc escape=none
{{- range .Values.proxy.logFormat }}
'{{ . }}'
{{- end }};
{{- end }}

server {
listen {{ .Values.proxy.port }};
location / {
proxy_pass http://{{ template `optimism.proxyname` . }};
{{- if .Values.proxy.serverConfig }}
{{- range .Values.proxy.serverConfig }}
{{ . }}
{{- end }}
{{- end }}
{{- if .Values.proxy.logFormat }}
access_log /var/log/nginx/access.log rpc;
{{- end }}
}
location /nginx_status {
stub_status;
access_log off;
}
}
106 changes: 106 additions & 0 deletions charts/optimism/templates/_helpers.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "optimism.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "optimism.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Determine volume name.
*/}}
{{- define "optimism.volumename" -}}
{{- if .Values.l2geth.persistence.VolumeName -}}
{{- printf "%s" .Values.l2geth.persistence.VolumeName | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" (include "optimism.fullname" .) "data" | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Determine dtl name.
*/}}
{{- define "optimism.dtlname" -}}
{{- printf "%s-%s" (include "optimism.name" .) "dtl" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Determine dtl full name.
*/}}
{{- define "optimism.dtlfullname" -}}
{{- printf "%s-%s" (include "optimism.fullname" .) "dtl" | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Determine dtl volume name.
*/}}
{{- define "optimism.dtlvolumename" -}}
{{- if .Values.l2geth.persistence.VolumeName -}}
{{- printf "%s" .Values.dtl.persistence.VolumeName | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" (include "optimism.dtlfullname" .) "db" | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Determine l2geth roolup address.
*/}}
{{- define "optimism.dtlservice" -}}
{{- printf "http://%s.%s:%s" (include "optimism.dtlfullname" .) .Release.Namespace .Values.dtl.service.dtl.port }}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "optimism.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for statefulset.
*/}}
{{- define "optimism.statefulset.apiVersion" -}}
{{- if .Capabilities.APIVersions.Has "apps/v1beta2" -}}
{{- print "apps/v1beta2" -}}
{{- else -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Determine service account name for statefulset.
*/}}
{{- define "optimism.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "optimism.fullname" .) .Values.serviceAccount.name | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- default "default" .Values.serviceAccount.name -}}
{{- end -}}
{{- end -}}

{{/*
Determine proxy name for statefulset.
*/}}
{{- define "optimism.proxyname" -}}
{{- if .Values.proxy.enabled -}}
{{- printf "%s-%s" .Chart.Name "proxy" | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
31 changes: 31 additions & 0 deletions charts/optimism/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "optimism.fullname" . }}
labels:
app: {{ template "optimism.name" . }}
chart: {{ template "optimism.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
init.sh: |
{{ include (print $.Template.BasePath "/_helper_l2geth_init.sh") . | indent 4 }}
l2geth.toml: |
{{ include (print $.Template.BasePath "/_helper_l2geth.toml") . | indent 4 }}

---
{{- if .Values.proxy.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "optimism.proxyname" . }}
labels:
app: {{ template "optimism.name" . }}
chart: {{ template "optimism.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
nginx.conf: |
{{ include (print $.Template.BasePath "/_helper_nginx.conf") . | indent 4 }}
{{- end }}
64 changes: 64 additions & 0 deletions charts/optimism/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "optimism.fullname" . -}}
{{- $svcPort := .Values.l2geth.service.rpc.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ template "optimism.dtlname" . }}
chart: {{ template "optimism.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/optimism/templates/service_dtl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "optimism.dtlfullname" . }}
labels:
app: {{ template "optimism.dtlname" . }}
chart: {{ template "optimism.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.dtl.service.annotations }}
annotations:
{{ toYaml .Values.dtl.service.annotations | indent 4 }}
{{- end }}
spec:
type: {{ .Values.dtl.service.type }}
ports:
- name: dtl
port: {{ .Values.dtl.service.dtl.port }}
targetPort: {{ .Values.dtl.service.dtl.port }}
protocol: TCP
selector:
app: {{ template "optimism.dtlname" . }}
release: {{ .Release.Name }}
27 changes: 27 additions & 0 deletions charts/optimism/templates/service_l2geth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "optimism.fullname" . }}
labels:
app: {{ template "optimism.name" . }}
chart: {{ template "optimism.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.l2geth.service.annotations }}
annotations:
{{ toYaml .Values.l2geth.service.annotations | indent 4 }}
{{- end }}
spec:
type: {{ .Values.l2geth.service.type }}
ports:
- name: l2geth
port: {{ .Values.l2geth.service.rpc.port }}
{{- if .Values.proxy.enabled }}
targetPort: {{ .Values.proxy.port }}
{{- else }}
targetPort: {{ .Values.l2geth.service.rpc.port }}
{{- end }}
protocol: TCP
selector:
app: {{ template "optimism.name" . }}
release: {{ .Release.Name }}
Loading

0 comments on commit feac2c3

Please sign in to comment.