diff --git a/Makefile b/Makefile index 39cd316631..8bcd4fbff2 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,11 @@ test: cd "conformance/echo-basic" && go test -race -cover ./... cd "gwctl" && go test -race -cover ./... +# Run tests for CRDs validation +.PHONY: test.crds-validation +test.crds-validation: + ./hack/test-crds-validation.sh $(VERSION) + # Run conformance tests against controller implementation .PHONY: conformance conformance: diff --git a/hack/verify-crds-kind.sh b/hack/test-crds-validation.sh similarity index 72% rename from hack/verify-crds-kind.sh rename to hack/test-crds-validation.sh index 319224f1ac..8f17b78dc7 100755 --- a/hack/verify-crds-kind.sh +++ b/hack/test-crds-validation.sh @@ -41,15 +41,48 @@ cleanup() { trap cleanup INT TERM EXIT +# TODO(mlavacca): find a good way to keep this dependency up to date. +KIND_VERSION="v0.24.0" + +# list of kind images taken from https://github.com/kubernetes-sigs/kind/releases/tag/v0.24.0. +# they need to be updated when kind is updated. +KIND_IMAGES=( + "kindest/node:v1.27.17@sha256:3fd82731af34efe19cd54ea5c25e882985bafa2c9baefe14f8deab1737d9fabe" + "kindest/node:v1.28.13@sha256:45d319897776e11167e4698f6b14938eb4d52eb381d9e3d7a9086c16c69a8110" + "kindest/node:v1.29.8@sha256:d46b7aa29567e93b27f7531d258c372e829d7224b25e3fc6ffdefed12476d3aa" + "kindest/node:v1.30.4@sha256:976ea815844d5fa93be213437e3ff5754cd599b040946b5cca43ca45c2047" + "kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865" +) + +if [ "$#" -gt 1 ]; then + echo "Error: Too many arguments provided. Only 1 argument is allowed." + exit 1 +fi + +DEFAULT_INDEX=$((1)) + +if [ "$#" -eq 1 ]; then + # Check if the argument is a valid number between 1 and 5 + if ! [[ "$1" =~ ^[1-5] ]]; then + echo "Error: Argument is not a valid integer between 1 and 5." + exit 1 + fi + INDEX=$(($1)) +else + INDEX=$((DEFAULT_INDEX)) +fi + +K8S_IMAGE=${KIND_IMAGES[$((INDEX-1))]} + # For exit code res=0 # Install kind -(cd $GOPATH && go install sigs.k8s.io/kind@v0.20.0) || res=$? +(cd "${GOPATH}" && go install sigs.k8s.io/kind@${KIND_VERSION}) || res=$? # Create cluster KIND_CREATE_ATTEMPTED=true -kind create cluster --name "${CLUSTER_NAME}" +kind create cluster --name "${CLUSTER_NAME}" --image "${K8S_IMAGE}" || res=$? # Verify CEL validation for CHANNEL in experimental standard; do diff --git a/hack/verify-all.sh b/hack/verify-all.sh index 2f67b64c17..3df89f5870 100755 --- a/hack/verify-all.sh +++ b/hack/verify-all.sh @@ -53,10 +53,14 @@ fi EXCLUDE="verify-all.sh" +# TODO(mlavacca): once the prow configuration will be updated with a new target for +# test-crds-validation.sh, we can remove it from the find command, otherwise it will be run twice. +SCRIPTS=$(find "${SCRIPT_ROOT}"/hack -name "verify-*.sh" -o -name "test-crds-validation.sh") + ret=0 -for t in `ls $SCRIPT_ROOT/hack/verify-*.sh` +for t in $SCRIPTS; do - if is-excluded $t ; then + if is-excluded "${t}" ; then echo "Skipping $t" continue fi