Skip to content

Commit 41e5675

Browse files
committed
ci: add script for aks windows cluster
Signed-off-by: Anish Ramasekar <[email protected]>
1 parent 97f9dec commit 41e5675

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

test/scripts/run-e2e-windows.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# set TEST_WINDOWS env variable to true to run windows tests
25+
export TEST_WINDOWS=true
26+
27+
parse_cred() {
28+
grep -E -o "\b$1[[:blank:]]*=[[:blank:]]*\"[^[:space:]\"]+\"" | cut -d '"' -f 2
29+
}
30+
31+
get_random_region() {
32+
local REGIONS=("eastus" "eastus2" "southcentralus" "westeurope" "uksouth" "northeurope" "francecentral")
33+
echo "${REGIONS[${RANDOM} % ${#REGIONS[@]}]}"
34+
}
35+
36+
cleanup() {
37+
echo "Deleting the AKS cluster "${CLUSTER_NAME}""
38+
# login again because the bats tests might have logged out after rotating the secret for testing
39+
az login --service-principal -u "${client_id}" -p "${client_secret}" --tenant "${tenant_id}" > /dev/null
40+
az account set --subscription "${subscription_id}" > /dev/null
41+
az group delete --name "${CLUSTER_NAME}" --yes --no-wait || true
42+
}
43+
trap cleanup EXIT
44+
45+
main() {
46+
# install azure cli
47+
curl -sL https://aka.ms/InstallAzureCLIDeb | bash > /dev/null
48+
49+
echo "Logging into Azure"
50+
az login --service-principal -u "${client_id}" -p "${client_secret}" --tenant "${tenant_id}" > /dev/null
51+
az account set --subscription "${subscription_id}" > /dev/null
52+
53+
LOCATION=$(get_random_region)
54+
echo "Creating AKS cluster "${CLUSTER_NAME}" in "${LOCATION}""
55+
az group create --name "${CLUSTER_NAME}" --location "${LOCATION}" > /dev/null
56+
az aks create \
57+
--resource-group "${CLUSTER_NAME}" \
58+
--name "${CLUSTER_NAME}" \
59+
--node-count 1 \
60+
--node-vm-size Standard_DS3_v2 \
61+
--enable-managed-identity \
62+
--network-plugin azure \
63+
--generate-ssh-keys > /dev/null
64+
65+
echo "Adding windows nodepool"
66+
# add windows nodepool
67+
az aks nodepool add \
68+
--resource-group "${CLUSTER_NAME}" \
69+
--cluster-name "${CLUSTER_NAME}" \
70+
--os-type Windows \
71+
--name npwin \
72+
--node-count 1 > /dev/null
73+
74+
az aks get-credentials --resource-group "${CLUSTER_NAME}" --name "${CLUSTER_NAME}" --overwrite-existing
75+
76+
if [[ "${REGISTRY}" =~ \.azurecr\.io ]]; then
77+
az acr login --name "${REGISTRY}"
78+
fi
79+
80+
# build the driver image and run e2e tests
81+
ALL_OS_ARCH=amd64 make e2e-test
82+
}
83+
84+
# for Prow we use the provided AZURE_CREDENTIALS file.
85+
# the file is expected to be in toml format.
86+
if [[ -n "${AZURE_CREDENTIALS:-}" ]]; then
87+
subscription_id="$(parse_cred SubscriptionID < "${AZURE_CREDENTIALS}")"
88+
tenant_id="$(parse_cred TenantID < "${AZURE_CREDENTIALS}")"
89+
client_id="$(parse_cred ClientID < "${AZURE_CREDENTIALS}")"
90+
client_secret="$(parse_cred ClientSecret < "${AZURE_CREDENTIALS}")"
91+
fi
92+
93+
main

0 commit comments

Comments
 (0)