-
Notifications
You must be signed in to change notification settings - Fork 72
443 lines (396 loc) · 17.9 KB
/
Copy pathkwok-recipes.yaml
File metadata and controls
443 lines (396 loc) · 17.9 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: KWOK Cluster Validation
on:
push:
branches:
- main
paths:
- 'recipes/**'
- 'kwok/**'
- 'tests/chainsaw/kwok/**'
# The aicr binary that renders/bundles recipes is built from Go source;
# a recipe-rendering regression or dependency bump must trigger KWOK e2e.
- 'pkg/recipe/**'
- 'pkg/bundler/**'
- 'pkg/cli/**'
- 'cmd/aicr/**'
- 'go.mod'
- 'go.sum'
- 'vendor/**'
- '.github/workflows/kwok-recipes.yaml'
- '.github/workflows/kwok-tier3-shard.yaml'
- '.github/actions/kwok-test/**'
- '!**.md'
pull_request:
branches:
- main
paths:
- 'recipes/**'
- 'kwok/**'
- 'tests/chainsaw/kwok/**'
# The aicr binary that renders/bundles recipes is built from Go source;
# a recipe-rendering regression or dependency bump must trigger KWOK e2e.
- 'pkg/recipe/**'
- 'pkg/bundler/**'
- 'pkg/cli/**'
- 'cmd/aicr/**'
- 'go.mod'
- 'go.sum'
- 'vendor/**'
- '.github/workflows/kwok-recipes.yaml'
- '.github/workflows/kwok-tier3-shard.yaml'
- '.github/actions/kwok-test/**'
- '!**.md'
schedule:
# Nightly at 03:00 UTC — Tier 3 full matrix backstop
- cron: '0 3 * * *'
workflow_dispatch:
inputs:
recipe:
description: 'Specific recipe to test (leave empty to test all with service criteria)'
required: false
type: string
permissions:
contents: read
# PR concurrency: cancel in-progress runs for the same PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
discover:
name: Discover Recipes
if: github.event_name != 'schedule' || github.repository == 'nvidia/aicr'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
tier1: ${{ steps.classify.outputs.tier1 }}
tier2: ${{ steps.classify.outputs.tier2 }}
tier3: ${{ steps.classify.outputs.tier3 }}
tier3_batches: ${{ steps.classify.outputs.tier3_batches }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
# Full checkout needed for diff-aware Tier 2 discovery
fetch-depth: 0
- name: Script unit tests (kwok/scripts/lib)
run: bash kwok/scripts/lib/sync-budget_test.sh
- name: Classify recipes into tiers
id: classify
shell: bash
env:
DISPATCH_RECIPE: ${{ github.event.inputs.recipe }}
run: |
set -euo pipefail
# --- workflow_dispatch: test exactly the requested recipe ---
if [[ -n "${DISPATCH_RECIPE}" ]]; then
single=$(jq -nc '[$r]' --arg r "${DISPATCH_RECIPE}")
echo "tier1=${single}" >> "$GITHUB_OUTPUT"
echo "tier2=[]" >> "$GITHUB_OUTPUT"
echo "tier3=[]" >> "$GITHUB_OUTPUT"
echo "tier3_batches=[]" >> "$GITHUB_OUTPUT"
echo "Manual dispatch: ${DISPATCH_RECIPE}"
exit 0
fi
# --- Scan all overlays and classify ---
tier1="[]" # generic overlays (no accelerator specialization)
all="[]" # every testable overlay
for overlay in recipes/overlays/*.yaml; do
name=$(basename "$overlay" .yaml)
service=$(yq eval '.spec.criteria.service // ""' "$overlay" 2>/dev/null || true)
# Skip non-testable overlays (no service, or OCP — needs OpenShift operators)
if [[ -z "$service" || "$service" == "null" || "$service" == "any" || "$service" == "ocp" ]]; then
continue
fi
all=$(echo "$all" | jq -c --arg r "$name" '. + [$r]')
accel=$(yq eval '.spec.criteria.accelerator // ""' "$overlay" 2>/dev/null || true)
if [[ -z "$accel" || "$accel" == "null" || "$accel" == "any" ]]; then
tier1=$(echo "$tier1" | jq -c --arg r "$name" '. + [$r]')
fi
done
# --- Tier 2: diff-aware accelerator tests (PR only) ---
tier2="[]"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
base_ref="${{ github.event.pull_request.base.sha }}"
head_ref="${{ github.event.pull_request.head.sha }}"
if ! changed_files=$(git diff --name-only "${base_ref}..${head_ref}" 2>&1); then
echo "::error::git diff failed — cannot compute Tier 2 affected overlays"
echo "git diff output: ${changed_files}"
exit 1
fi
# If registry.yaml or base.yaml changed, all accelerator overlays are
# potentially affected — promote the full accelerator set to Tier 2.
promote_all=false
if echo "$changed_files" | grep -qE '^recipes/(registry\.yaml|overlays/base\.yaml)$'; then
promote_all=true
echo "registry.yaml or base.yaml changed — all accelerator overlays promoted to Tier 2"
fi
# Build set of affected accelerator-specific overlays
for overlay in recipes/overlays/*.yaml; do
name=$(basename "$overlay" .yaml)
service=$(yq eval '.spec.criteria.service // ""' "$overlay" 2>/dev/null || true)
accel=$(yq eval '.spec.criteria.accelerator // ""' "$overlay" 2>/dev/null || true)
# Only accelerator-specific, KWOK-testable overlays belong in Tier 2
if [[ -z "$service" || "$service" == "null" || "$service" == "any" || "$service" == "ocp" ]]; then
continue
fi
if [[ -z "$accel" || "$accel" == "null" || "$accel" == "any" ]]; then
continue
fi
# If registry.yaml or base.yaml changed, include all accelerator overlays
if [[ "$promote_all" == "true" ]]; then
tier2=$(echo "$tier2" | jq -c --arg r "$name" '. + [$r]')
continue
fi
include=false
# Rule 1: overlay file itself changed
if echo "$changed_files" | grep -qF "recipes/overlays/${name}.yaml"; then
include=true
fi
# Rule 2: check if any ancestor overlay in the base chain changed
if [[ "$include" == "false" ]]; then
current="$overlay"
while true; do
parent=$(yq eval '.spec.base // ""' "$current" 2>/dev/null || true)
if [[ -z "$parent" || "$parent" == "null" ]]; then
break
fi
if echo "$changed_files" | grep -qF "recipes/overlays/${parent}.yaml"; then
include=true
break
fi
current="recipes/overlays/${parent}.yaml"
if [[ ! -f "$current" ]]; then
break
fi
done
fi
# Rule 3: a component values file referenced by this overlay changed
if [[ "$include" == "false" ]]; then
# Collect valuesFile references from this overlay and its base chain
values_files=""
current="$overlay"
while true; do
vf=$(yq eval '.spec.componentRefs[].valuesFile // ""' "$current" 2>/dev/null | grep -v '^$' || true)
if [[ -n "$vf" ]]; then
values_files="${values_files}"$'\n'"${vf}"
fi
parent=$(yq eval '.spec.base // ""' "$current" 2>/dev/null || true)
if [[ -z "$parent" || "$parent" == "null" ]]; then
break
fi
current="recipes/overlays/${parent}.yaml"
if [[ ! -f "$current" ]]; then
break
fi
done
# Check if any referenced values file changed
for vf in $values_files; do
# valuesFile paths are relative to recipes/
if echo "$changed_files" | grep -qF "recipes/${vf}"; then
include=true
break
fi
done
fi
if [[ "$include" == "true" ]]; then
tier2=$(echo "$tier2" | jq -c --arg r "$name" '. + [$r]')
fi
done
fi
# --- Tier 3: full matrix (all testable overlays) ---
tier3="$all"
# --- Tier 3 batching ---
# GitHub caps a single job's matrix at 256 configurations. Tier 3
# crosses every testable recipe with every deployer, so the raw
# cross-product (recipes × deployers) outgrew the cap. Split the
# {recipe, deployer} pairs into batches of <= TIER3_BATCH_SIZE; the
# caller fans each batch out to kwok-tier3-shard.yaml, keeping every
# shard's matrix under the limit. Keep this deployer list in sync
# with the test-tier1 matrix above and the input doc in
# .github/actions/kwok-test/action.yml.
deployers='["helm","argocd-oci","argocd-helm-oci","argocd-git","flux-oci","flux-git"]'
readonly TIER3_BATCH_SIZE=200 # headroom under GitHub's 256 cap
# Fail closed if the batch size is ever raised past the hard limit —
# a too-large batch would otherwise resurface the opaque
# "produced N configurations which exceeds the maximum of 256" error.
if (( TIER3_BATCH_SIZE > 256 )); then
echo "::error::TIER3_BATCH_SIZE=${TIER3_BATCH_SIZE} exceeds GitHub's 256-configuration matrix limit"
exit 1
fi
tier3_batches=$(jq -cn \
--argjson recipes "$tier3" \
--argjson deployers "$deployers" \
--argjson size "$TIER3_BATCH_SIZE" '
[ $recipes[] as $r | $deployers[] as $d | {recipe: $r, deployer: $d} ]
| [ range(0; length; $size) as $i
# id = zero-based batch index; used as the concurrency-group suffix
| {id: ($i / $size | floor), pairs: .[$i:$i+$size]} ]
')
# --- Output ---
echo "tier1=${tier1}" >> "$GITHUB_OUTPUT"
echo "tier2=${tier2}" >> "$GITHUB_OUTPUT"
echo "tier3=${tier3}" >> "$GITHUB_OUTPUT"
echo "tier3_batches=${tier3_batches}" >> "$GITHUB_OUTPUT"
tier3_pairs=$(echo "$tier3_batches" | jq '[.[].pairs[]] | length')
tier3_batch_count=$(echo "$tier3_batches" | jq 'length')
echo "Tier 1 (generic): $(echo "$tier1" | jq 'length') recipe(s)"
echo "Tier 2 (diff-aware): $(echo "$tier2" | jq 'length') recipe(s)"
echo "Tier 3 (full matrix): $(echo "$tier3" | jq 'length') recipe(s) × $(echo "$deployers" | jq 'length') deployer(s) = ${tier3_pairs} pair(s) in ${tier3_batch_count} batch(es)"
# ── Tier 1: PR gate — generic overlays (PR + push, skip on schedule) ──
test-tier1:
name: 'Tier 1: ${{ matrix.recipe }} (${{ matrix.deployer }})'
needs: discover
if: >-
github.event_name != 'schedule' &&
needs.discover.outputs.tier1 != '[]' &&
needs.discover.outputs.tier1 != ''
runs-on: ubuntu-latest
timeout-minutes: 18
strategy:
fail-fast: false
matrix:
recipe: ${{ fromJSON(needs.discover.outputs.tier1) }}
deployer: [helm, argocd-oci, argocd-helm-oci, argocd-git, flux-oci, flux-git]
steps:
- name: Checkout Code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Load versions
id: versions
uses: ./.github/actions/load-versions
- name: Run KWOK test
uses: ./.github/actions/kwok-test
with:
recipe: ${{ matrix.recipe }}
deployer: ${{ matrix.deployer }}
go_version: ${{ steps.versions.outputs.go }}
goreleaser_version: ${{ steps.versions.outputs.goreleaser }}
kind_version: ${{ steps.versions.outputs.kind }}
helm_version: ${{ steps.versions.outputs.helm }}
kwok_version: ${{ steps.versions.outputs.kwok }}
kubectl_version: ${{ steps.versions.outputs.kubectl }}
yq_version: ${{ steps.versions.outputs.yq }}
flux_version: ${{ steps.versions.outputs.flux }}
chainsaw_version: ${{ steps.versions.outputs.chainsaw }}
chainsaw_sha256: ${{ steps.versions.outputs.chainsaw_sha256_linux_amd64 }}
kind_node_image: ${{ steps.versions.outputs.kind_node_image }}
# keep == this job's timeout-minutes (asserted by sync-budget_test.sh)
job_timeout_minutes: '18'
# ── Tier 2: diff-aware accelerator tests (PR only, conditional) ──
test-tier2:
name: 'Tier 2: ${{ matrix.recipe }}'
needs: discover
if: >-
github.event_name == 'pull_request' &&
needs.discover.outputs.tier2 != '[]' &&
needs.discover.outputs.tier2 != ''
runs-on: ubuntu-latest
timeout-minutes: 18
strategy:
fail-fast: false
matrix:
recipe: ${{ fromJSON(needs.discover.outputs.tier2) }}
steps:
- name: Checkout Code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Load versions
id: versions
uses: ./.github/actions/load-versions
- name: Run KWOK test
uses: ./.github/actions/kwok-test
with:
recipe: ${{ matrix.recipe }}
go_version: ${{ steps.versions.outputs.go }}
goreleaser_version: ${{ steps.versions.outputs.goreleaser }}
kind_version: ${{ steps.versions.outputs.kind }}
helm_version: ${{ steps.versions.outputs.helm }}
kwok_version: ${{ steps.versions.outputs.kwok }}
kubectl_version: ${{ steps.versions.outputs.kubectl }}
yq_version: ${{ steps.versions.outputs.yq }}
flux_version: ${{ steps.versions.outputs.flux }}
chainsaw_version: ${{ steps.versions.outputs.chainsaw }}
chainsaw_sha256: ${{ steps.versions.outputs.chainsaw_sha256_linux_amd64 }}
kind_node_image: ${{ steps.versions.outputs.kind_node_image }}
# keep == this job's timeout-minutes (asserted by sync-budget_test.sh)
job_timeout_minutes: '18'
# ── Tier 3: full matrix (push to main + nightly schedule) ──
# The recipe × deployer cross-product exceeds GitHub's 256-config matrix cap,
# so discover splits it into batches and we fan each batch out to the
# kwok-tier3-shard reusable workflow (one shard per batch, each <= 256).
# Per ADR-003: the concurrency group is keyed by SHA so successive merges to
# main never cancel in-flight Tier 3 runs; the batch id keeps every shard of a
# single run in its own group so they all run in parallel.
test-tier3:
needs: discover
concurrency:
group: kwok-tier3-${{ github.sha }}-${{ matrix.batch.id }}
cancel-in-progress: false
if: >-
(github.event_name == 'push' || (github.event_name == 'schedule' && github.repository == 'nvidia/aicr')) &&
needs.discover.outputs.tier3_batches != '[]' &&
needs.discover.outputs.tier3_batches != ''
strategy:
fail-fast: false
matrix:
batch: ${{ fromJSON(needs.discover.outputs.tier3_batches) }}
uses: ./.github/workflows/kwok-tier3-shard.yaml
with:
pairs: ${{ toJSON(matrix.batch.pairs) }}
# ── Summary: aggregate all tiers ──
summary:
name: KWOK Test Summary
needs: [test-tier1, test-tier2, test-tier3]
runs-on: ubuntu-latest
timeout-minutes: 5
if: always()
steps:
- name: Check test results
run: |
echo "## KWOK Cluster Validation Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
tier1="${{ needs.test-tier1.result }}"
tier2="${{ needs.test-tier2.result }}"
tier3="${{ needs.test-tier3.result }}"
echo "| Tier | Result |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Tier 1 (generic) | ${tier1} |" >> $GITHUB_STEP_SUMMARY
echo "| Tier 2 (diff-aware) | ${tier2} |" >> $GITHUB_STEP_SUMMARY
echo "| Tier 3 (full matrix) | ${tier3} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
failed=false
# Tier 1 must pass (unless skipped on schedule-only with no recipes)
if [[ "$tier1" == "failure" || "$tier1" == "cancelled" ]]; then
echo "Tier 1 (generic) failed or was cancelled" >> $GITHUB_STEP_SUMMARY
failed=true
fi
# Tier 2 must pass when it runs (skipped is OK — means no diff-affected overlays)
if [[ "$tier2" == "failure" || "$tier2" == "cancelled" ]]; then
echo "Tier 2 (diff-aware) failed or was cancelled" >> $GITHUB_STEP_SUMMARY
failed=true
fi
# Tier 3 must pass on push/schedule (skipped is OK on PR)
if [[ "$tier3" == "failure" || "$tier3" == "cancelled" ]]; then
echo "Tier 3 (full matrix) failed or was cancelled" >> $GITHUB_STEP_SUMMARY
failed=true
fi
if [[ "$failed" == "true" ]]; then
exit 1
fi
echo "All recipe validations passed" >> $GITHUB_STEP_SUMMARY