Merge pull request #9871 from wainersm/fix-print_cluster_name

tests/gha-run-k8s-common: shorten AKS cluster name
This commit is contained in:
Wainer Moschetta 2025-01-09 14:35:02 -03:00 committed by GitHub
commit 5fae2a9f91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,12 +31,16 @@ function _print_instance_type() {
function _print_cluster_name() { function _print_cluster_name() {
local test_type="${1:-k8s}" local test_type="${1:-k8s}"
local short_sha local short_sha
local metadata
if [ -n "${AKS_NAME:-}" ]; then if [ -n "${AKS_NAME:-}" ]; then
echo "$AKS_NAME" echo "$AKS_NAME"
else else
short_sha="$(git rev-parse --short=12 HEAD)" 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 fi
} }
@ -80,12 +84,22 @@ function login_azure() {
function create_cluster() { function create_cluster() {
test_type="${1:-k8s}" test_type="${1:-k8s}"
local short_sha
local tags
# First ensure it didn't fail to get cleaned up from a previous run. # First ensure it didn't fail to get cleaned up from a previous run.
delete_cluster "${test_type}" || true delete_cluster "${test_type}" || true
local rg="$(_print_rg_name ${test_type})" 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 \ az group create \
-l eastus \ -l eastus \
-n "${rg}" -n "${rg}"
@ -97,6 +111,7 @@ function create_cluster() {
-s "$(_print_instance_type)" \ -s "$(_print_instance_type)" \
--node-count 1 \ --node-count 1 \
--generate-ssh-keys \ --generate-ssh-keys \
--tags "${tags[@]}" \
$([ "${KATA_HOST_OS}" = "cbl-mariner" ] && echo "--os-sku AzureLinux --workload-runtime KataMshvVmIsolation") $([ "${KATA_HOST_OS}" = "cbl-mariner" ] && echo "--os-sku AzureLinux --workload-runtime KataMshvVmIsolation")
} }