From ddfd39199e3463ff5b752a6f7ecc2dbbdb19bb6f Mon Sep 17 00:00:00 2001 From: "Roland C. Dowdeswell" Date: Wed, 24 Mar 2021 20:56:52 +0000 Subject: [PATCH] refactor charts --- charts/tezos/templates/_containers.tpl | 180 +++++++++++++++++++++++++ charts/tezos/templates/baker.yaml | 173 ++---------------------- charts/tezos/templates/node.yaml | 135 +------------------ 3 files changed, 194 insertions(+), 294 deletions(-) create mode 100644 charts/tezos/templates/_containers.tpl diff --git a/charts/tezos/templates/_containers.tpl b/charts/tezos/templates/_containers.tpl new file mode 100644 index 000000000..1ad18df38 --- /dev/null +++ b/charts/tezos/templates/_containers.tpl @@ -0,0 +1,180 @@ +{{- define "tezos.localvars.pod_envvars" }} +- name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP +- name: MY_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name +- name: MY_NODE_TYPE +{{- if contains "baker" .Template.Name }} + value: {{ .Values.baker_statefulset.node_type }} +{{- else }} + value: {{ .Values.regular_node_statefulset.node_type }} +{{- end }} +{{- end }} + +{{- define "tezos.init_container.config_generator" }} +- image: {{ .Values.tezos_k8s_images.config_generator }} + imagePullPolicy: IfNotPresent + name: config-generator + args: + - "--generate-config-json" + envFrom: + - secretRef: + name: tezos-secret + - configMapRef: + name: tezos-config + env: +{{- include "tezos.localvars.pod_envvars" . | indent 4 }} + volumeMounts: + - mountPath: /etc/tezos + name: config-volume + - mountPath: /var/tezos + name: var-volume +{{- end }} + +{{- define "tezos.init_container.wait_for_bootstrap" }} +{{- if include "tezos.shouldWaitForBootstrapNode" . }} +- image: {{ .Values.tezos_k8s_images.wait_for_bootstrap }} + imagePullPolicy: IfNotPresent + name: wait-for-bootstrap + envFrom: + - configMapRef: + name: tezos-config + volumeMounts: + - mountPath: /var/tezos + name: var-volume +{{- end }} +{{- end }} + +{{- define "tezos.init_container.snapshot_downloader" }} +{{- if include "tezos.shouldDownloadSnapshot" . }} +- image: "{{ .Values.tezos_k8s_images.snapshot_downloader }}" + imagePullPolicy: IfNotPresent + name: snapshot-downloader + volumeMounts: + - mountPath: /var/tezos + name: var-volume + - mountPath: /etc/tezos + name: config-volume + envFrom: + - configMapRef: + name: tezos-config + env: +{{- include "tezos.localvars.pod_envvars" . | indent 4 }} +{{- end }} +{{- end }} + +{{- define "tezos.container.node" }} +- args: + - run + - "--bootstrap-threshold" + - '0' + - "--config-file" + - /etc/tezos/config.json + command: + - /usr/local/bin/tezos-node + image: "{{ .Values.images.tezos }}" + imagePullPolicy: IfNotPresent + name: tezos-node + ports: + - containerPort: 8732 + name: tezos-rpc + - containerPort: 9732 + name: tezos-net + volumeMounts: + - mountPath: /etc/tezos + name: config-volume + - mountPath: /var/tezos + name: var-volume +{{- end }} + +{{- define "tezos.container.baker" }} +- image: "{{ .Values.tezos_k8s_images.baker_endorser }}" + imagePullPolicy: IfNotPresent + name: baker + volumeMounts: + - mountPath: /var/tezos + name: var-volume + envFrom: + - configMapRef: + name: tezos-config + - secretRef: + name: tezos-secret + env: +{{- include "tezos.localvars.pod_envvars" . | indent 4 }} + - name: DAEMON + value: baker +{{- end }} + +{{- define "tezos.container.endorser" }} +- image: "{{ .Values.tezos_k8s_images.baker_endorser }}" + imagePullPolicy: IfNotPresent + name: endorser + volumeMounts: + - mountPath: /var/tezos + name: var-volume + envFrom: + - configMapRef: + name: tezos-config + - secretRef: + name: tezos-secret + env: +{{- include "tezos.localvars.pod_envvars" . | indent 4 }} + - name: DAEMON + value: endorser +{{- end }} + +{{/* +// * The zerotier containers: +*/}} + +{{- define "tezos.init_container.zerotier" }} +{{- if (include "tezos.doesZerotierConfigExist" .) }} +- envFrom: + - configMapRef: + name: zerotier-config + image: "{{ .Values.tezos_k8s_images.zerotier }}" + imagePullPolicy: IfNotPresent + name: get-zerotier-ip + securityContext: + capabilities: + add: + - NET_ADMIN + - NET_RAW + - SYS_ADMIN + privileged: true + volumeMounts: + - mountPath: /var/tezos + name: var-volume + - mountPath: /dev/net/tun + name: dev-net-tun + env: +{{- include "tezos.localvars.pod_envvars" . | indent 4 }} +{{- end }} +{{- end }} + +{{- define "tezos.container.zerotier" }} +{{- if (include "tezos.doesZerotierConfigExist" .) }} +- args: + - "-c" + - "echo 'starting zerotier' && zerotier-one /var/tezos/zerotier" + command: + - sh + image: "{{ .Values.tezos_k8s_images.zerotier }}" + imagePullPolicy: IfNotPresent + name: zerotier + securityContext: + capabilities: + add: + - NET_ADMIN + - NET_RAW + - SYS_ADMIN + privileged: true + volumeMounts: + - mountPath: /var/tezos + name: var-volume +{{- end }} +{{- end }} diff --git a/charts/tezos/templates/baker.yaml b/charts/tezos/templates/baker.yaml index bf4d6654f..1b7af5680 100644 --- a/charts/tezos/templates/baker.yaml +++ b/charts/tezos/templates/baker.yaml @@ -77,172 +77,15 @@ spec: appType: tezos spec: containers: - - args: - - run - - "--bootstrap-threshold" - - '0' - - "--config-file" - - /etc/tezos/config.json - command: - - /usr/local/bin/tezos-node - image: "{{ .Values.images.tezos }}" - imagePullPolicy: IfNotPresent - name: tezos-node - ports: - - containerPort: 8732 - name: tezos-rpc - - containerPort: 9732 - name: tezos-net - volumeMounts: - - mountPath: /etc/tezos - name: config-volume - - mountPath: /var/tezos - name: var-volume - - image: "{{ .Values.tezos_k8s_images.baker_endorser }}" - imagePullPolicy: IfNotPresent - name: baker - volumeMounts: - - mountPath: /var/tezos - name: var-volume - envFrom: - - configMapRef: - name: tezos-config - - secretRef: - name: tezos-secret - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.baker_statefulset.node_type }} - - name: DAEMON - value: baker - - image: "{{ .Values.tezos_k8s_images.baker_endorser }}" - imagePullPolicy: IfNotPresent - name: endorser - volumeMounts: - - mountPath: /var/tezos - name: var-volume - envFrom: - - configMapRef: - name: tezos-config - - secretRef: - name: tezos-secret - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.baker_statefulset.node_type }} - - name: DAEMON - value: endorser -{{- if (include "tezos.doesZerotierConfigExist" .) }} - - args: - - "-c" - - "echo 'starting zerotier' && zerotier-one /var/tezos/zerotier" - command: - - sh - image: "{{ .Values.tezos_k8s_images.zerotier }}" - imagePullPolicy: IfNotPresent - name: zerotier - securityContext: - capabilities: - add: - - NET_ADMIN - - NET_RAW - - SYS_ADMIN - privileged: true - volumeMounts: - - mountPath: /var/tezos - name: var-volume -{{- end }} +{{- include "tezos.container.node" . | indent 8 }} +{{- include "tezos.container.baker" . | indent 8 }} +{{- include "tezos.container.endorser" . | indent 8 }} +{{- include "tezos.container.zerotier" . | indent 8 }} initContainers: -{{- if include "tezos.shouldWaitForBootstrapNode" . }} - - image: {{ .Values.tezos_k8s_images.wait_for_bootstrap }} - imagePullPolicy: IfNotPresent - name: wait-for-bootstrap - envFrom: - - configMapRef: - name: tezos-config - volumeMounts: - - mountPath: /var/tezos - name: var-volume -{{- end }} -{{- if (include "tezos.doesZerotierConfigExist" .) }} - - envFrom: - - configMapRef: - name: zerotier-config - image: "{{ .Values.tezos_k8s_images.zerotier }}" - imagePullPolicy: IfNotPresent - name: get-zerotier-ip - securityContext: - capabilities: - add: - - NET_ADMIN - - NET_RAW - - SYS_ADMIN - privileged: true - volumeMounts: - - mountPath: /var/tezos - name: var-volume - - mountPath: /dev/net/tun - name: dev-net-tun - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.baker_statefulset.node_type }} -{{- end }} - - image: {{ .Values.tezos_k8s_images.config_generator }} - imagePullPolicy: IfNotPresent - name: config-generator - args: - - "--generate-config-json" - envFrom: - - secretRef: - name: tezos-secret - - configMapRef: - name: tezos-config - env: - - name: MY_POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.baker_statefulset.node_type }} - volumeMounts: - - mountPath: /etc/tezos - name: config-volume - - mountPath: /var/tezos - name: var-volume -{{- if include "tezos.shouldDownloadSnapshot" . }} - - image: "{{ .Values.tezos_k8s_images.snapshot_downloader }}" - imagePullPolicy: IfNotPresent - name: snapshot-downloader - volumeMounts: - - mountPath: /var/tezos - name: var-volume - - mountPath: /etc/tezos - name: config-volume - envFrom: - - configMapRef: - name: tezos-config - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.baker_statefulset.node_type }} -{{- end }} +{{- include "tezos.init_container.wait_for_bootstrap" . | indent 8 }} +{{- include "tezos.init_container.zerotier" . | indent 8 }} +{{- include "tezos.init_container.config_generator" . | indent 8 }} +{{- include "tezos.init_container.snapshot_downloader" . | indent 8 }} securityContext: fsGroup: 100 volumes: diff --git a/charts/tezos/templates/node.yaml b/charts/tezos/templates/node.yaml index f0a6c04f1..ccaabb1e9 100644 --- a/charts/tezos/templates/node.yaml +++ b/charts/tezos/templates/node.yaml @@ -18,136 +18,13 @@ spec: appType: tezos spec: containers: - - args: - - run - - "--config-file" - - /etc/tezos/config.json - command: - - /usr/local/bin/tezos-node - image: {{ .Values.images.tezos | quote }} - imagePullPolicy: IfNotPresent - name: tezos-node - ports: - - containerPort: 8732 - name: tezos-rpc - - containerPort: 9732 - name: tezos-p2p - volumeMounts: - - mountPath: /etc/tezos - name: config-volume - - mountPath: /var/tezos - name: var-volume -{{- if (include "tezos.doesZerotierConfigExist" .) }} - - args: - - "-c" - - "echo 'starting zerotier' && zerotier-one /var/tezos/zerotier" - - "-P" - - '8732' - - "-d" - - /var/tezos/client - - run - - baker - command: - - sh - image: "{{ .Values.tezos_k8s_images.zerotier }}" - imagePullPolicy: IfNotPresent - name: zerotier - securityContext: - capabilities: - add: - - NET_ADMIN - - NET_RAW - - SYS_ADMIN - privileged: true - volumeMounts: - - mountPath: /var/tezos - name: var-volume -{{- end }} +{{- include "tezos.container.node" . | indent 8 }} +{{- include "tezos.container.zerotier" . | indent 8 }} initContainers: -{{- if include "tezos.shouldWaitForBootstrapNode" . }} - - image: {{ .Values.tezos_k8s_images.wait_for_bootstrap }} - imagePullPolicy: IfNotPresent - name: wait-for-bootstrap - envFrom: - - configMapRef: - name: tezos-config - volumeMounts: - - mountPath: /var/tezos - name: var-volume -{{- end }} -{{- if (include "tezos.doesZerotierConfigExist" .) }} - - envFrom: - - configMapRef: - name: zerotier-config - image: "{{ .Values.tezos_k8s_images.zerotier }}" - imagePullPolicy: IfNotPresent - name: get-zerotier-ip - securityContext: - capabilities: - add: - - NET_ADMIN - - NET_RAW - - SYS_ADMIN - privileged: true - volumeMounts: - - mountPath: /var/tezos - name: var-volume - - mountPath: /dev/net/tun - name: dev-net-tun - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.regular_node_statefulset.node_type }} -{{- end }} - - image: {{ .Values.tezos_k8s_images.config_generator }} - imagePullPolicy: IfNotPresent - name: config-generator - args: - - "--generate-config-json" - envFrom: - - secretRef: - name: tezos-secret - - configMapRef: - name: tezos-config - env: - - name: MY_POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.regular_node_statefulset.node_type }} - volumeMounts: - - mountPath: /etc/tezos - name: config-volume - - mountPath: /var/tezos - name: var-volume -{{- if include "tezos.shouldDownloadSnapshot" . }} - - image: "{{ .Values.tezos_k8s_images.snapshot_downloader }}" - imagePullPolicy: IfNotPresent - name: snapshot-downloader - volumeMounts: - - mountPath: /var/tezos - name: var-volume - - mountPath: /etc/tezos - name: config-volume - envFrom: - - configMapRef: - name: tezos-config - env: - - name: MY_POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: MY_NODE_TYPE - value: {{ .Values.regular_node_statefulset.node_type }} -{{- end }} +{{- include "tezos.init_container.wait_for_bootstrap" . | indent 8 }} +{{- include "tezos.init_container.zerotier" . | indent 8 }} +{{- include "tezos.init_container.config_generator" . | indent 8 }} +{{- include "tezos.init_container.snapshot_downloader" . | indent 8 }} securityContext: fsGroup: 100 volumes: