1
+ ---
2
+ # Migrates the TLS CA keypair from the hard-coded default namespace to the operator namespace
3
+ # See https://github.com/stackabletech/secret-operator/issues/453
4
+ apiVersion : batch/v1
5
+ kind : Job
6
+ metadata :
7
+ name : {{ include "operator.fullname" . }}-secret-migration
8
+ annotations :
9
+ " helm.sh/hook " : pre-install
10
+ " helm.sh/hook-delete-policy " : hook-succeeded
11
+ " helm.sh/hook-weight " : " -5"
12
+ labels :
13
+ {{- include "operator.labels" . | nindent 4 }}
14
+ spec :
15
+ template :
16
+ metadata :
17
+ {{- with .Values.podAnnotations }}
18
+ annotations :
19
+ {{- toYaml . | nindent 8 }}
20
+ {{- end }}
21
+ labels :
22
+ {{- include "operator.selectorLabels" . | nindent 8 }}
23
+ spec :
24
+ {{- with .Values.image.pullSecrets }}
25
+ imagePullSecrets :
26
+ {{- toYaml . | nindent 8 }}
27
+ {{- end }}
28
+ serviceAccountName : {{ include "operator.fullname" . }}-secret-migration-serviceaccount
29
+ securityContext :
30
+ {{- toYaml .Values.podSecurityContext | nindent 8 }}
31
+ containers :
32
+ - name : migrate-secret
33
+ image : " {{ .Values.secretMigrationJob.image.repository }}:1.0.0-stackable{{ .Chart.AppVersion }}"
34
+ imagePullPolicy : {{ .Values.secretMigrationJob.image.pullPolicy }}
35
+ resources :
36
+ {{ .Values.secretMigrationJob.resources | toYaml | nindent 12 }}
37
+ command : ["bash", "-c"]
38
+ args :
39
+ - |
40
+ #!/bin/bash
41
+ set -euo pipefail
42
+ SOURCE_NAMESPACE=default
43
+ TARGET_NAMESPACE={{ .Values.secretClasses.tls.caSecretNamespace | default .Release.Namespace }}
44
+
45
+ # only continue if secret exists
46
+ if source_ca_secret="$(kubectl get secret -n $SOURCE_NAMESPACE secret-provisioner-tls-ca -o json)"; then
47
+ echo "secret exists in namespace $SOURCE_NAMESPACE"
48
+ # only continue if secret in target namespace does NOT exist
49
+ if ! kubectl get secret -n $TARGET_NAMESPACE secret-provisioner-tls-ca; then
50
+ echo "secret does not exist in namespace $TARGET_NAMESPACE"
51
+ # copy secret from default to {{ .Values.secretClasses.tls.caSecretNamespace | default .Release.Namespace }}
52
+ echo "$source_ca_secret" | jq 'del(.metadata["namespace","creationTimestamp","resourceVersion","selfLink","uid"])' | kubectl apply -n $TARGET_NAMESPACE -f -
53
+ fi
54
+ fi
55
+ restartPolicy : Never
0 commit comments