adjusting validation check to find files not containing new cert-manager domain
#!/usr/bin/env bash
-# cainjection*
-# cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
+invalid_files=$(grep -L "cert-manager.io" ./config/crd/patches/cainjection*.yaml)
-# go to project root directory
-cd $(dirname "${BASH_SOURCE[0]}")/..
+# using a subshell to not modify the IFS variable that determines how the expression "${arr[*]}" is output
+# this workaround allows us to reject an array containing empty elements
+(IFS='' ; [[ -n "${invalid_files[*]}" ]] ); is_empty=$?
-old_certmgr_str="certmanager.k8s.io/inject-ca-from"
-old_certmgr_files=$(grep -Hino "$old_certmgr_str" ./config/crd/patches/cainjection*.yaml)
-if [ ${#old_certmgr_files[@]} -gt 0 ]; then
+# fail validation if the array is not empty
+if [[ $is_empty -eq 0 ]]; then
echo "Validation check failed for the following files:"
- for file in $old_certmgr_files; do
+ for file in $invalid_files; do
echo " $file"
done
echo "Run the following command to fix the files:"
- echo " sed -i '' 's/certmanager.k8s.io/certmanager.io/' ./config/crd/patches/cainjection*.yaml"
+ echo " sed -i '' 's/certmanager.k8s.io/cert-manager.io/' ./config/crd/patches/cainjection*.yaml"
exit 1
fi
