{{- if .Values.mollysocket.vapidKey.create }} --- {{- $fullname := (include "mollysocket.fullname" .) }} apiVersion: batch/v1 kind: Job metadata: name: {{ $fullname }}-setup labels: {{- include "mollysocket.labels" . | nindent 4 }} app.kubernetes.io/component: setup-job annotations: "helm.sh/hook": pre-install,pre-upgrade "helm.sh/hook-weight": "5" "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded spec: template: metadata: labels: {{- include "mollysocket.labels" . | nindent 8 }} app.kubernetes.io/component: setup-job spec: restartPolicy: "Never" serviceAccount: {{ $fullname }}-setup initContainers: - name: generate-config {{- with $.Values.image }} image: "{{ coalesce $.Values.global.image.registry .registry }}/{{ .repository }}:{{ .tag | default $.Chart.AppVersion }}" imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }} {{- end }} command: - sh - -c - mollysocket vapid generate > /data/output volumeMounts: - mountPath: /data/ name: data containers: - name: upload-config {{- with $.Values.kubectl.image }} image: "{{ coalesce $.Values.global.image.registry .registry }}/{{ .repository }}:{{ .tag }}" imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }} {{- end }} command: - sh - -c - | # check if key already exists key=$(kubectl get secret {{ $fullname }} -o jsonpath="{.data['ms_vapid_key']}" 2> /dev/null) [ $? -ne 0 ] && echo "Failed to get existing secret" && exit 1 [ -n "$key" ] && echo "Config already created, exiting." && exit 0 # update secret kubectl patch secret {{ $fullname }} -p '{"data":{"ms_vapid_key":"'$(cat /data/output | base64 -w 0)'"}}' [ $? -ne 0 ] && echo "Failed to update secret." && exit 1 echo "VAPID successfully setup" volumeMounts: - mountPath: /data/ name: data readOnly: true volumes: - name: data emptyDir: {} parallelism: 1 completions: 1 backoffLimit: 1 {{- end }}