-
Notifications
You must be signed in to change notification settings - Fork 9
388 lines (373 loc) · 15 KB
/
int_test.yml
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
name: Integration tests
on:
workflow_call:
inputs:
resource-group:
description: Resource group for cluster creation
type: string
required: true
default: ops-cli-int-test-rg
runtime-init-args:
description: Additional INIT arguments (beyond cluster name, resource group, schema registry).
type: string
required: false
default: ''
runtime-create-args:
description: Additional CREATE arguments (beyond cluster name, resource group, instance name).
type: string
required: false
default: ''
custom-locations-oid:
description: Custom Locations OID
type: string
required: false
default: '51dfe1e8-70c6-4de5-a08e-e18aff23d815'
init-continue-on-error:
description: Continue on error for init integration tests
type: boolean
required: false
default: true
use-container:
description: Build container image for tests
type: boolean
required: false
default: false
secrets:
# required for az login
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
# optional --sp-* init params
AIO_SP_APP_ID:
AIO_SP_OBJECT_ID:
AIO_SP_SECRET:
workflow_dispatch:
inputs:
resource-group:
description: Resource group for cluster creation
type: string
required: true
default: ops-cli-int-test-rg
custom-locations-oid:
description: Object ID of Custom Locations RP
type: string
required: false
default: '51dfe1e8-70c6-4de5-a08e-e18aff23d815'
runtime-init-args:
description: Additional INIT arguments (beyond cluster name, resource group, schema registry).
type: string
required: false
default: ''
runtime-create-args:
description: Additional CREATE arguments (beyond cluster name, resource group, instance name).
type: string
required: false
default: ''
init-continue-on-error:
description: Continue on error for init integration tests
type: boolean
required: false
default: true
use-container:
description: Build container image for tests
type: boolean
required: false
default: false
permissions:
# required for OpenID federation
contents: 'read'
id-token: 'write'
env:
RESOURCE_GROUP: "${{ inputs.resource-group }}"
jobs:
test:
env:
CLUSTER_NAME: "opt${{ github.run_number }}${{ matrix.feature }}"
INSTANCE_NAME: "inst${{ github.run_number }}${{ matrix.feature }}"
CUSTOM_LOCATIONS_OID: ${{ inputs.custom-locations-oid }}
EXTENSION_SOURCE_DIRECTORY: "./azure-iot-ops-cli-extension"
K3S_VERSION: "v1.28.5+k3s1"
CA_FILE: "test-ca.pem"
CA_KEY_FILE: "test-ca-key.pem"
strategy:
fail-fast: false
matrix:
feature: [custom-input, default, insecure-listener, syncrules, redeploy, trustbundle]
runtime-args:
- ${{ inputs.runtime-init-args != '' || inputs.runtime-create-args != '' }}
exclude:
- feature: custom-input
runtime-args: false
- feature: default
runtime-args: true
- feature: insecure-listener
runtime-args: true
- feature: syncrules
runtime-args: true
- feature: redeploy
runtime-args: true
- feature: trustbundle
runtime-args: true
name: "Run cluster tests"
runs-on: ubuntu-22.04
steps:
- name: "Determine Init Args"
id: "init"
run: |
echo "NO_PREFLIGHT=false" >> $GITHUB_OUTPUT
if [[ ${{ matrix.feature }} == "insecure-listener" ]]; then
echo "CREATE_ARG=--add-insecure-listener --broker-listener-type NodePort" >> $GITHUB_OUTPUT
echo "NO_PREFLIGHT=true" >> $GITHUB_OUTPUT
elif [[ ${{ matrix.feature }} == "syncrules" ]]; then
echo "CREATE_ARG=--enable-rsync" >> $GITHUB_OUTPUT
elif [[ ${{ matrix.feature }} == "redeploy" ]]; then
echo "REDEPLOY=True" >> $GITHUB_OUTPUT
elif [[ ${{ matrix.feature }} == "custom-input" ]]; then
echo "CREATE_ARG=${{ inputs.runtime-create-args }}" >> $GITHUB_OUTPUT
echo "INIT_ARG=${{ inputs.runtime-init-args }}" >> $GITHUB_OUTPUT
elif [[ ${{ matrix.feature }} == "trustbundle" ]]; then
echo "CREATE_ARG=--trust-settings configMapName=example-bundle configMapKey=trust-bundle.pem issuerKind=Issuer issuerName=selfsigned-issuer " >> $GITHUB_OUTPUT
echo "INIT_ARG=--user-trust true" >> $GITHUB_OUTPUT
fi
- name: "Output variables for future steps"
id: "env_out"
run: |
echo "RESOURCE_GROUP=${{ env.RESOURCE_GROUP }}" >> $GITHUB_OUTPUT
echo "CLUSTER_NAME=${{ env.CLUSTER_NAME }}" >> $GITHUB_OUTPUT
echo "INSTANCE_NAME=${{ env.INSTANCE_NAME }}" >> $GITHUB_OUTPUT
- name: "Setup python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: "Checkout extension source for build"
uses: actions/checkout@v4
with:
# ensure source checkout uses our repo instead of calling workflow
repository: azure/azure-iot-ops-cli-extension
path: ${{ env.EXTENSION_SOURCE_DIRECTORY }}
- name: "Build and install local IoT Ops extension from source"
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
pip install -r dev_requirements.txt
python -m setup bdist_wheel -d dist
wheel=$(find ./dist/*.whl)
az extension add --source $wheel -y
- name: "Create k3s cluster"
run: |
# vars
release_url="https://github.com/k3s-io/k3s/releases/download"
install_dir="/usr/local/bin/k3s"
# install k3s
curl -Lo $install_dir "$release_url/${{ env.K3S_VERSION }}/k3s"
chmod a+x $install_dir
# config
K3S_KUBECONFIG_MODE="644"
# start cluster in background
sudo k3s server --cluster-init &
# allow time for cluster to initialize
sleep 15s
- name: "Write cluster config"
run: |
mkdir ~/.kube 2> /dev/null
sudo k3s kubectl config view --raw > ~/.kube/config
chmod 600 ~/.kube/config
export KUBECONFIG=~/.kube/config
- name: "Apply custom cluster issuer"
if: ${{ matrix.feature == 'trustbundle' || contains(inputs.runtime-init-args, '--user-trust') }}
run: |
set -x
helm repo add jetstack https://charts.jetstack.io --force-update
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.13.6 \
--set installCRDs=true \
--set startupapicheck.timeout=5m
kubectl create namespace azure-iot-operations
helm upgrade trust-manager jetstack/trust-manager \
--install \
--namespace cert-manager \
--set app.trust.namespace=cert-manager \
--wait
kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
namespace: cert-manager
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: trust-manager-example-ca
namespace: cert-manager
spec:
isCA: true
commonName: trust-manager-example-ca
secretName: trust-manager-example-ca-secret
privateKey:
algorithm: ECDSA
size: 256
issuerRef:
name: selfsigned-issuer
kind: Issuer
group: cert-manager.io
EOF
kubectl apply -f - <<EOF
apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
name: example-bundle
namespace: cert-manager
spec:
sources:
- useDefaultCAs: true
- secret:
name: "trust-manager-example-ca-secret"
key: "tls.crt"
target:
configMap:
key: "trust-bundle.pem"
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: azure-iot-operations
EOF
kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
namespace: azure-iot-operations
spec:
selfSigned: {}
EOF
- name: "Az CLI login"
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: "OIDC Token exchange service"
run: |
while true; do
token_request=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
token_uri=$ACTIONS_ID_TOKEN_REQUEST_URL
token=$(curl -H "Authorization: bearer $token_request" "${token_uri}&audience=api://AzureADTokenExchange" | jq .value -r)
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -t ${{ secrets.AZURE_TENANT_ID }} --federated-token $token --output none
# Sleep for 4 minutes
sleep 240
done &
- name: "ARC connect cluster"
uses: azure/azure-iot-ops-cli-extension/.github/actions/connect-arc@dev
with:
cluster-name: ${{ env.CLUSTER_NAME }}
resource-group: ${{ env.RESOURCE_GROUP }}
custom-locations-oid: ${{ env.CUSTOM_LOCATIONS_OID }}
- name: "Tox test environment setup for init"
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
python -m pip install tox
tox r -vv -e python-init-int --notest
- name: "Tox test environment setup for integration tests"
if: ${{ matrix.feature == 'default' && !inputs.use-container }}
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
tox r -vv -e python-int --notest
- name: "Tox INIT Integration Tests"
env:
AIO_CLI_INIT_PREFLIGHT_DISABLED: ${{ steps.init.outputs.NO_PREFLIGHT }}
azext_edge_init_continue_on_error: ${{ inputs.init-continue-on-error || '' }}
azext_edge_rg: ${{ steps.env_out.outputs.RESOURCE_GROUP }}
azext_edge_cluster: ${{ steps.env_out.outputs.CLUSTER_NAME }}
azext_edge_instance: ${{ steps.env_out.outputs.INSTANCE_NAME }}
azext_edge_init_args: ${{ steps.init.outputs.INIT_ARG }}
azext_edge_create_args: ${{ steps.init.outputs.CREATE_ARG }}
azext_edge_init_redeployment: ${{ steps.init.outputs.REDEPLOY }}
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
tox r -e python-init-int --skip-pkg-install -- --durations=0
- name: "Tox Integration Tests"
if: ${{ matrix.feature == 'default' && !inputs.use-container }}
env:
azext_edge_rg: ${{ steps.env_out.outputs.RESOURCE_GROUP }}
azext_edge_cluster: ${{ steps.env_out.outputs.CLUSTER_NAME }}
azext_edge_instance: ${{ steps.env_out.outputs.INSTANCE_NAME }}
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
tox r -e python-int --skip-pkg-install -- --durations=0
coverage=$(jq .totals.percent_covered coverage.json | cut -c1-4)
echo "Code coverage: $coverage%" >> $GITHUB_STEP_SUMMARY
- name: "Containerized tests"
if: ${{ matrix.feature == 'default' && inputs.use-container }}
env:
azext_edge_skip_init: true # skip init tests in container
azext_edge_init_redeployment: false # ensure no redeployment in container
AIO_CLI_INIT_PREFLIGHT_DISABLED: ${{ steps.init.outputs.NO_PREFLIGHT }}
azext_edge_rg: ${{ steps.env_out.outputs.RESOURCE_GROUP }}
azext_edge_cluster: ${{ steps.env_out.outputs.CLUSTER_NAME }}
azext_edge_instance: ${{ steps.env_out.outputs.INSTANCE_NAME }}
run: |
# volume mounts
azure_dir=$(realpath ~/.azure)
kubeconfig=$(realpath ~/.kube/config)
kubeconfig_mount=/root/.kube/config
tempLog=$(mktemp -d)
# env vars
envVars=()
envVars+=("-e" "azext_edge_skip_init=$azext_edge_skip_init")
envVars+=("-e" "azext_edge_init_redeployment=$azext_edge_init_redeployment")
envVars+=("-e" "AIO_CLI_INIT_PREFLIGHT_DISABLED=$AIO_CLI_INIT_PREFLIGHT_DISABLED")
envVars+=("-e" "azext_edge_rg=$azext_edge_rg")
envVars+=("-e" "azext_edge_cluster=$azext_edge_cluster")
envVars+=("-e" "azext_edge_instance=$azext_edge_instance")
envVars+=("-e" "KUBECONFIG=$kubeconfig_mount")
# Run tests
set +e
docker run \
--rm \
"${envVars[@]}" \
-v "$kubeconfig:$kubeconfig_mount:ro" \
-v "${azure_dir}:/root/.azure" \
-v "${tempLog}:/usr/src/azure-iot-ops/junit" \
--network host \
$(docker build ${{ env.EXTENSION_SOURCE_DIRECTORY }} -q)
- name: "Run smoke tests"
run: |
az iot ops support create-bundle
az iot ops support create-bundle --svc broker --broker-traces
az iot ops support create-bundle --ops-service acs secretstore
az iot ops check
az iot ops check --pre
az iot ops check --post
az iot ops check --as-object
az iot ops check --svc broker --resources broker brokerlistener
az iot ops asset query -g ${{ env.RESOURCE_GROUP }} --location westus -o table
- name: "Delete Cluster for redeployment"
if: ${{ matrix.feature == 'redeploy' }}
run: |
az iot ops delete -n ${{ env.INSTANCE_NAME }} -g ${{ env.RESOURCE_GROUP }} -y
- name: "Redeploy cluster via tox"
if: ${{ matrix.feature == 'redeploy' }}
env:
azext_edge_rg: ${{ steps.env_out.outputs.RESOURCE_GROUP }}
azext_edge_cluster: ${{ steps.env_out.outputs.CLUSTER_NAME }}
azext_edge_instance: ${{ steps.env_out.outputs.INSTANCE_NAME }}
azext_edge_init_args: ${{ steps.init.outputs.INIT_ARG }}
azext_edge_create_args: ${{ steps.init.outputs.CREATE_ARG }}
run: |
cd ${{ env.EXTENSION_SOURCE_DIRECTORY }}
tox r -e python-init-int --skip-pkg-install -- --durations=0
- name: "Delete AIO resources"
if: ${{ always() }}
run: |
az iot ops delete --cluster ${{ env.CLUSTER_NAME }} -g ${{ env.RESOURCE_GROUP }} -y
- name: "Delete connected cluster"
if: ${{ always() }}
run: |
az resource delete -v --name ${{ env.CLUSTER_NAME }} -g ${{ env.RESOURCE_GROUP }} --resource-type Microsoft.Kubernetes/connectedClusters --verbose