From d025177e199e607458a2808b69289a8c34a71ab5 Mon Sep 17 00:00:00 2001 From: Dejan Zele Pejchev Date: Tue, 13 Aug 2024 09:59:43 +0200 Subject: [PATCH] add support for defining registry for wait for mongo init container --- .../testkube-cloud-api/templates/_helpers.tpl | 20 +++++++++++++++++++ .../templates/deployment.yaml | 2 +- .../templates/migrations-job.yaml | 4 +++- charts/testkube-cloud-api/values.yaml | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/charts/testkube-cloud-api/templates/_helpers.tpl b/charts/testkube-cloud-api/templates/_helpers.tpl index 432ef25fd..9013214b7 100644 --- a/charts/testkube-cloud-api/templates/_helpers.tpl +++ b/charts/testkube-cloud-api/templates/_helpers.tpl @@ -134,3 +134,23 @@ Define API image {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $tag -}} {{- end -}} {{- end -}} + +{{/* +Define Mongo init image +TODO: Implement this using dict and reuse the same for each image +*/}} +{{- define "testkube-cloud-api.init-mongo-image" -}} +{{- $registryName := default "docker.io" .Values.init.mongo.image.registry -}} +{{- if .Values.global.imageRegistry -}} + {{- $registryName = .Values.global.imageRegistry -}} +{{- end -}} +{{- $repositoryName := .Values.init.mongo.image.repository -}} +{{- $tag := default .Chart.AppVersion .Values.init.mongo.image.tag | toString -}} +{{- $separator := ":" -}} +{{- if .Values.init.mongo.image.digest -}} + {{- $separator = "@" -}} + {{- $tag = .Values.init.mongo.image.digest | toString -}} +{{- end -}} + +{{- printf "%s/%s%s%s" $registryName $repositoryName $separator $tag -}} +{{- end -}} \ No newline at end of file diff --git a/charts/testkube-cloud-api/templates/deployment.yaml b/charts/testkube-cloud-api/templates/deployment.yaml index 1d0f517eb..b67275f99 100644 --- a/charts/testkube-cloud-api/templates/deployment.yaml +++ b/charts/testkube-cloud-api/templates/deployment.yaml @@ -33,7 +33,7 @@ spec: {{- if .Values.init.enabled }} initContainers: - name: wait-for-mongo - image: {{ .Values.init.mongo.image.repository }}:{{ .Values.init.mongo.image.tag }} + image: {{ include "testkube-cloud-api.init-mongo-image" . }} imagePullPolicy: {{ .Values.init.mongo.image.pullPolicy }} command: ["/bin/sh", "-c"] args: diff --git a/charts/testkube-cloud-api/templates/migrations-job.yaml b/charts/testkube-cloud-api/templates/migrations-job.yaml index 6b0e43413..d4747608a 100644 --- a/charts/testkube-cloud-api/templates/migrations-job.yaml +++ b/charts/testkube-cloud-api/templates/migrations-job.yaml @@ -34,9 +34,10 @@ spec: serviceAccountName: {{ include "testkube-cloud-api.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.init.enabled }} initContainers: - name: wait-for-mongo - image: alpine/mongosh:2.0.2 + image: {{ include "testkube-cloud-api.init-mongo-image" . }} command: ["/bin/sh", "-c"] args: - | @@ -55,6 +56,7 @@ spec: {{- else }} value: {{ .Values.global.mongo.dsn | default .Values.api.mongo.dsn }} {{- end }} + {{- end }} containers: - name: migrations image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/charts/testkube-cloud-api/values.yaml b/charts/testkube-cloud-api/values.yaml index 4db072d36..7a555bbd9 100644 --- a/charts/testkube-cloud-api/values.yaml +++ b/charts/testkube-cloud-api/values.yaml @@ -113,12 +113,16 @@ init: enabled: false mongo: image: + # -- MongoSH image registry + registry: "docker.io" # -- MongoSH image repository repository: alpine/mongosh # -- MongoSH image tag tag: 2.0.2 # -- MongoSH image pull policy pullPolicy: IfNotPresent + # -- MongoSH image digest + digest: "" analytics: segmentio: # -- Toggle whether to enable Segment.io analytics