Skip to content

Commit

Permalink
feat: validate CRDs on specific k8s versions (kubernetes-sigs#3316)
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 Oct 28, 2024
1 parent b7005fc commit 34a0ebb
Show file tree
Hide file tree
Showing 3 changed files with 46 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
37 changes: 35 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,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
Expand Down
8 changes: 6 additions & 2 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 34a0ebb

Please sign in to comment.