Skip to content

Commit

Permalink
ci: Create clusters in individual resource groups
Browse files Browse the repository at this point in the history
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 <abombo@microsoft.com>
(cherry picked from commit 68267a3)
  • Loading branch information
sprt authored and fidencio committed Sep 21, 2023
1 parent b09a3f8 commit 882d7d7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/gha-run-k8s-common.sh
Expand Up @@ -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() {
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -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 \
Expand All @@ -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
}

Expand Down

0 comments on commit 882d7d7

Please sign in to comment.