diff --git a/Makefile b/Makefile index b6d15a5c9..e556529e6 100644 --- a/Makefile +++ b/Makefile @@ -145,15 +145,7 @@ fmt: lint.check ## Ensure consistent code style @$(OK) Ensured consistent code style generate: ## Generate code and crds - @go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." - @go run sigs.k8s.io/controller-tools/cmd/controller-gen crd paths="./..." output:crd:artifacts:config=$(CRD_DIR)/bases -# Remove extra header lines in generated CRDs - @for i in $(CRD_DIR)/bases/*.yaml; do \ - tail -n +2 <"$$i" >"$$i.bkp" && \ - cp "$$i.bkp" "$$i" && \ - rm "$$i.bkp"; \ - done - @yq e '.spec.conversion.strategy = "Webhook" | .spec.conversion.webhook.conversionReviewVersions = ["v1"] | .spec.conversion.webhook.clientConfig.service.name = "kubernetes" | .spec.conversion.webhook.clientConfig.service.namespace = "default" | .spec.conversion.webhook.clientConfig.service.path = "/convert"' $(CRD_DIR)/bases/* > $(BUNDLE_DIR)/bundle.yaml + @./hack/crd.generate.sh $(BUNDLE_DIR) $(CRD_DIR) @$(OK) Finished generating deepcopy and crds # ==================================================================================== @@ -190,31 +182,7 @@ helm.build: helm.generate ## Build helm chart @$(OK) helm package helm.generate: -# Split the generated bundle yaml file to inject control flags - @for i in $(BUNDLE_DIR)/*.yaml; do \ - yq e -Ns '"$(HELM_DIR)/templates/crds/" + .spec.names.singular' "$$i"; \ - done -# Add helm if statement for controlling the install of CRDs - @for i in $(HELM_DIR)/templates/crds/*.yml; do \ - export CRDS_FLAG_NAME="create$$(yq e '.spec.names.kind' $$i)"; \ - cp "$$i" "$$i.bkp"; \ - if [[ "$$CRDS_FLAG_NAME" == *"Cluster"* ]]; then \ - echo "{{- if and (.Values.installCRDs) (.Values.crds.$$CRDS_FLAG_NAME) }}" > "$$i"; \ - else \ - echo "{{- if .Values.installCRDs }}" > "$$i"; \ - fi; \ - cat "$$i.bkp" >> "$$i" && \ - echo "{{- end }}" >> "$$i" && \ - rm "$$i.bkp" && \ - if [[ "$$OSTYPE" == "darwin"* ]]; then \ - SEDPRG="gsed"; \ - else \ - SEDPRG="sed"; \ - fi; \ - $$SEDPRG -i 's/name: kubernetes/name: {{ include "external-secrets.fullname" . }}-webhook/g' "$$i" && \ - $$SEDPRG -i 's/namespace: default/namespace: {{ .Release.Namespace | quote }}/g' "$$i" && \ - mv "$$i" "$${i%.yml}.yaml"; \ - done + ./hack/helm.generate.sh $(BUNDLE_DIR) $(HELM_DIR) @$(OK) Finished generating helm chart files # ==================================================================================== diff --git a/config/crds/bases/kustomization.yaml b/config/crds/bases/kustomization.yaml new file mode 100644 index 000000000..fb90b9c42 --- /dev/null +++ b/config/crds/bases/kustomization.yaml @@ -0,0 +1,8 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - external-secrets.io_clusterexternalsecrets.yaml + - external-secrets.io_clustersecretstores.yaml + - external-secrets.io_externalsecrets.yaml + - external-secrets.io_secretstores.yaml diff --git a/hack/crd.generate.sh b/hack/crd.generate.sh new file mode 100755 index 000000000..28edcf1bd --- /dev/null +++ b/hack/crd.generate.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUNDLE_DIR="${1}" +CRD_DIR="${2}" +BUNDLE_YAML="${BUNDLE_DIR}/bundle.yaml" + +cd "${SCRIPT_DIR}"/../ + +go run sigs.k8s.io/controller-tools/cmd/controller-gen \ + object:headerFile="hack/boilerplate.go.txt" \ + paths="./..." +go run sigs.k8s.io/controller-tools/cmd/controller-gen crd \ + paths="./..." \ + output:crd:artifacts:config="${CRD_DIR}/bases" + +# Remove extra header lines in generated CRDs +# This is needed for building the helm chart +for f in "${CRD_DIR}"/bases/*.yaml; do + if [[ $f == *kustomization.yaml ]]; + then + continue; + fi; + tail -n +2 < "$f" > "$f.bkp" + cp "$f.bkp" "$f" + rm "$f.bkp" +done + +shopt -s extglob +yq e \ + '.spec.conversion.strategy = "Webhook" | .spec.conversion.webhook.conversionReviewVersions = ["v1"] | .spec.conversion.webhook.clientConfig.service.name = "kubernetes" | .spec.conversion.webhook.clientConfig.service.namespace = "default" | .spec.conversion.webhook.clientConfig.service.path = "/convert"' \ + "${CRD_DIR}"/bases/!(kustomization).yaml > "${BUNDLE_YAML}" diff --git a/hack/helm.generate.sh b/hack/helm.generate.sh new file mode 100755 index 000000000..836e68d12 --- /dev/null +++ b/hack/helm.generate.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUNDLE_DIR="${1}" +HELM_DIR="${2}" + +if [[ "$OSTYPE" == "darwin"* ]]; then + SEDPRG="gsed" +else + SEDPRG="sed" +fi + +cd "${SCRIPT_DIR}"/../ + +# Split the generated bundle yaml file to inject control flags +yq e -Ns "\"${HELM_DIR}/templates/crds/\" + .spec.names.singular" ${BUNDLE_DIR}/bundle.yaml + +# Add helm if statement for controlling the install of CRDs +for i in "${HELM_DIR}"/templates/crds/*.yml; do + export CRDS_FLAG_NAME="create$(yq e '.spec.names.kind' $i)" + cp "$i" "$i.bkp" + if [[ "$CRDS_FLAG_NAME" == *"Cluster"* ]]; then + echo "{{- if and (.Values.installCRDs) (.Values.crds.$CRDS_FLAG_NAME) }}" > "$i" + else + echo "{{- if .Values.installCRDs }}" > "$i" + fi + cat "$i.bkp" >> "$i" + echo "{{- end }}" >> "$i" + rm "$i.bkp" + $SEDPRG -i 's/name: kubernetes/name: {{ include "external-secrets.fullname" . }}-webhook/g' "$i" + $SEDPRG -i 's/namespace: default/namespace: {{ .Release.Namespace | quote }}/g' "$i" + mv "$i" "${i%.yml}.yaml" +done \ No newline at end of file