diff --git a/charts/geth-swap/.helmignore b/charts/geth-swap/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/geth-swap/.helmignore @@ -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/ diff --git a/charts/geth-swap/Chart.yaml b/charts/geth-swap/Chart.yaml new file mode 100644 index 0000000..28fd68c --- /dev/null +++ b/charts/geth-swap/Chart.yaml @@ -0,0 +1,26 @@ +apiVersion: v1 +name: geth-swap +description: A Helm chart for Kubernetes +home: https://swarm.ethereum.org + +maintainers: + - name: ralph-pichler + email: pichler.ralph@gmail.com + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +version: 0.1.3 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. +appVersion: 1.16.0 diff --git a/charts/geth-swap/templates/_helpers.tpl b/charts/geth-swap/templates/_helpers.tpl new file mode 100644 index 0000000..a705747 --- /dev/null +++ b/charts/geth-swap/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "geth-swap.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 "geth-swap.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 -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "geth-swap.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "geth-swap.labels" -}} +helm.sh/chart: {{ include "geth-swap.chart" . }} +{{ include "geth-swap.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "geth-swap.selectorLabels" -}} +app.kubernetes.io/name: {{ include "geth-swap.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "geth-swap.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "geth-swap.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/charts/geth-swap/templates/deployment.yaml b/charts/geth-swap/templates/deployment.yaml new file mode 100644 index 0000000..9afeae7 --- /dev/null +++ b/charts/geth-swap/templates/deployment.yaml @@ -0,0 +1,87 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "geth-swap.fullname" . }} + labels: + {{- include "geth-swap.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "geth-swap.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "geth-swap.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "geth-swap.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + volumes: + - name: geth-config + configMap: + name: {{ include "geth-swap.fullname" . }}-config + - name: datadir + emptyDir: {} + initContainers: + - name: geth-setup + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sh + - -ac + - > + set -xe; + geth account import --password /dev/null /etc/config/validatorKey; + geth init /etc/config/genesis.json; + volumeMounts: + - name: geth-config + mountPath: /etc/config + - name: datadir + mountPath: /root/.ethereum + containers: + - name: geth + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: rpc + containerPort: 8545 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: geth-config + mountPath: /etc/config + - name: datadir + mountPath: /root/.ethereum + command: + - geth + - --rpc + - --rpcaddr + - "0.0.0.0" + - --rpcvhosts + - "*" + - --allow-insecure-unlock + - --unlock + - {{ .Values.geth.genesis.validatorAddress }} + - --password + - /dev/null + - --mine + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/geth-swap/templates/genesis.configmap.yaml b/charts/geth-swap/templates/genesis.configmap.yaml new file mode 100644 index 0000000..3ad7f2d --- /dev/null +++ b/charts/geth-swap/templates/genesis.configmap.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "geth-swap.fullname" . }}-config +data: + networkid: {{ .Values.geth.genesis.networkid | quote }} + validatorKey: {{ .Values.geth.genesis.validatorKey | quote }} + genesis.json: |- + { + "config": { + "chainId": {{ .Values.geth.genesis.networkid }}, + "homesteadBlock": 0, + "eip150Block": 0, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "eip155Block": 0, + "eip158Block": 0, + "byzantiumBlock": 0, + "constantinopleBlock": 0, + "petersburgBlock": 0, + "istanbulBlock": 0, + "clique": { + "period": {{ .Values.geth.genesis.clique.period }}, + "epoch": {{ .Values.geth.genesis.clique.epoch }} + } + }, + "nonce": "0x0", + "timestamp": "0x5e4bc3a6", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000{{ .Values.geth.genesis.validatorAddress }}0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x47b760", + "difficulty": "0x1", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "alloc": { + {{- range $i := until 256 }} + {{ $i | printf "%040x" | quote }}: { + "balance": "0x1" + }, + {{- end}} + {{- range $i, $account := .Values.geth.genesis.accounts }} + {{if $i}},{{end}}{{ $account.addr | quote }}: { + "balance": {{ $account.wei | quote }} + } + {{- end }} + }, + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + } \ No newline at end of file diff --git a/charts/geth-swap/templates/ingress.yaml b/charts/geth-swap/templates/ingress.yaml new file mode 100644 index 0000000..0f2d516 --- /dev/null +++ b/charts/geth-swap/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "geth-swap.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "geth-swap.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- 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: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/geth-swap/templates/service.yaml b/charts/geth-swap/templates/service.yaml new file mode 100644 index 0000000..41dcde6 --- /dev/null +++ b/charts/geth-swap/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "geth-swap.fullname" . }} + labels: + {{- include "geth-swap.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: rpc + protocol: TCP + name: rpc + selector: + {{- include "geth-swap.selectorLabels" . | nindent 4 }} diff --git a/charts/geth-swap/templates/serviceaccount.yaml b/charts/geth-swap/templates/serviceaccount.yaml new file mode 100644 index 0000000..d6d1898 --- /dev/null +++ b/charts/geth-swap/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "geth-swap.serviceAccountName" . }} + labels: + {{- include "geth-swap.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end -}} diff --git a/charts/geth-swap/templates/setupcontracts.yaml b/charts/geth-swap/templates/setupcontracts.yaml new file mode 100644 index 0000000..7be49f9 --- /dev/null +++ b/charts/geth-swap/templates/setupcontracts.yaml @@ -0,0 +1,27 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "geth-swap.fullname" . }}-setupcontracts + labels: + {{- include "geth-swap.labels" . | nindent 4 }} +spec: + template: + spec: + containers: + - name: setup + image: bash:3.2 + env: + - name: BACKEND + value: "http://{{ include "geth-swap.fullname" . }}:8545" + - name: BZZACCOUNTS + value: {{ .Values.swap.bzzaccounts | join " " }} + command: + - sh + - -ac + - > + apk add --no-cache jq curl; + curl https://gist.githubusercontent.com/ralph-pichler/dc0386f81ffa09c220271d4389b4a139/raw -o deploy.sh; + while curl $BACKEND; do sleep 1; done; + bash deploy.sh + restartPolicy: Never + backoffLimit: 1 diff --git a/charts/geth-swap/templates/tests/test-connection.yaml b/charts/geth-swap/templates/tests/test-connection.yaml new file mode 100644 index 0000000..3bee118 --- /dev/null +++ b/charts/geth-swap/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "geth-swap.fullname" . }}-test-connection" + labels: + {{- include "geth-swap.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "geth-swap.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/geth-swap/values.yaml b/charts/geth-swap/values.yaml new file mode 100644 index 0000000..2963d51 --- /dev/null +++ b/charts/geth-swap/values.yaml @@ -0,0 +1,71 @@ +# Default values for geth-swap. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ethereum/client-go + tag: latest + pullPolicy: IfNotPresent + +geth: + genesis: + networkid: 12345 + clique: + period: 15 + epoch: 30000 + validatorAddress: 62cab2b3b55f341f10348720ca18063cdb779ad5 + validatorKey: 4663c222787e30c1994b59044aa5045377a6e79193a8ead88293926b535c722d + accounts: + - addr: "62cab2b3b55f341f10348720ca18063cdb779ad5" + wei: "0xf0000000000000000000000000" + +swap: + bzzaccounts: + - cD604B06F0A015269b34c2a8DC8C779535c24B2f + - c029885FCeedD27623f3293cD892460B528e33E2 + - DCD36E29Ed55a66F6A3dB114dFcDe7ef1Fb4b346 + - 894A9BfAf6dFe917F0F61bbDcC3096Cd5eA77F2A + - 666f30fD950Cc8A8Db93f9C7d86Bb0B14cb1773A + - CD51767481E08aa21eF38Ff346726b61521A3D37 + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: false + annotations: {} + name: + +podSecurityContext: {} + +securityContext: {} + +service: + type: ClusterIP + port: 8545 + +ingress: + enabled: false + annotations: {} + tls: [] + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {}