Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework migrations #247

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# testkube-cloud-charts

Internal Helm charts for Testkube Cloud

TEST
52 changes: 22 additions & 30 deletions charts/testkube-cloud-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -137,49 +137,41 @@ Define API image
{{- end -}}
{{- end -}}

{{/*
Define Migration image
*/}}
{{- define "testkube-migration.image" -}}
{{- $registryName := default "docker.io" .Values.migrationImage.registry -}}
{{- $repositoryName := .Values.migrationImage.repository -}}
{{- $tag := default .Chart.AppVersion .Values.migrationImage.tag | toString -}}
{{- $separator := ":" -}}
{{- if .Values.migrationImage.digest }}
{{- $separator = "@" -}}
{{- $tag = .Values.migrationImage.digest | toString -}}
{{- end -}}
{{- if .Values.global }}
{{- if .Values.global.imageRegistry }}
{{- printf "%s/%s%s%s" .Values.global.imageRegistry $repositoryName $separator $tag -}}
{{- else -}}
{{- printf "%s/%s%s%s" $registryName $repositoryName $separator $tag -}}
{{- end -}}
{{- else -}}
{{- 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 -}}
{{- define "testkube-cloud-api.toolbox-image" -}}
{{- $registryName := default "docker.io" .Values.toolboxImage.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 -}}
{{- $repositoryName := .Values.toolboxImage.repository -}}
{{- $tag := default .Chart.AppVersion .Values.toolboxImage.tag | toString -}}
{{- $separator := ":" -}}
{{- if .Values.init.mongo.image.digest -}}
{{- if .Values.toolboxImage.digest -}}
{{- $separator = "@" -}}
{{- $tag = .Values.init.mongo.image.digest | toString -}}
{{- $tag = .Values.toolboxImage.digest | toString -}}
{{- end -}}

{{- printf "%s/%s%s%s" $registryName $repositoryName $separator $tag -}}
{{- end -}}

{{- define "testkube-cloud-api.jobNameSuffix" -}}
{{- if .Values.global.job.nameSuffixOverride -}}
{{- tpl .Values.global.job.nameSuffixOverride . -}}
{{- else -}}
{{- printf "%s-%s-%s" .Chart.Version .Chart.AppVersion ( .Values | toYaml | b64enc ) | sha256sum | trunc 7 -}}
{{- end -}}
{{- end -}}

