-
Notifications
You must be signed in to change notification settings - Fork 17
384 lines (362 loc) · 15.5 KB
/
bm_maintenance.yml
File metadata and controls
384 lines (362 loc) · 15.5 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
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
name: bare metal maintenance
on:
workflow_call:
secrets:
GITHUB_TOKEN_IN:
required: true
CACHIX_AUTH_TOKEN:
required: true
TEAMS_CI_WEBHOOK:
required: true
workflow_dispatch:
push:
branches:
- main
paths:
- ".github/workflows/bm_maintenance.yml"
- "tools/bm-maintenance/**"
- "packages/by-name/scripts/upgrade-gpu-operator/**"
env:
container_registry: ghcr.io/edgelesssys
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
build-image:
name: "Build cleanup-bare-metal image"
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
outputs:
image: "${{ steps.build.outputs.image }}"
env:
SET: base
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: ./.github/actions/setup_nix
with:
githubToken: ${{ secrets.GITHUB_TOKEN_IN || secrets.GITHUB_TOKEN }}
cachixToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
- name: Log in to ghcr.io Container registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN_IN || secrets.GITHUB_TOKEN }}
- name: Create justfile.env
run: |
cat <<EOF > justfile.env
container_registry=${{ env.container_registry }}
set=${SET}
EOF
- name: Build and push cleanup-bare-metal image
id: build
env:
ghcr: ${{ env.container_registry }}
run: |
just push cleanup-bare-metal
image=$(sed -n "s#${{ env.container_registry }}/contrast/cleanup-bare-metal:latest=##p" ./workspace/just.containerlookup)
echo "image=${image}" >> "$GITHUB_OUTPUT"
update-resources:
name: "Update resources ${{ matrix.platform.name }}"
runs-on: ${{ matrix.platform.runner }}
needs: build-image
outputs:
snp: ${{ steps.report.outputs.Metal-QEMU-SNP }}
tdx: ${{ steps.report.outputs.Metal-QEMU-TDX }}
snp-gpu: ${{ steps.report.outputs.Metal-QEMU-SNP-GPU }}
snp-dev: ${{ steps.report.outputs.Metal-QEMU-SNP-DEV }}
tdx-gpu: ${{ steps.report.outputs.Metal-QEMU-TDX-GPU }}
env:
SET: base
permissions:
contents: read
strategy:
matrix:
platform:
- name: Metal-QEMU-SNP
runner: SNP
- name: Metal-QEMU-TDX
runner: TDX
- name: Metal-QEMU-SNP-GPU
runner: SNP-GPU
- name: Metal-QEMU-SNP-DEV
runner: DEV
- name: Metal-QEMU-TDX-GPU
runner: TDX-GPU
fail-fast: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
- name: Update storageclass
run: |
nix build ".#${SET}.csi-driver-host-path"
kubectl apply -k result
- name: Update sync fifo for GPU platform
if: ${{ matrix.platform.name == 'Metal-QEMU-SNP-GPU' || matrix.platform.name == 'Metal-QEMU-TDX-GPU' }}
run: |
kubectl apply -k tools/bm-maintenance/sync-fifo
kubectl rollout status statefulset/sync --timeout=5m
kubectl wait --for=jsonpath='{.status.loadBalancer.ingress[0].ip}' --timeout=5m svc/sync
nix run ".#${SET}.scripts.renew-sync-fifo"
- name: Update namespace cleanup cronjob
id: update
env:
IMAGE: ${{ needs.build-image.outputs.image }}
run: |
sed -i "s#@@REPLACE_IMAGE@@#${IMAGE}#g" ./tools/bm-maintenance/cleanup-namespaces.yml
kubectl apply -f ./tools/bm-maintenance/cleanup-namespaces.yml
- name: Update gpu operator
if: ${{ matrix.platform.name == 'Metal-QEMU-SNP-GPU' || matrix.platform.name == 'Metal-QEMU-TDX-GPU' }}
run: |
GPU_OPERATOR_VERSION=$(jq -r '."gpu-operator".currentValue' ./tools/bm-maintenance/versions.json)
OPTS=(--version "$GPU_OPERATOR_VERSION")
if [[ "${{ matrix.platform.name }}" == "Metal-QEMU-TDX-GPU" ]]; then
OPTS+=(--blackwell)
fi
nix run ".#${SET}.scripts.upgrade-gpu-operator" -- "${OPTS[@]}"
- name: Report success
id: report
run: |
echo "${{ matrix.platform.name }}=success" >> "$GITHUB_OUTPUT"
cleanup:
name: "Cleanup ${{ matrix.platform.name }}"
runs-on: ${{ matrix.platform.runner }}
needs: build-image
outputs:
snp: ${{ steps.update.outputs.Metal-QEMU-SNP }}
tdx: ${{ steps.update.outputs.Metal-QEMU-TDX }}
snp-gpu: ${{ steps.update.outputs.Metal-QEMU-SNP-GPU }}
snp-dev: ${{ steps.update.outputs.Metal-QEMU-SNP-DEV }}
tdx-gpu: ${{ steps.update.outputs.Metal-QEMU-TDX-GPU }}
strategy:
matrix:
platform:
- name: Metal-QEMU-SNP
runner: SNP
- name: Metal-QEMU-TDX
runner: TDX
- name: Metal-QEMU-SNP-GPU
runner: SNP-GPU
- name: Metal-QEMU-SNP-DEV
runner: DEV
- name: Metal-QEMU-TDX-GPU
runner: TDX-GPU
fail-fast: false
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
- name: Apply resources
env:
IMAGE: ${{ needs.build-image.outputs.image }}
run: |
K3S_VERSION=$(jq -r '.k3s.currentValue' ./tools/bm-maintenance/versions.json)
sed -i "s#@@REPLACE_IMAGE@@#${IMAGE}#g" ./tools/bm-maintenance/cleanup.yml
sed -i "s#@@REPLACE_K3S_VERSION@@#${K3S_VERSION}#g" ./tools/bm-maintenance/cleanup.yml
kubectl apply -f ./tools/bm-maintenance/cleanup.yml
- name: Wait for cleanup job
id: update
run: |
kubectl wait -n maintenance-cleanup --for=condition=complete --timeout=600s job/cleanup-maintenance
echo "${{ matrix.platform.name }}=success" >> "$GITHUB_OUTPUT"
- name: Collect logs and cleanup
if: always()
run: |
kubectl logs -n maintenance-cleanup job/cleanup-maintenance || true
kubectl delete -f ./tools/bm-maintenance/cleanup.yml || true
cleanup-containerd:
name: "Cleanup Containerd ${{ matrix.platform.name }}"
runs-on: ${{ matrix.platform.runner }}
needs: build-image
outputs:
snp: ${{ steps.update.outputs.Metal-QEMU-SNP }}
tdx: ${{ steps.update.outputs.Metal-QEMU-TDX }}
snp-gpu: ${{ steps.update.outputs.Metal-QEMU-SNP-GPU }}
snp-dev: ${{ steps.update.outputs.Metal-QEMU-SNP-DEV }}
tdx-gpu: ${{ steps.update.outputs.Metal-QEMU-TDX-GPU }}
strategy:
matrix:
platform:
- name: Metal-QEMU-SNP
runner: SNP
- name: Metal-QEMU-TDX
runner: TDX
- name: Metal-QEMU-SNP-GPU
runner: SNP-GPU
- name: Metal-QEMU-SNP-DEV
runner: DEV
- name: Metal-QEMU-TDX-GPU
runner: TDX-GPU
fail-fast: false
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
- name: Apply resources
env:
IMAGE: ${{ needs.build-image.outputs.image }}
run: |
sed -i "s#@@REPLACE_IMAGE@@#${IMAGE}#g" ./tools/bm-maintenance/cleanup-containerd.yml
kubectl apply -f ./tools/bm-maintenance/cleanup-containerd.yml
- name: Wait for cleanup job
id: update
run: |
kubectl wait -n maintenance-containerd-cleanup --for=condition=complete --timeout=600s job/containerd-cleanup-maintenance
echo "${{ matrix.platform.name }}=success" >> "$GITHUB_OUTPUT"
- name: Collect logs and cleanup
if: always()
run: |
kubectl logs -n maintenance-containerd-cleanup job/containerd-cleanup-maintenance || true
kubectl delete -f ./tools/bm-maintenance/cleanup-containerd.yml || true
nix-gc:
name: "Nix gc ${{ matrix.platform.name }}"
runs-on: ${{ matrix.platform.runner }}
needs: build-image
outputs:
snp: ${{ steps.update.outputs.Metal-QEMU-SNP }}
tdx: ${{ steps.update.outputs.Metal-QEMU-TDX }}
snp-gpu: ${{ steps.update.outputs.Metal-QEMU-SNP-GPU }}
snp-dev: ${{ steps.update.outputs.Metal-QEMU-SNP-DEV }}
tdx-gpu: ${{ steps.update.outputs.Metal-QEMU-TDX-GPU }}
strategy:
matrix:
platform:
- name: Metal-QEMU-SNP
runner: SNP
- name: Metal-QEMU-TDX
runner: TDX
- name: Metal-QEMU-SNP-GPU
runner: SNP-GPU
- name: Metal-QEMU-SNP-DEV
runner: DEV
- name: Metal-QEMU-TDX-GPU
runner: TDX-GPU
fail-fast: false
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
- name: Apply resources
env:
IMAGE: ${{ needs.build-image.outputs.image }}
run: |
sed -i "s#@@REPLACE_IMAGE@@#${IMAGE}#g" ./tools/bm-maintenance/nix-gc.yml
kubectl apply -f ./tools/bm-maintenance/nix-gc.yml
- name: Wait for nix garbage collection job
id: update
run: |
kubectl wait -n maintenance-nix-gc --for=condition=complete --timeout=600s job/nix-garbage-collection
echo "${{ matrix.platform.name }}=success" >> "$GITHUB_OUTPUT"
- name: Collect logs and cleanup
if: always()
run: |
kubectl logs -n maintenance-nix-gc job/nix-garbage-collection || true
kubectl delete -f ./tools/bm-maintenance/nix-gc.yml || true
notify-teams:
name: "Notify teams channel of failure"
runs-on: ubuntu-24.04
needs: [build-image, update-resources, cleanup, cleanup-containerd, nix-gc]
if: always() && github.event_name == 'schedule' && github.run_attempt == 1
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Get JSON output
id: get-json
env:
UPDATE_RESOURCES_SNP: ${{ needs.update-resources.outputs.snp }}
UPDATE_RESOURCES_TDX: ${{ needs.update-resources.outputs.tdx }}
UPDATE_RESOURCES_SNP_GPU: ${{ needs.update-resources.outputs.snp-gpu }}
UPDATE_RESOURCES_SNP_DEV: ${{ needs.update-resources.outputs.snp-dev }}
UPDATE_RESOURCES_TDX_GPU: ${{ needs.update-resources.outputs.tdx-gpu }}
CLEANUP_SNP: ${{ needs.cleanup.outputs.snp }}
CLEANUP_TDX: ${{ needs.cleanup.outputs.tdx }}
CLEANUP_SNP_GPU: ${{ needs.cleanup.outputs.snp-gpu }}
CLEANUP_SNP_DEV: ${{ needs.cleanup.outputs.snp-dev }}
CLEANUP_TDX_GPU: ${{ needs.cleanup.outputs.tdx-gpu }}
CLEANUP_CONTAINERD_SNP: ${{ needs.cleanup-containerd.outputs.snp }}
CLEANUP_CONTAINERD_TDX: ${{ needs.cleanup-containerd.outputs.tdx }}
CLEANUP_CONTAINERD_SNP_GPU: ${{ needs.cleanup-containerd.outputs.snp-gpu }}
CLEANUP_CONTAINERD_SNP_DEV: ${{ needs.cleanup-containerd.outputs.snp-dev }}
CLEANUP_CONTAINERD_TDX_GPU: ${{ needs.cleanup-containerd.outputs.tdx-gpu }}
NIX_GC_SNP: ${{ needs.nix-gc.outputs.snp }}
NIX_GC_TDX: ${{ needs.nix-gc.outputs.tdx }}
NIX_GC_SNP_GPU: ${{ needs.nix-gc.outputs.snp-gpu }}
NIX_GC_SNP_DEV: ${{ needs.nix-gc.outputs.snp-dev }}
NIX_GC_TDX_GPU: ${{ needs.nix-gc.outputs.tdx-gpu }}
IMAGE_BUILD_RESULT: ${{ needs.build-image.outputs.image }}
GITHUB_EVENT_SCHEDULE: ${{ github.event.schedule }}
run: |
if [[ -z "${IMAGE_BUILD_RESULT}" ]]; then
echo 'json=[{"title": "Job ID", "value": "build-image"}]' >> "$GITHUB_OUTPUT"
exit 0
fi
declare -a entries snp tdx snp_gpu snp_dev tdx_gpu
[[ "${UPDATE_RESOURCES_SNP}" != "success" ]] && snp+=("update-resources")
[[ "${CLEANUP_SNP}" != "success" ]] && snp+=("cleanup")
[[ "${NIX_GC_SNP}" != "success" ]] && snp+=("nix-gc")
[[ "${UPDATE_RESOURCES_TDX}" != "success" ]] && tdx+=("update-resources")
[[ "${CLEANUP_TDX}" != "success" ]] && tdx+=("cleanup")
[[ "${NIX_GC_TDX}" != "success" ]] && tdx+=("nix-gc")
[[ "${UPDATE_RESOURCES_SNP_GPU}" != "success" ]] && snp_gpu+=("update-resources")
[[ "${CLEANUP_SNP_GPU}" != "success" ]] && snp_gpu+=("cleanup")
[[ "${NIX_GC_SNP_GPU}" != "success" ]] && snp_gpu+=("nix-gc")
[[ "${UPDATE_RESOURCES_SNP_DEV}" != "success" ]] && snp_dev+=("update-resources")
[[ "${CLEANUP_SNP_DEV}" != "success" ]] && snp_dev+=("cleanup")
[[ "${NIX_GC_SNP_DEV}" != "success" ]] && snp_dev+=("nix-gc")
[[ "${UPDATE_RESOURCES_TDX_GPU}" != "success" ]] && tdx_gpu+=("update-resources")
[[ "${CLEANUP_TDX_GPU}" != "success" ]] && tdx_gpu+=("cleanup")
[[ "${NIX_GC_TDX_GPU}" != "success" ]] && tdx_gpu+=("nix-gc")
if [[ "${GITHUB_EVENT_SCHEDULE}" == "0 2 * * 5" ]]; then
[[ "${CLEANUP_CONTAINERD_SNP}" != "success" ]] && snp+=("cleanup-containerd")
[[ "${CLEANUP_CONTAINERD_TDX}" != "success" ]] && tdx+=("cleanup-containerd")
[[ "${CLEANUP_CONTAINERD_SNP_GPU}" != "success" ]] && snp_gpu+=("cleanup-containerd")
[[ "${CLEANUP_CONTAINERD_SNP_DEV}" != "success" ]] && snp_dev+=("cleanup-containerd")
[[ "${CLEANUP_CONTAINERD_TDX_GPU}" != "success" ]] && tdx_gpu+=("cleanup-containerd")
fi
if [[ "${#snp[@]}" -gt 0 ]]; then
entries+=("{\"title\": \"Metal-QEMU-SNP\", \"value\": \"$(str="${snp[*]}"; echo "${str// /, }")\"}")
fi
if [[ "${#tdx[@]}" -gt 0 ]]; then
entries+=("{\"title\": \"Metal-QEMU-TDX\", \"value\": \"$(str="${tdx[*]}"; echo "${str// /, }")\"}")
fi
if [[ "${#snp_gpu[@]}" -gt 0 ]]; then
entries+=("{\"title\": \"Metal-QEMU-SNP-GPU\", \"value\": \"$(str="${snp_gpu[*]}"; echo "${str// /, }")\"}")
fi
if [[ "${#snp_dev[@]}" -gt 0 ]]; then
entries+=("{\"title\": \"Metal-QEMU-SNP-DEV\", \"value\": \"$(str="${snp_dev[*]}"; echo "${str// /, }")\"}")
fi
if [[ "${#tdx_gpu[@]}" -gt 0 ]]; then
entries+=("{\"title\": \"Metal-QEMU-TDX-GPU\", \"value\": \"$(str="${tdx_gpu[*]}"; echo "${str// /, }")\"}")
fi
if [[ "${#entries[@]}" -eq 0 ]]; then
echo "No failures detected, nothing to notify."
exit 0
fi
json=$(IFS=,; echo "${entries[*]}")
echo "json=[${json}]" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/post_to_teams
if: ${{ steps.get-json.outputs.json != '' }}
with:
webhook: ${{ secrets.TEAMS_CI_WEBHOOK }}
title: "${{ github.workflow }} failed"
message: "workflow ${{ github.workflow }} failed"
additionalFields: "${{ steps.get-json.outputs.json }}"