crd.generate.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. CRD_DIR="${2}"
  6. BUNDLE_YAML="${BUNDLE_DIR}/bundle.yaml"
  7. cd "${SCRIPT_DIR}"/../
  8. go run sigs.k8s.io/controller-tools/cmd/controller-gen \
  9. object:headerFile="hack/boilerplate.go.txt" \
  10. paths="./apis/..."
  11. go run sigs.k8s.io/controller-tools/cmd/controller-gen crd \
  12. paths="./apis/..." \
  13. output:crd:artifacts:config="${CRD_DIR}/bases"
  14. ## Update resources list from kustomization.yaml
  15. ls "${CRD_DIR}"/bases | grep -v "kustomization.yaml" | jq -R -s -c 'split("\n")[:-1]' | yq -p=json - > kustomize-files.yaml
  16. yq -i '.resources = (load("kustomize-files.yaml"))' "${CRD_DIR}"/bases/kustomization.yaml
  17. rm kustomize-files.yaml
  18. # Remove extra header lines in generated CRDs
  19. # This is needed for building the helm chart
  20. for f in "${CRD_DIR}"/bases/*.yaml; do
  21. if [[ $f == *kustomization.yaml ]];
  22. then
  23. continue;
  24. fi;
  25. tail -n +2 < "$f" > "$f.bkp"
  26. cp "$f.bkp" "$f"
  27. rm "$f.bkp"
  28. done
  29. shopt -s extglob
  30. yq e "${CRD_DIR}"/bases/!(kustomization).yaml > "${BUNDLE_YAML}"