-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
170 lines (160 loc) · 5.66 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
170 lines (160 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Azure DevOps pipeline for kubectl-aks integration tests.
#
# Integration tests need a real AKS cluster, so they live here (in Azure DevOps)
# instead of in GitHub Actions. The GitHub workflow keeps build, lint, unit tests,
# documentation tests and release.
#
# Prerequisites (configure in Azure DevOps before running):
# - An ARM service connection (default name: "azure-aks") with permission to
# create/delete AKS clusters in the target subscription. This replaces the
# GitHub `azure/login` federated-credential steps.
# - A secret pipeline variable `AZURE_AKS_SUBSCRIPTION_ID` with the subscription
# ID consumed by the integration tests.
#
# This pipeline is self-contained: it builds the kubectl-aks binary it needs for
# each OS rather than depending on GitHub-produced artifacts.
name: kubectl-aks integration tests
variables:
GO_VERSION: '1.23'
AZURE_PREFIX: kubectl-aks-ci
AZURE_NODE_COUNT: 3 # multiple nodes are needed to allow running parallel 'run-command' against the same cluster
AZURE_VM_SIZE: Standard_D2_v5
AZURE_LOCATION: westus2
# Name of the ARM service connection used to authenticate to Azure.
AZURE_SERVICE_CONNECTION: azure-aks
trigger:
branches:
include:
- main
tags:
include:
- 'v*'
paths:
include:
- '**/*.go'
- '**/*.yml'
- '**/*.yaml'
- Makefile
- go.mod
- go.sum
exclude:
- .krew.yaml
- README.md
- docs/*
pr:
paths:
include:
- '**/*.go'
- '**/*.yml'
- '**/*.yaml'
- Makefile
- go.mod
- go.sum
exclude:
- .krew.yaml
- README.md
- docs/*
stages:
- stage: integration
displayName: AKS integration tests
jobs:
- job: create_aks_cluster
displayName: Create AKS cluster
pool:
vmImage: ubuntu-latest
steps:
- task: AzureCLI@2
displayName: Create AKS cluster and prepare list of nodes
name: nodes
inputs:
azureSubscription: $(AZURE_SERVICE_CONNECTION)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -euo pipefail
az aks create \
--resource-group $(AZURE_PREFIX)-rg \
--name $(AZURE_PREFIX)-amd64-cluster \
--node-count $(AZURE_NODE_COUNT) \
--node-vm-size $(AZURE_VM_SIZE) \
--location $(AZURE_LOCATION) \
--no-ssh-key
az aks get-credentials \
--resource-group $(AZURE_PREFIX)-rg \
--name $(AZURE_PREFIX)-amd64-cluster \
--overwrite-existing
result=$(kubectl get nodes -o jsonpath={.items[*].metadata.name} | jq -R -s -c 'split(" ")')
echo "##vso[task.setvariable variable=result;isOutput=true]$result"
- job: integration_tests
displayName: Run integration tests
dependsOn: create_aks_cluster
variables:
nodes: $[ dependencies.create_aks_cluster.outputs['nodes.result'] ]
strategy:
matrix:
linux:
IMAGE: ubuntu-latest
TARGET_OS: linux
macos:
IMAGE: macOS-latest
TARGET_OS: darwin
windows:
IMAGE: windows-latest
TARGET_OS: windows
pool:
vmImage: $(IMAGE)
steps:
- bash: |
set -euo pipefail
if [ $(echo '$(nodes)' | jq -r '. | length') -lt $(System.TotalJobsInPhase) ]; then
echo "Not enough nodes to run parallel tests"
exit 1
fi
displayName: Ensure enough nodes are available to run parallel tests
- task: GoTool@0
displayName: Set up Go
inputs:
version: $(GO_VERSION)
- bash: make kubectl-aks
displayName: Build kubectl-aks binary
- task: AzureCLI@2
displayName: Run integration tests
inputs:
azureSubscription: $(AZURE_SERVICE_CONNECTION)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -euo pipefail
# kubectl is already present on Linux agents; install it elsewhere.
if [ "$(TARGET_OS)" != "linux" ]; then
az aks install-cli --client-version v1.28.2 || true
fi
az aks get-credentials \
--resource-group $(AZURE_PREFIX)-rg \
--name $(AZURE_PREFIX)-amd64-cluster \
--overwrite-existing
export AZURE_RESOURCE_GROUP=$(AZURE_PREFIX)-rg
export AZURE_CLUSTER_NAME=$(AZURE_PREFIX)-amd64-cluster
export AZURE_SUBSCRIPTION_ID=$(AZURE_AKS_SUBSCRIPTION_ID)
export AZURE_NODE_NAME=$(echo '$(nodes)' | jq -r ".[$(System.JobPositionInPhase) - 1]")
export
make integration-test -o kubectl-aks
- job: delete_aks_cluster
displayName: Delete AKS cluster
dependsOn: integration_tests
condition: always()
pool:
vmImage: ubuntu-latest
steps:
- task: AzureCLI@2
displayName: Delete AKS cluster
inputs:
azureSubscription: $(AZURE_SERVICE_CONNECTION)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -euo pipefail
az aks delete \
--resource-group $(AZURE_PREFIX)-rg \
--name $(AZURE_PREFIX)-amd64-cluster \
--yes