Skip to content

Commit

Permalink
feat: validate CRDs on specific k8s versions
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
  • Loading branch information
mlavacca committed Sep 9, 2024
1 parent ff517b3 commit 45a3e46
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 56 additions & 2 deletions hack/verify-crds-kind.sh → hack/test-crds-validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,69 @@ 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"
)

# Cleanup logic for cleanup on exit
CLEANED_UP=false
cleanup() {
if [ "$CLEANED_UP" = "true" ]; then
return
fi

if [ "${KIND_CREATE_ATTEMPTED:-}" = true ]; then
kind delete cluster --name "${CLUSTER_NAME}" || true
fi
CLEANED_UP=true
}

trap cleanup INT TERM EXIT

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
if ! [[ "$1" =~ ^-?[0-9]+$ ]]; then
echo "Error: Argument is not a valid integer."
exit 1
fi
index=$(($1))
else
index=$((default_index))
fi

# Check if the number is greater than 5 or smaller than 1
if [ "$index" -gt 5 ] || [ "$index" -lt 1 ]; then
echo "Error: Argument must be between 1 and 5."
exit 1
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
Expand Down
10 changes: 8 additions & 2 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ 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
echo $t
continue
if is-excluded "${t}" ; then
echo "Skipping $t"
continue
fi
Expand Down

0 comments on commit 45a3e46

Please sign in to comment.