Skip to content

Commit 261fc40

Browse files
authored
Merge pull request #1405 from aramase/aramase/f/aks_windows_testing
ci: add script for aks windows cluster
2 parents 97f9dec + a54afd0 commit 261fc40

File tree

2 files changed

+91
-55
lines changed

2 files changed

+91
-55
lines changed

test/bats/tests/azure/job_templates/kubernetes_windows.json

Lines changed: 0 additions & 55 deletions
This file was deleted.

test/scripts/run-e2e-windows.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
: "${REGISTRY:?Environment variable empty or not defined.}"
22+
23+
readonly CLUSTER_NAME="${CLUSTER_NAME:-sscsi-e2e-$(openssl rand -hex 2)}"
24+
25+
parse_cred() {
26+
grep -E -o "\b$1[[:blank:]]*=[[:blank:]]*\"[^[:space:]\"]+\"" | cut -d '"' -f 2
27+
}
28+
29+
get_random_region() {
30+
local REGIONS=("eastus" "eastus2" "southcentralus" "westeurope" "uksouth" "northeurope" "francecentral")
31+
echo "${REGIONS[${RANDOM} % ${#REGIONS[@]}]}"
32+
}
33+
34+
cleanup() {
35+
echo "Deleting the AKS cluster ${CLUSTER_NAME}"
36+
# login again because the bats tests might have logged out after rotating the secret for testing
37+
az login --service-principal -u "${client_id}" -p "${client_secret}" --tenant "${tenant_id}" > /dev/null
38+
az account set --subscription "${subscription_id}" > /dev/null
39+
az group delete --name "${CLUSTER_NAME}" --yes --no-wait || true
40+
}
41+
trap cleanup EXIT
42+
43+
main() {
44+
# install azure cli
45+
curl -sL https://aka.ms/InstallAzureCLIDeb | bash > /dev/null
46+
47+
echo "Logging into Azure"
48+
az login --service-principal -u "${client_id}" -p "${client_secret}" --tenant "${tenant_id}" > /dev/null
49+
az account set --subscription "${subscription_id}" > /dev/null
50+
51+
LOCATION=$(get_random_region)
52+
echo "Creating AKS cluster ${CLUSTER_NAME} in ${LOCATION}"
53+
az group create --name "${CLUSTER_NAME}" --location "${LOCATION}" > /dev/null
54+
az aks create \
55+
--resource-group "${CLUSTER_NAME}" \
56+
--name "${CLUSTER_NAME}" \
57+
--node-count 1 \
58+
--node-vm-size Standard_DS3_v2 \
59+
--enable-managed-identity \
60+
--network-plugin azure \
61+
--generate-ssh-keys > /dev/null
62+
63+
echo "Adding windows nodepool"
64+
# add windows nodepool
65+
az aks nodepool add \
66+
--resource-group "${CLUSTER_NAME}" \
67+
--cluster-name "${CLUSTER_NAME}" \
68+
--os-type Windows \
69+
--name npwin \
70+
--node-count 1 > /dev/null
71+
72+
az aks get-credentials --resource-group "${CLUSTER_NAME}" --name "${CLUSTER_NAME}" --overwrite-existing
73+
74+
if [[ "${REGISTRY}" =~ \.azurecr\.io ]]; then
75+
az acr login --name "${REGISTRY}"
76+
fi
77+
78+
# build the driver image and run e2e tests
79+
ALL_OS_ARCH=amd64 make e2e-test
80+
}
81+
82+
# for Prow we use the provided AZURE_CREDENTIALS file.
83+
# the file is expected to be in toml format.
84+
if [[ -n "${AZURE_CREDENTIALS:-}" ]]; then
85+
subscription_id="$(parse_cred SubscriptionID < "${AZURE_CREDENTIALS}")"
86+
tenant_id="$(parse_cred TenantID < "${AZURE_CREDENTIALS}")"
87+
client_id="$(parse_cred ClientID < "${AZURE_CREDENTIALS}")"
88+
client_secret="$(parse_cred ClientSecret < "${AZURE_CREDENTIALS}")"
89+
fi
90+
91+
main

0 commit comments

Comments
 (0)