-
Notifications
You must be signed in to change notification settings - Fork 84
367 lines (327 loc) · 13.2 KB
/
azure-e2e-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
name: azure-e2e-test
permissions:
id-token: write
contents: read
env:
CLUSTER_NAME_TEMPLATE: "{0}-e2e-test-${{ github.run_id }}-${{ github.run_attempt }}"
TEST_PROVISION_PATH_TEMPLATE: "${{ github.workspace }}/provision_azure${{ github.run_id }}_{0}.properties"
CLOUD_PROVIDER: "azure"
BUILTIN_CLOUD_PROVIDERS: "azure"
TEST_E2E_CREATE_RG: "no"
ACR_URL: "${{ vars.AZURE_ACR_URL }}"
TEST_TAGS: "owner=github-actions,run=${{ github.run_id }}-${{ github.run_attempt }}"
on:
schedule:
# Runs "at midnight every day" (see https://crontab.guru)
# will base on default branch `main`
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
podvm-image-id:
type: string
description: prebuilt podvm image
caa-image:
type: string
description: prebuilt caa image
kbs-image-id:
type: string
description: prebuild kbs image
kbs-image-tag:
type: string
description: prebuild kbs image tag
jobs:
generate-podvm-image-version:
if: github.event.inputs.podvm-image-id == ''
runs-on: ubuntu-latest
outputs:
image-version: "${{ steps.generate-image-version.outputs.image-version }}"
steps:
- name: Generate PodVM image version
id: generate-image-version
run: |
unique_version="$(date '+%m.%d.%H%M%S')${{ github.run_attempt }}"
echo "Generated unique version for the image as: ${unique_version}"
echo "image-version=${unique_version}" >> "$GITHUB_OUTPUT"
build-podvm-image:
uses: ./.github/workflows/azure-podvm-image-build.yml
needs:
- generate-podvm-image-version
if: github.event.inputs.podvm-image-id == ''
secrets: inherit
with:
image-version: ${{ needs.generate-podvm-image-version.outputs.image-version }}
build-caa-container-image:
if: github.event.inputs.caa-image == ''
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/cloud-api-adaptor
outputs:
caa-image: "${{ steps.build-container.outputs.caa-image }}"
steps:
- uses: actions/checkout@v3
- name: Extract go version number
run: echo "GO_VERSION=$(yq -e '.tools.golang' versions.yaml)" >> "$GITHUB_ENV"
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: go.sum
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install build dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y libvirt-dev
- name: Build container image
id: build-container
env:
ARCHES: "linux/amd64"
RELEASE_BUILD: "false"
run: |
az acr login --name "$ACR_URL"
# This builds image in the following format:
# $ACR_URL/cloud-api-adaptor:dev-COMMIT
make image "registry=${ACR_URL}"
echo "caa-image=${ACR_URL}/cloud-api-adaptor:dev-${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
install-aks:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/cloud-api-adaptor
needs:
- generate-podvm-image-version
- build-caa-container-image
# when none of required steps failed, skipped is ok
if: always() && !failure() && !cancelled()
strategy:
matrix:
parameters:
- id: "tdx"
machine_type: "Standard_DC2es_v5"
- id: "snp"
machine_type: "Standard_DC2as_v5"
steps:
- uses: actions/checkout@v3
- name: Extract go version number
run: echo "GO_VERSION=$(yq -e '.tools.golang' versions.yaml)" >> "$GITHUB_ENV"
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Set Provisioner Environment Variables
run: |
echo "TEST_PROVISION_FILE=${{ format(env.TEST_PROVISION_PATH_TEMPLATE, matrix.parameters.id) }}" >> "$GITHUB_ENV"
echo "CLUSTER_NAME=${{ format(env.CLUSTER_NAME_TEMPLATE, matrix.parameters.id) }}" >> "$GITHUB_ENV"
- name: Extract provisioner environment
run: |
echo "KBS_IMAGE=$(yq -e '.oci.kbs.registry' versions.yaml)" >> "$GITHUB_ENV"
echo "KBS_IMAGE_TAG=$(yq -e '.oci.kbs.tag' versions.yaml)" >> "$GITHUB_ENV"
- name: Create provisioner file
env:
AZURE_IMAGE_ID: ${{ github.event.inputs.podvm-image-id || format('/CommunityGalleries/{0}/images/{1}/Versions/{2}', vars.AZURE_COMMUNITY_GALLERY_NAME, vars.AZURE_PODVM_IMAGE_DEF_NAME, needs.generate-podvm-image-version.outputs.image-version) }}
CAA_IMAGE: "${{ github.event.inputs.caa-image || needs.build-caa-container-image.outputs.caa-image }}"
KBS_IMAGE: ${{ github.event.inputs.kbs-image-id || env.KBS_IMAGE }}
KBS_IMAGE_TAG: ${{ github.event.inputs.kbs-image-tag || env.KBS_IMAGE_TAG}}
AZURE_INSTANCE_SIZE: ${{ matrix.parameters.machine_type }}
run: |
echo "Provisioner file for ${{ matrix.parameters.id }}"
cat << EOF > "$TEST_PROVISION_FILE"
AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}"
RESOURCE_GROUP_NAME="${{ secrets.AZURE_RESOURCE_GROUP }}"
CLUSTER_NAME="${{ env.CLUSTER_NAME }}"
LOCATION="${{ secrets.AZURE_REGION }}"
SSH_KEY_ID="id_rsa.pub"
AZURE_IMAGE_ID="$AZURE_IMAGE_ID"
IS_CI_MANAGED_CLUSTER="true"
MANAGED_IDENTITY_NAME="${{ secrets.AZURE_MANAGED_IDENTITY_NAME}}"
CAA_IMAGE="${CAA_IMAGE}"
KBS_IMAGE="${KBS_IMAGE}"
KBS_IMAGE_TAG="${KBS_IMAGE_TAG}"
AZURE_INSTANCE_SIZE="${AZURE_INSTANCE_SIZE}"
TAGS="${{ env.TEST_TAGS }}"
FEDERATED_CREDENTIAL_NAME="${{ env.CLUSTER_NAME }}"
EOF
cat "$TEST_PROVISION_FILE"
# assert that no variable is unset
! grep -E '=x$|=""$' "$TEST_PROVISION_FILE"
- name: Create public ssh key
run: ssh-keygen -t rsa -b 4096 -f install/overlays/azure/id_rsa -N "" -C dev@coco.io
- name: Save the configuration created here
uses: actions/upload-artifact@v3
with:
path: |
src/cloud-api-adaptor/install/overlays/azure/id_rsa.pub
${{ env.TEST_PROVISION_FILE }}
name: e2e-configuration
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# Install AKS cluster in parallel with the podvm image build.
- name: Run provisioner
working-directory: src/cloud-api-adaptor/test/tools
run: |
echo "Creating cluster for ${{ matrix.parameters.id }} machine"
make caa-provisioner-cli
./caa-provisioner-cli -action=createcluster
run-e2e-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/cloud-api-adaptor
needs:
- install-aks
- build-podvm-image
# when none of required steps failed, build-podvm-image can be skipped
if: always() && !failure() && !cancelled()
strategy:
matrix:
parameters:
- id: "tdx"
machine_type: "Standard_DC2es_v5"
- id: "snp"
machine_type: "Standard_DC2as_v5"
steps:
- uses: actions/checkout@v3
- name: Extract go version number
run: echo "GO_VERSION=$(yq -e '.tools.golang' versions.yaml)" >> "$GITHUB_ENV"
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Set Provisioner Environment Variables
run: |
echo "TEST_PROVISION_FILE=${{ format(env.TEST_PROVISION_PATH_TEMPLATE, matrix.parameters.id) }}" >> "$GITHUB_ENV"
echo "CLUSTER_NAME=${{ format(env.CLUSTER_NAME_TEMPLATE, matrix.parameters.id) }}" >> "$GITHUB_ENV"
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Restore the configuration created before
uses: actions/download-artifact@v3
with:
name: e2e-configuration
- name: Add AKS Cluster Subnet ID to test provision file
run: |
NODE_RESOURCE_GROUP="$(az aks show -g ${{ secrets.AZURE_RESOURCE_GROUP }} -n "$CLUSTER_NAME" --query nodeResourceGroup -o tsv)"
SUBNET_ID="$(az network vnet list -g "$NODE_RESOURCE_GROUP" --query '[0].subnets[0].id' -o tsv)"
test -n "$SUBNET_ID"
echo "AZURE_SUBNET_ID=\"${SUBNET_ID}\"" >> "$TEST_PROVISION_FILE"
- name: Extract kbs reference
run: echo "KBS_VERSION=$(yq -e '.git.kbs.reference' versions.yaml)" >> "$GITHUB_ENV"
- name: Checkout kbs Repository
run: |
rm -rf test/trustee
git clone https://github.com/confidential-containers/trustee test/trustee
pushd test/trustee
git checkout "${KBS_VERSION}"
popd
- name: Run e2e test
env:
TEST_PROVISION: "no"
DEPLOY_KBS: "yes"
run: |
# Since we install the cluster in parallel, we need to get the credentials here.
echo "running e2e test for ${{ matrix.parameters.id }} machine"
az aks get-credentials \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name "${CLUSTER_NAME}"
make test-e2e
cleanup:
runs-on: ubuntu-latest
needs:
- run-e2e-test
- generate-podvm-image-version
if: always()
strategy:
matrix:
parameters:
- id: "tdx"
machine_type: "Standard_DC2es_v5"
- id: "snp"
machine_type: "Standard_DC2as_v5"
steps:
- uses: azure/login@v1
name: 'Az CLI login'
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
- name: Delete coco namespace
# We want to delete the coco namespace because CAA might still spawn resources
# which prevents deletion of the AKS cluster
run: |
az aks get-credentials \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name "${{ format(env.CLUSTER_NAME_TEMPLATE, matrix.parameters.id) }}" || true
namespace="confidential-containers-system"
kubectl patch namespace "$namespace" -p '{"metadata":{"finalizers": null }}' || true
kubectl delete namespace "$namespace" || true
- name: Remove podvm image
if: github.event.inputs.podvm-image-id == ''
run: |
# Delete the Pod VM image from the gallery.
az sig image-version delete \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--gallery-name ${{ secrets.AZURE_PODVM_GALLERY_NAME }} \
--gallery-image-definition ${{ vars.AZURE_PODVM_IMAGE_DEF_NAME }} \
--gallery-image-version "${{ needs.generate-podvm-image-version.outputs.image-version }}" || true
- name: Remove container image
if: github.event.inputs.caa-image == ''
run: |
# Delete the CAA container image built for this run.
suffix=".azurecr.io"
registry_name="${ACR_URL%"${suffix}"}"
az acr repository delete \
--name "${registry_name}" \
--image "${ACR_URL}/cloud-api-adaptor:dev-${GITHUB_SHA}" \
--yes || true
- name: Remove dangling VMs
# Remove any VMs that might have been left behind in failed test runs
run: |
vms=$(az resource list \
--tag owner=github-actions \
--tag run="${{ github.run_id }}-${{ github.run_attempt }}" \
-o tsv --query "[?type == 'Microsoft.Compute/virtualMachines'].name")
for vm in $vms; do
az vm delete -n "$vm" -g "${{ secrets.AZURE_RESOURCE_GROUP }}" --yes || true
done
- name: Remove dangling NICs
# Remove any NICs that might have been left behind in failed test runs
# NICs are reserved for 180s for VMs, even if they never launched
run: |
nics=$(az resource list \
--tag owner=github-actions \
--tag run="${{ github.run_id }}-${{ github.run_attempt }}" \
-o tsv --query "[?type == 'Microsoft.Network/networkInterfaces'].name")
sleep 180
for nic in $nics; do
az network nic delete -n "$nic" -g "${{ secrets.AZURE_RESOURCE_GROUP }}" || true
done
- name: Remove AKS cluster
run: |
# Delete the cluster even if it has been deleted already or does not exists.
az aks delete \
--name "${{ format(env.CLUSTER_NAME_TEMPLATE, matrix.parameters.id) }}" \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--no-wait \
--yes || true
- name: Remove federated credential
run: |
az identity federated-credential delete \
--identity-name "${{ secrets.AZURE_MANAGED_IDENTITY_NAME }}" \
--name "${{ format(env.CLUSTER_NAME_TEMPLATE, matrix.parameters.id) }}" \
--resource-group "${{ secrets.AZURE_RESOURCE_GROUP }}" \
--yes || true