From ee7a4d9630b52ab73e6128b1dc35e21b2b8d244d Mon Sep 17 00:00:00 2001 From: Mart van Santen <mart@greenhost.nl> Date: Thu, 21 Oct 2021 08:25:13 +0000 Subject: [PATCH] Embed patched migration job --- .../single-sign-on/templates/_helpers.tpl | 34 +++++++++++++++++++ .../templates/job-migration.yaml | 31 +++++++++-------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/helmchart/single-sign-on/templates/_helpers.tpl b/helmchart/single-sign-on/templates/_helpers.tpl index 7400884..1f32059 100644 --- a/helmchart/single-sign-on/templates/_helpers.tpl +++ b/helmchart/single-sign-on/templates/_helpers.tpl @@ -43,3 +43,37 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end -}} + +{{/* +Generate image +*/}} +{{- define "kratos-migration-job.image" -}} +{{- if eq "string" ( typeOf .Values.kratos.image ) }} +{{- printf "%s" .Values.kratos.image -}} +{{- else -}} +{{- printf "%s:%s" .Values.kratos.image.repository .Values.kratos.image.tag -}} +{{- end -}} +{{- end -}} + +{{/* +Generate imagePullPolicy +*/}} +{{- define "kratos-migration-job.imagePullPolicy" -}} +{{- if eq "string" ( typeOf .Values.kratos.image ) }} +{{- printf "%s" .Values.kratos.imagePullPolicy -}} +{{- else -}} +{{- printf "%s" .Values.kratos.image.pullPolicy -}} +{{- end -}} +{{- end -}} + +{{/* +Create a secret name which can be overridden. +*/}} +{{- define "kratos-migration-job.secretname" -}} +{{- if .Values.kratos.secret.nameOverride -}} +{{- .Values.kratos.secret.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{ include "single-sign-on.fullname" . }} +{{- end -}} +{{- end -}} + diff --git a/helmchart/single-sign-on/templates/job-migration.yaml b/helmchart/single-sign-on/templates/job-migration.yaml index 22149cf..0d2a03c 100644 --- a/helmchart/single-sign-on/templates/job-migration.yaml +++ b/helmchart/single-sign-on/templates/job-migration.yaml @@ -2,14 +2,14 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "kratos.fullname" . }}-automigrate + name: {{ include "single-sign-on.fullname" . }}-automigrate {{- if .Release.Namespace }} namespace: {{ .Release.Namespace }} {{- end }} labels: -{{ include "kratos.labels" . | indent 4 }} +{{ include "single-sign-on.labels" . | indent 4 }} annotations: - {{- with .Values.job.annotations }} + {{- with .Values.kratos.job.annotations }} {{- toYaml . | nindent 4 }} {{- end }} helm.sh/hook-weight: "1" @@ -17,38 +17,39 @@ metadata: helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded" spec: template: - {{- with .Values.job.annotations }} + {{- with .Values.kratos.job.annotations }} metadata: annotations: {{- toYaml . | nindent 8 }} {{- end }} spec: - automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} + automountServiceAccountToken: {{ .Values.kratos.automountServiceAccountToken }} containers: - name: {{ .Chart.Name }}-automigrate - image: {{ include "kratos.image" . }} - imagePullPolicy: {{ include "kratos.imagePullPolicy" . }} + image: {{ include "kratos-migration-job.image" . }} + imagePullPolicy: {{ include "kratos-migration-job.imagePullPolicy" . }} command: ["kratos"] args: ["migrate", "sql", "-e", "--yes"] env: - name: DSN valueFrom: secretKeyRef: - name: {{ include "kratos.secretname" . }} + name: "single-sign-on-kratos" + # name: {{ include "kratos-migration-job.secretname" . }} key: dsn securityContext: - {{- toYaml .Values.securityContext | nindent 10 }} - {{- if .Values.deployment.extraVolumeMounts }} + {{- toYaml .Values.kratos.securityContext | nindent 10 }} + {{- if .Values.kratos.deployment.extraVolumeMounts }} volumeMounts: -{{ toYaml .Values.deployment.extraVolumeMounts | indent 10 }} +{{ toYaml .Values.kratos.deployment.extraVolumeMounts | indent 10 }} {{- end }} restartPolicy: Never - {{- if .Values.deployment.extraInitContainers }} + {{- if .Values.kratos.deployment.extraInitContainers }} initContainers: -{{ tpl .Values.deployment.extraInitContainers . | indent 8 }} +{{ tpl .Values.kratos.deployment.extraInitContainers . | indent 8 }} {{- end }} - {{- if .Values.deployment.extraVolumes }} + {{- if .Values.kratos.deployment.extraVolumes }} volumes: -{{ toYaml .Values.deployment.extraVolumes | indent 8 }} +{{ toYaml .Values.kratos.deployment.extraVolumes | indent 8 }} {{- end }} backoffLimit: 10 -- GitLab