From ef1bb9b7eee5869e168f6362f7438890c2ffc853 Mon Sep 17 00:00:00 2001 From: Echoz Date: Tue, 28 May 2024 15:18:38 +0200 Subject: [PATCH] Centralize job hash generation and incorporate chart version in it (#30) refactor: centralize job hash generation and incorporate chart version in it --- templates/_helpers.tpl | 7 +++++++ templates/bulker/deployment.yaml | 4 ++-- templates/console/deployment.yaml | 4 ++-- templates/event-log-init/job.yaml | 4 ++-- templates/event-log-trim/cronjob.yaml | 4 ++-- templates/ingest/deployment.yaml | 2 +- templates/migration/job.yaml | 4 ++-- templates/rotor/deployment.yaml | 2 +- templates/syncctl/deployment.yaml | 4 ++-- templates/token-generator/job.yaml | 2 +- 10 files changed, 22 insertions(+), 15 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index a267969..63474db 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -50,6 +50,13 @@ app.kubernetes.io/name: {{ include "jitsu.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Hash, used as a unique label for the Chart version + value set +*/}} +{{- define "jitsu.hash" -}} +{{- sha1sum (printf "%s%s" (toJson .Values) (.Chart.Version)) | substr 0 8 -}} +{{- end }} + {{/* Create the name of the service account to use */}} diff --git a/templates/bulker/deployment.yaml b/templates/bulker/deployment.yaml index 78dd461..682a21d 100644 --- a/templates/bulker/deployment.yaml +++ b/templates/bulker/deployment.yaml @@ -44,7 +44,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.clickhouse.enabled }} - name: wait-for-clickhouse @@ -80,7 +80,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.console.enabled }} - name: wait-for-console diff --git a/templates/console/deployment.yaml b/templates/console/deployment.yaml index 94bb0ef..6b7e8f7 100644 --- a/templates/console/deployment.yaml +++ b/templates/console/deployment.yaml @@ -44,7 +44,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.clickhouse.enabled }} - name: wait-for-clickhouse @@ -62,7 +62,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ include "jitsu.hash" . }}"] {{- end }} containers: - name: {{ .Chart.Name }} diff --git a/templates/event-log-init/job.yaml b/templates/event-log-init/job.yaml index 243bb8e..6c42004 100644 --- a/templates/event-log-init/job.yaml +++ b/templates/event-log-init/job.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "jitsu.fullname" . }}-event-log-init-{{ sha1sum (toJson .Values) | substr 0 8 }} + name: {{ include "jitsu.fullname" . }}-event-log-init-{{ include "jitsu.hash" . }} labels: {{- include "jitsu.labels" . | nindent 4 }} {{- with .Values.eventLogInit.jobAnnotations }} @@ -38,7 +38,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.console.enabled }} - name: wait-for-console diff --git a/templates/event-log-trim/cronjob.yaml b/templates/event-log-trim/cronjob.yaml index 23bbcf2..1012636 100644 --- a/templates/event-log-trim/cronjob.yaml +++ b/templates/event-log-trim/cronjob.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: CronJob metadata: - name: {{ include "jitsu.fullname" . }}-event-log-trim-{{ sha1sum (toJson .Values) | substr 0 8 }} + name: {{ include "jitsu.fullname" . }}-event-log-trim labels: {{- include "jitsu.labels" . | nindent 4 }} {{- with .Values.eventLogTrim.jobAnnotations }} @@ -41,7 +41,7 @@ spec: {{- toYaml . | nindent 16 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.console.enabled }} - name: wait-for-console diff --git a/templates/ingest/deployment.yaml b/templates/ingest/deployment.yaml index a82d6cb..dbedb7e 100644 --- a/templates/ingest/deployment.yaml +++ b/templates/ingest/deployment.yaml @@ -40,7 +40,7 @@ spec: {{- if .Values.tokenGenerator.enabled }} - name: wait-for-tokens image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.clickhouse.enabled }} - name: wait-for-clickhouse diff --git a/templates/migration/job.yaml b/templates/migration/job.yaml index 3100e60..c8a30fc 100644 --- a/templates/migration/job.yaml +++ b/templates/migration/job.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "jitsu.fullname" . }}-migration-{{ sha1sum (toJson .Values) | substr 0 8 }} + name: {{ include "jitsu.fullname" . }}-migration-{{ include "jitsu.hash" . }} labels: {{- include "jitsu.labels" . | nindent 4 }} {{- with .Values.migration.jobAnnotations }} @@ -38,7 +38,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.postgresql.enabled }} - name: wait-for-postgresql diff --git a/templates/rotor/deployment.yaml b/templates/rotor/deployment.yaml index 5e52185..821616a 100644 --- a/templates/rotor/deployment.yaml +++ b/templates/rotor/deployment.yaml @@ -44,7 +44,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.clickhouse.enabled }} - name: wait-for-clickhouse diff --git a/templates/syncctl/deployment.yaml b/templates/syncctl/deployment.yaml index 4a565ee..c3648e2 100644 --- a/templates/syncctl/deployment.yaml +++ b/templates/syncctl/deployment.yaml @@ -44,7 +44,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }}"] {{- end }} {{- if .Values.migration.enabled }} - name: wait-for-migration @@ -53,7 +53,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} image: ghcr.io/groundnuty/k8s-wait-for:v2.0 - args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ sha1sum (toJson .Values) | substr 0 8 }}"] + args: ["job-wr", "{{ include "jitsu.fullname" . }}-migration-{{ include "jitsu.hash" . }}"] {{- end }} containers: - name: {{ .Chart.Name }} diff --git a/templates/token-generator/job.yaml b/templates/token-generator/job.yaml index 454bad0..b09308b 100644 --- a/templates/token-generator/job.yaml +++ b/templates/token-generator/job.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "jitsu.fullname" . }}-token-generator-{{ sha1sum (toJson .Values) | substr 0 8 }} + name: {{ include "jitsu.fullname" . }}-token-generator-{{ include "jitsu.hash" . }} labels: {{- include "jitsu.labels" . | nindent 4 }} {{- with .Values.tokenGenerator.jobAnnotations }}