|
| 1 | +{{- if index .Values "stac-auth-proxy" "enabled" }} |
| 2 | +{{- if index .Values "stac-auth-proxy" "initContainers" }} |
| 3 | +# NOTE: This hook patches the stac-auth-proxy deployment to add initContainers. |
| 4 | +# Since Helm hooks run AFTER all resources (including subcharts) are installed, |
| 5 | +# the deployment will start once without initContainers, then be patched and rolled out. |
| 6 | +# This is a temporary workaround until upstream stac-auth-proxy chart adds native initContainers support. |
| 7 | +apiVersion: batch/v1 |
| 8 | +kind: Job |
| 9 | +metadata: |
| 10 | + name: {{ .Release.Name }}-stac-auth-proxy-patch |
| 11 | + namespace: {{ .Release.Namespace }} |
| 12 | + labels: |
| 13 | + {{- include "eoapi.labels" . | nindent 4 }} |
| 14 | + annotations: |
| 15 | + helm.sh/hook: "post-install,post-upgrade" |
| 16 | + helm.sh/hook-weight: "5" |
| 17 | + helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded" |
| 18 | +spec: |
| 19 | + template: |
| 20 | + metadata: |
| 21 | + labels: |
| 22 | + {{- include "eoapi.labels" . | nindent 8 }} |
| 23 | + spec: |
| 24 | + restartPolicy: Never |
| 25 | + serviceAccountName: {{ include "eoapi.serviceAccountName" . }} |
| 26 | + containers: |
| 27 | + - name: patch-deployment |
| 28 | + image: bitnami/kubectl:latest |
| 29 | + imagePullPolicy: IfNotPresent |
| 30 | + command: |
| 31 | + - /bin/bash |
| 32 | + - -c |
| 33 | + - | |
| 34 | + set -e |
| 35 | + DEPLOYMENT_NAME="{{ .Release.Name }}-stac-auth-proxy" |
| 36 | + NAMESPACE="{{ .Release.Namespace }}" |
| 37 | + echo "Waiting for deployment $DEPLOYMENT_NAME..." |
| 38 | + for i in {1..30}; do |
| 39 | + kubectl get deployment "$DEPLOYMENT_NAME" -n "$NAMESPACE" &>/dev/null && break |
| 40 | + sleep 2 |
| 41 | + done |
| 42 | + EXISTING_INIT=$(kubectl get deployment "$DEPLOYMENT_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.template.spec.initContainers}' 2>/dev/null || echo "") |
| 43 | + if [ -n "$EXISTING_INIT" ] && [ "$EXISTING_INIT" != "null" ]; then |
| 44 | + echo "Deployment already has initContainers, skipping" |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | + echo "Patching deployment with initContainers..." |
| 48 | + INIT_CONTAINERS_JSON='{{ index .Values "stac-auth-proxy" "initContainers" | toJson }}' |
| 49 | + kubectl patch deployment "$DEPLOYMENT_NAME" -n "$NAMESPACE" --type='json' -p="[{\"op\":\"add\",\"path\":\"/spec/template/spec/initContainers\",\"value\":$INIT_CONTAINERS_JSON}]" |
| 50 | + echo "Waiting for rollout..." |
| 51 | + kubectl rollout status deployment/"$DEPLOYMENT_NAME" -n "$NAMESPACE" --timeout=300s |
| 52 | + backoffLimit: 2 |
| 53 | +{{- end }} |
| 54 | +{{- end }} |
0 commit comments