Skip to content

Commit

Permalink
Merge pull request kata-containers#9871 from wainersm/fix-print_clust…
Browse files Browse the repository at this point in the history
…er_name

tests/gha-run-k8s-common: shorten AKS cluster name
  • Loading branch information
wainersm authored Jan 9, 2025
2 parents 8f8988f + badc208 commit 5fae2a9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/gha-run-k8s-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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}"
Expand All @@ -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")
}

Expand Down

0 comments on commit 5fae2a9

Please sign in to comment.