diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 768177d2ba5..ee1a5620481 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -370,6 +370,19 @@ jobs: template: templates/default.yaml - name: "Run BATS integration tests" run: make bats + - name: Cache image used by templates/k8s.yaml + uses: ./.github/actions/setup_cache_for_template + with: + template: templates/k8s.yaml + - name: "Run BATS k8s tests" + # Wish we could use BATS_TEST_RETRIES=3 as an environment variable here, + # but bats does not seem to support it. + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 + with: + timeout_minutes: 30 + retry_on: error + max_attempts: 3 + command: ./hack/bats/lib/bats-core/bin/bats --timing ./hack/bats/extras/k8s.bats colima: name: "Colima tests (QEMU, Linux host)" diff --git a/hack/bats/extras/README.md b/hack/bats/extras/README.md new file mode 100644 index 00000000000..419a094825a --- /dev/null +++ b/hack/bats/extras/README.md @@ -0,0 +1,6 @@ +# Extra tests + +The extra tests located in this directory are not automatically executed via `make bats`. + +Some tests are executed on the CI, some ones are not. +Refer to the configuration of the GitHub Actions to see what tests are executed. \ No newline at end of file diff --git a/hack/bats/extras/k8s.bats b/hack/bats/extras/k8s.bats new file mode 100644 index 00000000000..fa6dc1c3762 --- /dev/null +++ b/hack/bats/extras/k8s.bats @@ -0,0 +1,64 @@ +# SPDX-FileCopyrightText: Copyright The Lima Authors +# SPDX-License-Identifier: Apache-2.0 + +# This test verifies that a Kubernetes cluster can be started and that the single node is ready. + +load "../helpers/load" + +: "${TEMPLATE:=k8s}" + +# Instance names are "${NAME}-0", "${NAME}-1", ... +NAME="k8s" + +get_num_nodes() { + local nodes=0 + for tag in "${BATS_TEST_TAGS[@]}"; do + if [[ $tag =~ ^nodes:([0-9]+)$ ]]; then + nodes="${BASH_REMATCH[1]}" + fi + done + if [[ $nodes -eq 0 ]]; then + echo >&2 "nodes:N tag is required" + exit 1 + fi + echo "$nodes" +} + +local_setup() { + local nodes=$(get_num_nodes) + for ((i=0; i&- 4>&- + # NOTE: No support for multi-node clusters yet. + done + for node in $(k get node -o name); do + k wait --timeout=5m --for=condition=ready "${node}" + done +} + +local_teardown() { + local nodes=$(get_num_nodes) + for ((i=0; i