diff --git a/tests/functional/kata-deploy/kata-deploy.bats b/tests/functional/kata-deploy/kata-deploy.bats index 94b378d4d..e2735f1f8 100644 --- a/tests/functional/kata-deploy/kata-deploy.bats +++ b/tests/functional/kata-deploy/kata-deploy.bats @@ -6,9 +6,10 @@ # load "${BATS_TEST_DIRNAME}/../../common.bash" +repo_root_dir="${BATS_TEST_DIRNAME}/../../../" +load "${repo_root_dir}/tests/gha-run-k8s-common.sh" setup() { - repo_root_dir="${BATS_TEST_DIRNAME}/../../../" ensure_yq pushd "${repo_root_dir}" @@ -25,77 +26,35 @@ setup() { "kata-${KATA_HYPERVISOR}\s+kata-${KATA_HYPERVISOR}" \ ) + # Set the latest image, the one generated as part of the PR, to be used as part of the tests - sed -i -e "s|quay.io/kata-containers/kata-deploy:latest|${DOCKER_REGISTRY}/${DOCKER_REPO}:${DOCKER_TAG}|g" "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_IMAGE_REFERENCE="${DOCKER_REGISTRY}/${DOCKER_REPO}" + export HELM_IMAGE_TAG="${DOCKER_TAG}" # Enable debug for Kata Containers - yq -i \ - '.spec.template.spec.containers[0].env[1].value = "true"' \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_DEBUG="true" + # Create the runtime class only for the shim that's being tested - yq -i \ - ".spec.template.spec.containers[0].env[2].value = \"${KATA_HYPERVISOR}\"" \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_SHIMS="${KATA_HYPERVISOR}" + # Set the tested hypervisor as the default `kata` shim - yq -i \ - ".spec.template.spec.containers[0].env[3].value = \"${KATA_HYPERVISOR}\"" \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_DEFAULT_SHIM="${KATA_HYPERVISOR}" + # Let the `kata-deploy` script take care of the runtime class creation / removal - yq -i \ - '.spec.template.spec.containers[0].env[4].value = "true"' \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_CREATE_RUNTIME_CLASSES="true" + # Let the `kata-deploy` create the default `kata` runtime class - yq -i \ - '.spec.template.spec.containers[0].env[5].value = "true"' \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" + export HELM_CREATE_DEFAULT_RUNTIME_CLASS="true" - if [ "${KATA_HOST_OS}" = "cbl-mariner" ]; then - yq -i \ - ".spec.template.spec.containers[0].env += [{\"name\": \"HOST_OS\", \"value\": \"${KATA_HOST_OS}\"}]" \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" - fi + HOST_OS="" + if [[ "${KATA_HOST_OS}" = "cbl-mariner" ]]; then + HOST_OS="${KATA_HOST_OS}" + fi + export HELM_HOST_OS="${HOST_OS}" - echo "::group::Final kata-deploy.yaml that is used in the test" - cat "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" - grep "${DOCKER_REGISTRY}/${DOCKER_REPO}:${DOCKER_TAG}" "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" || die "Failed to setup the tests image" - echo "::endgroup::" + export HELM_K8S_DISTRIBUTION="${KUBERNETES}" - echo "::group::Debug overlays directory content" - echo "Current working directory: $(pwd)" - ls -la tools/packaging/kata-deploy/kata-deploy/overlays/ - echo "::endgroup::" - - kubectl apply -f "tools/packaging/kata-deploy/kata-rbac/base/kata-rbac.yaml" - if [ "${KUBERNETES}" = "k0s" ]; then - kubectl apply -k "tools/packaging/kata-deploy/kata-deploy/overlays/k0s" - elif [ "${KUBERNETES}" = "k3s" ]; then - kubectl apply -k "tools/packaging/kata-deploy/kata-deploy/overlays/k3s" - elif [ "${KUBERNETES}" = "rke2" ]; then - kubectl apply -k "tools/packaging/kata-deploy/kata-deploy/overlays/rke2" - elif [ "${KUBERNETES}" = "microk8s" ]; then - kubectl apply -k "tools/packaging/kata-deploy/kata-deploy/overlays/microk8s" - else - kubectl apply -f "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" - fi - - local cmd="kubectl -n kube-system get -l name=kata-deploy pod 2>/dev/null | grep '\'" - - if ! waitForProcess 240 10 "$cmd"; then - echo "Kata-deploy pod is not running. Printing pod details for debugging:" - kubectl -n kube-system get pods -o wide - kubectl -n kube-system get pods -l name=kata-deploy -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | while read -r pod; do - echo "Describing pod: $pod" - kubectl -n kube-system describe pod "$pod" - done - - echo "ERROR: kata-deploy pod is not running, tests will not be execute." - echo "ERROR: setup() aborting tests..." - return 1 - fi - - # Give some time for the pod to finish what's doing and have the - # runtimeclasses properly created - sleep 30s + helm_helper echo "::group::kata-deploy logs" kubectl -n kube-system logs --tail=100 -l name=kata-deploy @@ -135,52 +94,8 @@ setup() { teardown() { pushd "${repo_root_dir}" - if [ "${KUBERNETES}" = "k0s" ]; then - deploy_spec="-k \"tools/packaging/kata-deploy/kata-deploy/overlays/k0s\"" - cleanup_spec="-k \"tools/packaging/kata-deploy/kata-cleanup/overlays/k0s\"" - elif [ "${KUBERNETES}" = "k3s" ]; then - deploy_spec="-k \"tools/packaging/kata-deploy/kata-deploy/overlays/k3s\"" - cleanup_spec="-k \"tools/packaging/kata-deploy/kata-cleanup/overlays/k3s\"" - elif [ "${KUBERNETES}" = "rke2" ]; then - deploy_spec="-k \"tools/packaging/kata-deploy/kata-deploy/overlays/rke2\"" - cleanup_spec="-k \"tools/packaging/kata-deploy/kata-cleanup/overlays/rke2\"" - elif [ "${KUBERNETES}" = "microk8s" ]; then - deploy_spec="-k \"tools/packaging/kata-deploy/kata-deploy/overlays/microk8s\"" - cleanup_spec="-k \"tools/packaging/kata-deploy/kata-cleanup/overlays/microk8s\"" - else - deploy_spec="-f \"tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml\"" - cleanup_spec="-f \"tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml\"" - fi - - kubectl delete ${deploy_spec} + helm uninstall --namespace=kube-system kata-deploy --wait kubectl -n kube-system wait --timeout=10m --for=delete -l name=kata-deploy pod - # Let the `kata-deploy` script take care of the runtime class creation / removal - yq -i \ - '.spec.template.spec.containers[0].env[4].value = "true"' \ - "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" - # Create the runtime class only for the shim that's being tested - yq -i \ - ".spec.template.spec.containers[0].env[2].value = \"${KATA_HYPERVISOR}\"" \ - "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" - # Set the tested hypervisor as the default `kata` shim - yq -i \ - ".spec.template.spec.containers[0].env[3].value = \"${KATA_HYPERVISOR}\"" \ - "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" - # Let the `kata-deploy` create the default `kata` runtime class - yq -i \ - '.spec.template.spec.containers[0].env[5].value = "true"' \ - "tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml" - - sed -i -e "s|quay.io/kata-containers/kata-deploy:latest|${DOCKER_REGISTRY}/${DOCKER_REPO}:${DOCKER_TAG}|g" "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" - cat "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" - grep "${DOCKER_REGISTRY}/${DOCKER_REPO}:${DOCKER_TAG}" "tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml" || die "Failed to setup the tests image" - - kubectl apply ${cleanup_spec} - sleep 30s - - kubectl delete ${cleanup_spec} - kubectl delete -f "tools/packaging/kata-deploy/kata-rbac/base/kata-rbac.yaml" - popd }