helm.generate.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. fi
  24. if [[ "$CRDS_FLAG_NAME" == *"Cluster"* ]]; then
  25. echo "{{- if and (.Values.installCRDs) (.Values.crds.$CRDS_FLAG_NAME) }}" > "$i"
  26. elif [[ "$CRDS_FLAG_NAME" == *"PushSecret"* ]]; then
  27. echo "{{- if and (.Values.installCRDs) (.Values.crds.$CRDS_FLAG_NAME) }}" > "$i"
  28. else
  29. echo "{{- if .Values.installCRDs }}" > "$i"
  30. fi
  31. cat "$i.bkp" >> "$i"
  32. echo "{{- end }}" >> "$i"
  33. rm "$i.bkp"
  34. $SEDPRG -i 's/name: kubernetes/name: {{ include "external-secrets.fullname" . }}-webhook/g' "$i"
  35. $SEDPRG -i 's/namespace: default/namespace: {{ .Release.Namespace | quote }}/g' "$i"
  36. $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"
  37. mv "$i" "${i%.yml}.yaml"
  38. done