helm.generate.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  4. BUNDLE_DIR="${1}"
  5. HELM_DIR="${2}"
  6. if [[ "$OSTYPE" == "darwin"* ]]; then
  7. SEDPRG="gsed"
  8. else
  9. SEDPRG="sed"
  10. fi
  11. cd "${SCRIPT_DIR}"/../
  12. # Split the generated bundle yaml file to inject control flags
  13. yq e -Ns "\"${HELM_DIR}/templates/crds/\" + .spec.names.singular" ${BUNDLE_DIR}/bundle.yaml
  14. # Add helm if statement for controlling the install of CRDs
  15. for i in "${HELM_DIR}"/templates/crds/*.yml; do
  16. export CRDS_FLAG_NAME="create$(yq e '.spec.names.kind' "${i}")"
  17. cp "$i" "$i.bkp"
  18. if [[ "${CRDS_FLAG_NAME}" == *"ExternalSecret"* || "${CRDS_FLAG_NAME}" == *"SecretStore"* ]]; then
  19. yq e '(.spec.versions[] | select(.name == "v1alpha1")) |= ("{{- if .Values.crds.conversion.enabled }}\n \(.)\n {{- end }}")' -i "$i.bkp" || true
  20. $SEDPRG -i '/- |-/d' "$i.bkp"
  21. # Indent the remaining additionalPrinterColumn property right
  22. $SEDPRG -i 's/ additionalPrinterColumns:/ - additionalPrinterColumns:/' "$i.bkp"
  23. # Replace served: false with templated value for v1beta1
  24. $SEDPRG -i '/name: v1beta1/,/served: false/{s/served: false/served: {{ .Values.crds.unsafeServeV1Beta1 }}/}' "$i.bkp"
  25. fi
  26. if [[ "${CRDS_FLAG_NAME}" == *"Cluster"* ]]; then
  27. echo "{{- if and (.Values.installCRDs) (.Values.crds.$CRDS_FLAG_NAME) }}" > "$i"
  28. elif [[ "${CRDS_FLAG_NAME}" == *"PushSecret"* ]]; then
  29. echo "{{- if and (.Values.installCRDs) (.Values.crds.$CRDS_FLAG_NAME) }}" > "$i"
  30. else
  31. echo "{{- if .Values.installCRDs }}" > "$i"
  32. fi
  33. cat "$i.bkp" >> "$i"
  34. echo "{{- end }}" >> "$i"
  35. rm "$i.bkp"
  36. $SEDPRG -i 's/name: kubernetes/name: {{ include "external-secrets.fullname" . }}-webhook/g' "$i"
  37. $SEDPRG -i 's/namespace: default/namespace: {{ .Release.Namespace | quote }}/g' "$i"
  38. $SEDPRG -i '0,/annotations/!b;//a\ {{- with .Values.crds.annotations }}\n {{- toYaml . | nindent 4}}\n {{- end }}\n {{- if and .Values.crds.conversion.enabled .Values.webhook.certManager.enabled .Values.webhook.certManager.addInjectorAnnotations }}\n cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "external-secrets.fullname" . }}-webhook\n {{- end }}' "$i"
  39. mv "$i" "${i%.yml}.yaml"
  40. done