Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional manifest checks to detect missing CRDs & CRs #5921

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion config/samples/keda_v1alpha1_triggerauthentication.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: keda.k8s.io/v1alpha1
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: example-triggerauthentication
Expand Down
2 changes: 2 additions & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
54 changes: 54 additions & 0 deletions hack/verify-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Loading