crd.generate.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  4. : "${CONTROLLER_GEN:?CONTROLLER_GEN must point to controller-gen}"
  5. BUNDLE_DIR="${1}"
  6. CRD_DIR="${2}"
  7. BUNDLE_YAML="${BUNDLE_DIR}/bundle.yaml"
  8. cd "${SCRIPT_DIR}"/../
  9. "${CONTROLLER_GEN}" \
  10. object:headerFile="hack/boilerplate.go.txt" \
  11. paths="./apis/..."
  12. "${CONTROLLER_GEN}" crd \
  13. paths="./apis/..." \
  14. output:crd:artifacts:config="${CRD_DIR}/bases"
  15. ## Update resources list from kustomization.yaml
  16. ls "${CRD_DIR}"/bases | grep -v "kustomization.yaml" | jq -R -s -c 'split("\n")[:-1]' | yq -p=json - > kustomize-files.yaml
  17. yq -i '.resources = (load("kustomize-files.yaml"))' "${CRD_DIR}"/bases/kustomization.yaml
  18. rm kustomize-files.yaml
  19. # Remove extra header lines in generated CRDs
  20. # This is needed for building the helm chart
  21. for f in "${CRD_DIR}"/bases/*.yaml; do
  22. if [[ $f == *kustomization.yaml ]];
  23. then
  24. continue;
  25. fi;
  26. tail -n +2 < "$f" > "$f.bkp"
  27. cp "$f.bkp" "$f"
  28. rm "$f.bkp"
  29. done
  30. shopt -s extglob
  31. yq e "${CRD_DIR}"/bases/!(kustomization).yaml > "${BUNDLE_YAML}"