From badc208e9a85d969d5f748c365fc3704db2f4ba6 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Tue, 18 Jun 2024 11:58:57 -0300 Subject: [PATCH] tests/gha-run-k8s-common: shorten AKS cluster name Because az client restricts the name to be less than 64 characters. In some cases (e.g. KATA_HYPERVISOR=qemu-runtime-rs) the generated name will exceed the limit. This changed the function to shorten the name: * SHA1 is computed from metadata then compound the cluster's name * metadata as plain-text are passed as --tags Fixes: #9850 Signed-off-by: Wainer dos Santos Moschetta --- tests/gha-run-k8s-common.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/gha-run-k8s-common.sh b/tests/gha-run-k8s-common.sh index 0d98b9e5a..70113dc85 100644 --- a/tests/gha-run-k8s-common.sh +++ b/tests/gha-run-k8s-common.sh @@ -31,12 +31,16 @@ function _print_instance_type() { function _print_cluster_name() { local test_type="${1:-k8s}" local short_sha + local metadata if [ -n "${AKS_NAME:-}" ]; then echo "$AKS_NAME" else short_sha="$(git rev-parse --short=12 HEAD)" - echo "${test_type}-${GH_PR_NUMBER}-${short_sha}-${KATA_HYPERVISOR}-${KATA_HOST_OS}-amd64-${K8S_TEST_HOST_TYPE:0:1}-${GENPOLICY_PULL_METHOD:0:1}" + metadata="${GH_PR_NUMBER}-${short_sha}-${KATA_HYPERVISOR}-${KATA_HOST_OS}-amd64-${K8S_TEST_HOST_TYPE:0:1}-${GENPOLICY_PULL_METHOD:0:1}" + # Compute the SHA1 digest of the metadata part to keep the name less + # than the limit of 63 chars of AKS + echo "${test_type}-$(sha1sum <<< "$metadata" | cut -d' ' -f1)" fi } @@ -80,12 +84,22 @@ function login_azure() { function create_cluster() { test_type="${1:-k8s}" + local short_sha + local tags # First ensure it didn't fail to get cleaned up from a previous run. delete_cluster "${test_type}" || true local rg="$(_print_rg_name ${test_type})" + short_sha="$(git rev-parse --short=12 HEAD)" + tags=("GH_PR_NUMBER=${GH_PR_NUMBER:-}" \ + "SHORT_SHA=${short_sha}" \ + "KATA_HYPERVISOR=${KATA_HYPERVISOR}"\ + "KATA_HOST_OS=${KATA_HOST_OS:-}" \ + "K8S_TEST_HOST_TYPE=${K8S_TEST_HOST_TYPE:0:1}" \ + "GENPOLICY_PULL_METHOD=${GENPOLICY_PULL_METHOD:0:1}") + az group create \ -l eastus \ -n "${rg}" @@ -97,6 +111,7 @@ function create_cluster() { -s "$(_print_instance_type)" \ --node-count 1 \ --generate-ssh-keys \ + --tags "${tags[@]}" \ $([ "${KATA_HOST_OS}" = "cbl-mariner" ] && echo "--os-sku AzureLinux --workload-runtime KataMshvVmIsolation") }