From 882d7d7d894a51b34cba6bec12c37ffb63353ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bombo?= Date: Mon, 18 Sep 2023 08:13:52 -0700 Subject: [PATCH] ci: Create clusters in individual resource groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it so that each AKS cluster is created in its own individual resource group, rather than using the "kataCI" resource group for all test clusters. This is to accommodate a tool that we recently introduced in our Azure subscription which automatically deletes resource groups after a set amount of time, in order to keep spending under control. The tool will automatically delete any resource group, unless it has a tag SkipAutoDeleteTill = YYYY-MM-DD. When this tag is present, the resource group will be retained until the specified date. Note that I tagged all current resource groups in our subscription with SkipAutoDeleteTill = 2043-01-01 so that we don't lose any existing resources. Fixes: #7982 Signed-off-by: Aurélien Bombo (cherry picked from commit 68267a399620dc8ef5f62bdbc2d980915006c1f4) --- tests/gha-run-k8s-common.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/gha-run-k8s-common.sh b/tests/gha-run-k8s-common.sh index fd9b98109..cbd79c01c 100644 --- a/tests/gha-run-k8s-common.sh +++ b/tests/gha-run-k8s-common.sh @@ -11,7 +11,6 @@ set -o pipefail tests_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${tests_dir}/common.bash" -AZ_RG="${AZ_RG:-kataCI}" K8S_TEST_HOST_TYPE="${K8S_TEST_HOST_TYPE:-small}" function _print_cluster_name() { @@ -21,6 +20,12 @@ function _print_cluster_name() { echo "${test_type}-${GH_PR_NUMBER}-${short_sha}-${KATA_HYPERVISOR}-${KATA_HOST_OS}-amd64" } +function _print_rg_name() { + test_type="${1:-k8s}" + + echo "${AZ_RG:-"kataCI-$(_print_cluster_name ${test_type})"}" +} + function install_azure_cli() { curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # The aks-preview extension is required while the Mariner Kata host is in preview. @@ -38,9 +43,15 @@ function login_azure() { function create_cluster() { test_type="${1:-k8s}" - # First, ensure that the cluster 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 + local rg="$(_print_rg_name ${test_type})" + + az group create \ + -l eastus2 \ + -n "${rg}" + local instance_type="" case ${K8S_TEST_HOST_TYPE} in small) @@ -52,7 +63,8 @@ function create_cluster() { esac az aks create \ - -g "${AZ_RG}" \ + -g "${rg}" \ + --node-resource-group "node-${rg}" \ -n "$(_print_cluster_name ${test_type})" \ -s "${instance_type}" \ --node-count 1 \ @@ -79,16 +91,15 @@ function get_cluster_credentials() { test_type="${1:-k8s}" az aks get-credentials \ - -g "${AZ_RG}" \ + -g "$(_print_rg_name ${test_type})" \ -n "$(_print_cluster_name ${test_type})" } function delete_cluster() { test_type="${1:-k8s}" - az aks delete \ - -g "${AZ_RG}" \ - -n "$(_print_cluster_name ${test_type})" \ + az group delete \ + -g "$(_print_rg_name ${test_type})" \ --yes }