Skip to content

Commit 409d1ae

Browse files
authored
refactor: codebase consistency fixes and test coverage (#179)
1 parent 068cf45 commit 409d1ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+519
-792
lines changed

.github/actions/kwok-test/action.yml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
# limitations under the License.
1414

1515
name: 'KWOK Cluster Test'
16-
description: 'Test recipes using KWOK simulated nodes in a shared Kind cluster'
16+
description: 'Test a single recipe using KWOK simulated nodes in a Kind cluster'
1717

1818
inputs:
1919
recipe:
20-
description: 'Recipe name to test (empty = all testable recipes)'
21-
required: false
22-
default: ''
20+
description: 'Recipe name to test'
21+
required: true
2322
go_version:
2423
description: 'Go version to install'
2524
required: true
@@ -156,49 +155,42 @@ runs:
156155
make build
157156
ls -la dist/
158157
159-
- name: Run KWOK recipe tests
158+
- name: Run KWOK recipe test
160159
id: validate
161160
shell: bash
162161
env:
163-
KWOK_CLUSTER: aicr-kwok-test
164162
KIND_NODE_IMAGE: ${{ inputs.kind_node_image }}
165163
run: |
166-
bash kwok/scripts/run-all-recipes.sh ${{ inputs.recipe }}
164+
KWOK_CLUSTER=aicr-kwok-test bash kwok/scripts/run-all-recipes.sh ${{ inputs.recipe }}
167165
168166
- name: Collect debug artifacts
169167
if: failure()
170168
shell: bash
171-
env:
172-
KWOK_CLUSTER: aicr-kwok-test
173169
run: |
174170
mkdir -p /tmp/kwok-debug-artifacts
175-
kubectl get all --all-namespaces > /tmp/kwok-debug-artifacts/all-resources.txt || true
176-
kubectl get nodes -o wide > /tmp/kwok-debug-artifacts/nodes.txt || true
177-
kubectl get nodes -l type=kwok -o yaml > /tmp/kwok-debug-artifacts/kwok-nodes.yaml || true
178-
kubectl get events --all-namespaces --sort-by='.lastTimestamp' > /tmp/kwok-debug-artifacts/events.txt || true
179-
kubectl get pods --all-namespaces -o wide > /tmp/kwok-debug-artifacts/pods.txt || true
180-
181-
# Get pending pod details
182-
for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
183-
for pod in $(kubectl get pods -n "$ns" --field-selector=status.phase=Pending -o jsonpath='{.items[*].metadata.name}' 2>/dev/null); do
184-
kubectl describe pod -n "$ns" "$pod" > "/tmp/kwok-debug-artifacts/pending-${ns}-${pod}.txt" 2>/dev/null || true
185-
done
171+
# Collect from whichever cluster is still running
172+
for cluster in $(kind get clusters 2>/dev/null); do
173+
kind export kubeconfig --name "$cluster" 2>/dev/null || continue
174+
kubectl get all --all-namespaces > "/tmp/kwok-debug-artifacts/${cluster}-resources.txt" || true
175+
kubectl get nodes -o wide > "/tmp/kwok-debug-artifacts/${cluster}-nodes.txt" || true
176+
kubectl get events --all-namespaces --sort-by='.lastTimestamp' > "/tmp/kwok-debug-artifacts/${cluster}-events.txt" || true
177+
kubectl get pods --all-namespaces -o wide > "/tmp/kwok-debug-artifacts/${cluster}-pods.txt" || true
186178
done
187179
188180
- name: Export Kind logs
189181
if: failure()
190182
shell: bash
191-
env:
192-
KWOK_CLUSTER: aicr-kwok-test
193183
run: |
194184
mkdir -p /tmp/kwok-kind-logs
195-
kind export logs /tmp/kwok-kind-logs --name "${KWOK_CLUSTER}" || true
185+
for cluster in $(kind get clusters 2>/dev/null); do
186+
kind export logs "/tmp/kwok-kind-logs/${cluster}" --name "$cluster" || true
187+
done
196188
197189
- name: Upload debug artifacts
198190
if: failure() && inputs.upload_artifacts == 'true'
199191
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
200192
with:
201-
name: kwok-debug-${{ github.run_id }}
193+
name: kwok-debug-${{ inputs.recipe }}-${{ github.run_id }}
202194
path: |
203195
/tmp/kwok-debug-artifacts/
204196
/tmp/kwok-kind-logs/
@@ -207,8 +199,8 @@ runs:
207199
- name: Cleanup
208200
if: always()
209201
shell: bash
210-
env:
211-
KWOK_CLUSTER: aicr-kwok-test
212202
run: |
213-
kind delete cluster --name "${KWOK_CLUSTER}" || true
203+
for cluster in $(kind get clusters 2>/dev/null); do
204+
kind delete cluster --name "$cluster" || true
205+
done
214206
docker system prune -f || true

.github/workflows/kwok-recipes.yaml

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,59 @@ concurrency:
4646
cancel-in-progress: true
4747

4848
jobs:
49+
discover:
50+
name: Discover Recipes
51+
runs-on: ubuntu-latest
52+
timeout-minutes: 2
53+
outputs:
54+
recipes: ${{ steps.find.outputs.recipes }}
55+
steps:
56+
- name: Checkout overlays
57+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
58+
with:
59+
persist-credentials: false
60+
sparse-checkout: |
61+
recipes/overlays
62+
sparse-checkout-cone-mode: false
63+
64+
- name: Find testable recipes
65+
id: find
66+
shell: bash
67+
run: |
68+
set -euo pipefail
69+
70+
# If a specific recipe was requested via workflow_dispatch, use it
71+
if [[ -n "${{ github.event.inputs.recipe }}" ]]; then
72+
recipes=$(jq -nc '[$recipe]' --arg recipe "${{ github.event.inputs.recipe }}")
73+
echo "recipes=${recipes}" >> "$GITHUB_OUTPUT"
74+
echo "Using specific recipe: ${{ github.event.inputs.recipe }}"
75+
exit 0
76+
fi
77+
78+
# Scan overlays for recipes with a cloud service criteria
79+
recipes="[]"
80+
for overlay in recipes/overlays/*.yaml; do
81+
name=$(basename "$overlay" .yaml)
82+
# yq is pre-installed on ubuntu-latest runners
83+
service=$(yq eval '.spec.criteria.service // ""' "$overlay" 2>/dev/null || true)
84+
if [[ -n "$service" && "$service" != "null" && "$service" != "any" ]]; then
85+
recipes=$(echo "$recipes" | jq -c --arg r "$name" '. + [$r]')
86+
fi
87+
done
88+
89+
echo "recipes=${recipes}" >> "$GITHUB_OUTPUT"
90+
echo "Discovered $(echo "$recipes" | jq 'length') recipe(s): $(echo "$recipes" | jq -c '.')"
91+
4992
test:
50-
name: KWOK Recipe Tests
93+
name: KWOK (${{ matrix.recipe }})
94+
needs: discover
95+
if: ${{ needs.discover.outputs.recipes != '[]' && needs.discover.outputs.recipes != '' }}
5196
runs-on: ubuntu-latest
52-
timeout-minutes: 45
97+
timeout-minutes: 15
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
recipe: ${{ fromJSON(needs.discover.outputs.recipes) }}
53102
steps:
54103
- name: Checkout Code
55104
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -60,10 +109,10 @@ jobs:
60109
id: versions
61110
uses: ./.github/actions/load-versions
62111

63-
- name: Run KWOK tests
112+
- name: Run KWOK test
64113
uses: ./.github/actions/kwok-test
65114
with:
66-
recipe: ${{ github.event.inputs.recipe }}
115+
recipe: ${{ matrix.recipe }}
67116
go_version: ${{ steps.versions.outputs.go }}
68117
kind_version: ${{ steps.versions.outputs.kind }}
69118
helm_version: ${{ steps.versions.outputs.helm }}
@@ -85,6 +134,8 @@ jobs:
85134
86135
if [[ "${{ needs.test.result }}" == "success" ]]; then
87136
echo "All recipe validations passed" >> $GITHUB_STEP_SUMMARY
137+
elif [[ "${{ needs.test.result }}" == "skipped" ]]; then
138+
echo "No recipes to test" >> $GITHUB_STEP_SUMMARY
88139
elif [[ "${{ needs.test.result }}" == "cancelled" ]]; then
89140
echo "Recipe validations were cancelled" >> $GITHUB_STEP_SUMMARY
90141
exit 1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ tags
123123
# Claude
124124
.claude/settings.local.json
125125
docs/plans
126+
.worktrees/
126127

127128
# Validator generator scaffolding output
128129
pkg/validator/checks/**/*_README.md

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,6 @@ endif
479479
kwok-test-all: build ## Run all KWOK recipe tests in a shared cluster
480480
@bash kwok/scripts/run-all-recipes.sh
481481

482-
.PHONY: kwok-test-all-parallel
483-
kwok-test-all-parallel: build ## Run all KWOK recipe tests in parallel across multiple clusters
484-
@bash kwok/scripts/run-all-recipes-parallel.sh
485-
486482
# =============================================================================
487483
# Combined Development Targets
488484
# =============================================================================
@@ -547,7 +543,6 @@ help-full: ## Displays commands grouped by category
547543
@echo " make kwok-status Show KWOK cluster and node status"
548544
@echo " make kwok-e2e Full KWOK workflow (RECIPE=<name>)"
549545
@echo " make kwok-test-all Run all recipes in shared cluster"
550-
@echo " make kwok-test-all-parallel Run all recipes in parallel clusters (faster)"
551546
@echo ""
552547
@echo "\033[1m=== Code Maintenance ===\033[0m"
553548
@echo " make tidy Format code and update dependencies"

0 commit comments

Comments
 (0)