{{- define "testkube-cloud-api.migration-jobname" -}}
{{- $fname := printf "%s-migration" (include "testkube-cloud-api.fullname" .) | trunc 55 | trimSuffix "-" -}}
{{- $name := $fname | trunc 55 | trimSuffix "-" -}}
{{- $suffix := ( include "testkube-cloud-api.jobNameSuffix" . )}}
{{- printf "%s-%s" $name $suffix | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Define podSecurityContext
*/}}
Expand Down Expand Up @@ -211,4 +203,4 @@ Define containerSecurityContext for Init Container
{{- else }}
{{- toYaml .Values.init.mongo.containerSecurityContext }}
{{- end }}
{{- end }}
{{- end }}
27 changes: 2 additions & 25 deletions charts/testkube-cloud-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,6 @@ spec:
{{- end }}
serviceAccountName: {{ include "testkube-cloud-api.serviceAccountName" . }}
securityContext: {{ include "testkube-cloud-api.podSecurityContext" . | nindent 8 }}
{{- if .Values.init.enabled }}
initContainers:
- name: wait-for-mongo
image: {{ include "testkube-cloud-api.init-mongo-image" . }}
imagePullPolicy: {{ .Values.init.mongo.image.pullPolicy }}
securityContext: {{ include "init-wait-for-mongo.containerSecurityContext" . | nindent 12 }}
command: ["/bin/sh", "-c"]
args:
- |
until mongosh "$API_MONGO_DSN" --eval "print('MongoDB is ready')" > /dev/null 2>&1; do
echo "Waiting for MongoDB ($API_MONGO_DSN) to become ready..."
sleep 5
done
echo "MongoDB is ready"
env:
- name: API_MONGO_DSN
{{- if (or .Values.global.mongo.dsnSecretRef .Values.api.mongo.dsnSecretRef) }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.global.mongo.dsnSecretRef | default .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.global.mongo.dsn | default .Values.api.mongo.dsn }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext: {{ include "testkube-cloud-api.containerSecurityContext" . | nindent 12 }}
Expand Down Expand Up @@ -458,6 +433,8 @@ spec:
value: "{{ .Values.api.storage.cleanup.retentionDays }}"
- name: ENTERPRISE_ARTIFACT_MAX_STORAGE_SIZE_GB
value: "{{ .Values.api.storage.cleanup.maxStorageSizeGb }}"
- name: MIGRATION_MIGRATE_DATABASE
value: "{{ .Values.api.migrations.enabled | quote }}"
ports:
- name: {{ if .Values.api.tls.serveHTTPS }}https{{ else }}http{{ end }}
containerPort: {{ if .Values.api.tls.serveHTTPS }}{{ .Values.api.tls.apiPort }}{{ else }}8090{{ end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "testkube-cloud-api.migration-jobname" . }}
labels:
{{- include "testkube-cloud-api.labels" . | nindent 4 }}
annotations:
{{- if .Values.api.migrations.useHelmHooks }}
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "-1"
{{- end }}
name: {{ include "testkube-cloud-api.fullname" . }}-migrations
{{- if .Values.api.migrations.useArgoHook }}
"argocd.argoproj.io/hook": "sync"
"argocd.argoproj.io/hook-delete-policy": "BeforeHookCreation"
{{- end }}
spec:
{{- if .Values.api.migrations.ttlSecondsAfterFinished }}
backoffLimit: 3
ttlSecondsAfterFinished: {{ .Values.api.migrations.ttlSecondsAfterFinished }}
{{- end }}
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -35,7 +34,10 @@ spec:
securityContext: {{ include "testkube-cloud-api.podSecurityContext" . | nindent 8 }}
containers:
- name: migrations
image: {{ include "testkube-migration.image" . }}
image: {{ include "testkube-cloud-api.toolbox-image" . }}
imagePullPolicy: {{ .Values.toolboxImage.pullPolicy }}
command: ["/testkube/toolbox"]
args: ["database", "migrations", "up"]
securityContext: {{ include "testkube-cloud-api.containerSecurityContext" . | nindent 12 }}
env:
- name: ENTERPRISE_MODE
Expand All @@ -51,23 +53,28 @@ spec:
value: {{ .Values.payments.apiKey }}
{{- end }}
{{- end }}
{{- $mongoDsnSecretRef := .Values.global.mongo.dsnSecretRef | default .Values.api.mongo.dsnSecretRef }}
{{- $mongoDsn := .Values.global.mongo.dsn | default .Values.api.mongo.dsn }}
{{- if $mongoDsnSecretRef }}
- name: API_MONGO_DSN
{{- if .Values.api.mongo.dsnSecretRef }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.api.mongo.dsn }}
{{- end }}
name: {{ $mongoDsnSecretRef }}
{{- else if $mongoDsn }}
- name: API_MONGO_DSN
value: {{ $mongoDsn }}
{{- end }}
{{- $mongoDatabase := .Values.global.mongo.database | default .Values.api.mongo.database }}
- name: API_MONGO_DB
value: {{ .Values.api.mongo.database }}
value: {{ $mongoDatabase }}
- name: MIGRATION_IGNORE_NO_DB_ERROR
value: "{{ .Values.api.migrations.ignoreNoDbError }}"
- name: MIGRATION_INIT_INDEXES
value: "false"
value: "true"
- name: MIGRATION_MIGRATE_DATABASE
value: "true"
- name: HELLO
value: "world"
restartPolicy: Never
backoffLimit: 3
{{- end }}
83 changes: 0 additions & 83 deletions charts/testkube-cloud-api/templates/migrations-indexes-job.yaml

This file was deleted.

27 changes: 4 additions & 23 deletions charts/testkube-cloud-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ image:
repository: kubeshop/testkube-cloud-api
pullPolicy: IfNotPresent
tag: "1.10.89"
migrationImage:
toolboxImage:
# -- If defined, it will prepend the registry to the image name, if not, default docker.io will be prepended
registry: ""
repository: kubeshop/testkube-migration
repository: kubeshop/testkube-toolbox
pullPolicy: IfNotPresent
tag: "0.0.7"
tag: "latest"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
Expand All @@ -140,24 +141,6 @@ enterpriseLicenseKeyPath: /testkube/license.key
enterpriseLicenseFilePath: /testkube/license.lic
# -- Api can allow to set demo organization id where user who don't have Kubernetes cluster can play around
demoOrganizationId: ""
## Init block defines settings for the dependency check containers
init:
# -- Toggle whether to enable the dependency check containers
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: ""
# -- Init container Security Context
containerSecurityContext: {}
analytics:
segmentio:
# -- Toggle whether to enable Segment.io analytics
Expand Down Expand Up @@ -207,8 +190,6 @@ api:
migrations:
# -- Toggle whether to apply migrations for MongoDB
enabled: true
# -- Toggle whether to enable pre-install & pre-upgrade hooks
useHelmHooks: true
# -- TTL for the migration job, defaults to 4 days
ttlSecondsAfterFinished: 345600
# -- Ignoring no db error - exit 0 - used when helm hooks are enabled on pre-install
Expand Down
2 changes: 2 additions & 0 deletions charts/testkube-enterprise/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ dependencies:
- name: testkube-cloud-api
version: 1.122.0
repository: file://../testkube-cloud-api
condition: testkube-cloud-api.enabled
- name: testkube-cloud-ui
version: 1.84.0
repository: file://../testkube-cloud-ui
condition: testkube-cloud-ui.enabled
- name: testkube-worker-service
version: 1.48.0
repository: file://../testkube-worker-service
Expand Down
Loading
Loading