Skip to content

Commit 24e9ba7

Browse files
committed
Fix K8s validation: use kubeconform for offline schema validation
kubectl apply --dry-run=client always contacts the API server for resource discovery (independent of --validate=false). In CI without a cluster this fails with "couldn't get current server API group list". Replace the kubectl apply loop with: 1. kubectl kustomize <dir> — renders the kustomization (offline, pure file processing). 2. kubeconform — validates rendered YAML against bundled OpenAPI schemas (no network calls, no cluster needed). This is the standard offline validation pattern: render with kustomize, schema-check with kubeconform. Skip kustomization.yaml automatically since it isn't a K8s resource (kubectl kustomize never emits it).
1 parent 5b4c7ca commit 24e9ba7

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,33 @@ jobs:
205205
chmod +x kubectl
206206
sudo mv kubectl /usr/local/bin/
207207
208-
- name: Validate base manifests
208+
- name: Install kubeconform (offline schema validator)
209209
run: |
210-
failed=0
211-
for f in k8s/base/*.yaml; do
212-
echo "Validating $f..."
213-
if ! kubectl apply --dry-run=client --validate=false -f "$f" 2>&1; then
214-
echo "::error::Validation failed for $f"
215-
failed=1
216-
fi
217-
done
218-
exit $failed
219-
220-
- name: Validate dev overlay
221-
run: kubectl kustomize k8s/overlays/dev > /dev/null
222-
223-
- name: Validate prod overlay
224-
run: kubectl kustomize k8s/overlays/prod > /dev/null
210+
curl -L -o kubeconform.tar.gz \
211+
https://github.com/yannh/kubeconform/releases/download/v0.6.7/kubeconform-linux-amd64.tar.gz
212+
tar -xzf kubeconform.tar.gz kubeconform
213+
chmod +x kubeconform
214+
sudo mv kubeconform /usr/local/bin/
215+
216+
- name: Validate base manifests (kubeconform, offline)
217+
run: |
218+
# Render the base kustomization, then validate all rendered manifests
219+
# against the bundled OpenAPI schemas. Skips kustomization.yaml (not a
220+
# K8s resource) and skips CRDs we don't ship.
221+
kubectl kustomize k8s/base | \
222+
kubeconform -strict -summary -ignore-missing-schemas \
223+
-schema-location default \
224+
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
225+
226+
- name: Validate dev overlay (render + kubeconform)
227+
run: |
228+
kubectl kustomize k8s/overlays/dev | \
229+
kubeconform -strict -summary -ignore-missing-schemas
230+
231+
- name: Validate prod overlay (render + kubeconform)
232+
run: |
233+
kubectl kustomize k8s/overlays/prod | \
234+
kubeconform -strict -summary -ignore-missing-schemas
225235
226236
# ── Release Docker Images ───────────────────────────────────────────────────
227237
release-docker:

0 commit comments

Comments
 (0)