diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 09da2bf6f60..bcd34e3984b 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -19,12 +19,16 @@ jobs: - runner: ubuntu-latest name: amd64 steps: - - name: Check out code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 with: fetch-depth: 1 + - name: Install prerequisites + run: | + apt-get update + apt-get install -y jq python3-yaml + - name: Register workspace path run: git config --global --add safe.directory "$GITHUB_WORKSPACE" diff --git a/CHANGELOG.md b/CHANGELOG.md index dd14e97d968..c3c8ed1b4d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Here is an overview of all new **experimental** features: ### Fixes +- **General**: Check for missing CRD references and sample CRs ([#5920](https://github.com/kedacore/keda/issues/5920)) - **General**: Scalers are properly closed after being refreshed ([#5806](https://github.com/kedacore/keda/issues/5806)) - **MongoDB Scaler**: MongoDB url parses correctly `+srv` scheme ([#5760](https://github.com/kedacore/keda/issues/5760)) diff --git a/config/samples/keda_v1alpha1_clustertriggerauthentication.yaml b/config/samples/keda_v1alpha1_clustertriggerauthentication.yaml new file mode 100644 index 00000000000..b0ab1ec8f67 --- /dev/null +++ b/config/samples/keda_v1alpha1_clustertriggerauthentication.yaml @@ -0,0 +1,9 @@ +apiVersion: keda.sh/v1alpha1 +kind: ClusterTriggerAuthentication +metadata: + name: example-clustertriggerauthentication +spec: + secretTargetRef: + - parameter: example-secret-parameter + name: example-secret-name + key: example-role-key diff --git a/config/samples/keda_v1alpha1_triggerauthentication.yaml b/config/samples/keda_v1alpha1_triggerauthentication.yaml index a4733a1d4ac..0bc49056653 100644 --- a/config/samples/keda_v1alpha1_triggerauthentication.yaml +++ b/config/samples/keda_v1alpha1_triggerauthentication.yaml @@ -1,4 +1,4 @@ -apiVersion: keda.k8s.io/v1alpha1 +apiVersion: keda.sh/v1alpha1 kind: TriggerAuthentication metadata: name: example-triggerauthentication diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 9ef860d16a0..94ec29e2c3a 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -1,5 +1,7 @@ ## Append samples you want in your CSV to this file as resources ## resources: +- eventing_v1alpha1_cloudeventsource.yaml +- keda_v1alpha1_clustertriggerauthentication.yaml - keda_v1alpha1_scaledobject.yaml - keda_v1alpha1_scaledjob.yaml - keda_v1alpha1_triggerauthentication.yaml diff --git a/hack/verify-manifests.sh b/hack/verify-manifests.sh index 74c8b8a2b05..31816755274 100755 --- a/hack/verify-manifests.sh +++ b/hack/verify-manifests.sh @@ -30,6 +30,55 @@ cleanup() { } trap "cleanup" EXIT SIGINT +yaml2json() { + python3 -c 'import json, sys, yaml ; y=yaml.safe_load(sys.stdin.read()) ; json.dump(y, sys.stdout)' +} + +if ! python3 -c "import yaml" >/dev/null 2>&1; then + echo "Python module 'yaml' required for this script." + exit 1 +fi + +# Make sure all the CRDs are listed in the kustomize resource list +declare -A crds +declare -A crs +while read -r filename; do + crds["$filename"]=1 +done < <(sed -n '/^resources:$/,/^[^-]/ s#^- ##p' config/crd/kustomization.yaml) +bad_crd_resource_list=0 +for f in config/crd/bases/*.yaml; do + key="bases/$(basename "$f")" + if [ ! -v "crds[${key}]" ]; then + echo "ERROR: CRD file $f is not listed in the resources section of config/crd/kustomization.yaml" + bad_crd_resource_list=1 + else + crs[$key]="$(yaml2json < $f | jq -r '.spec.names.singular as $k | (.spec.group | sub("\\..*"; "")) as $g | .spec.versions[] | ($g+"_"+.name+"_"+$k)')" + fi +done + +# Make sure all sample CRs are listed in the kustomize resource list (part 1) +declare -A crslist +while read -r filename; do + if ! test -f "$filename"; then + crslist["$filename"]=1 + fi +done < <(sed -n '/^resources:$/,/^[^-]/ s#^- ##p' config/samples/kustomization.yaml) + +# Make sure there is a sample CR for each CRD version +for key in ${!crs[@]}; do + for gvk in ${crs[$key]}; do + if [ ! -f "config/samples/${gvk}.yaml" ]; then + echo "ERROR: CRD config/crd/$key does not have a sample CR config/samples/$gvk.yaml" + bad_crd_resource_list=1 + fi + # Make sure all sample CRs are listed in the kustomize resource list (part 2) + if [ ! -v "crslist[${gvk}.yaml]" ]; then + echo "ERROR: CR config/samples/${gvk}.yaml is not listed in the resources section of config/samples/kustomization.yaml" + bad_crd_resource_list=1 + fi + done +done + cleanup mkdir -p "${TMP_DIFFROOT}" @@ -47,3 +96,8 @@ else echo "${DIFFROOT} is out of date. Please run 'make manifests'" exit 1 fi + +if [ "$bad_crd_resource_list" != 0 ]; then + echo "Check failed due to previous errors. See output above" + exit 1 +fi