better-kubeconform #205

Merged
aggarwalakshun merged 7 commits from better-kubeconform into main 2025-12-12 23:13:42 +05:30

View File

@@ -1,10 +1,12 @@
name: Validate Kubernetes Manifests name: Validate Kubernetes Manifests
on: on:
pull_request:
branches: [main]
push: push:
branches: [main] paths:
- '**.yml'
- '**.yaml'
- '!.gitea/workflows/**'
- '!clusters/**/system-upgrade/crd.yml'
jobs: jobs:
kubeconform: kubeconform:
@@ -37,6 +39,7 @@ jobs:
files: | files: |
**.yml **.yml
!.gitea/workflows/** !.gitea/workflows/**
!clusters/**/system-upgrade/crd.yml
- name: Validate Manifests - name: Validate Manifests
if: steps.changed-files.outputs.any_changed == 'true' if: steps.changed-files.outputs.any_changed == 'true'
@@ -53,6 +56,7 @@ jobs:
["IPAddressPool"]="metallb.io/ipaddresspool_v1beta1.json" ["IPAddressPool"]="metallb.io/ipaddresspool_v1beta1.json"
["SealedSecret"]="bitnami.com/sealedsecret_v1alpha1.json" ["SealedSecret"]="bitnami.com/sealedsecret_v1alpha1.json"
["ClusterPolicy"]="nvidia.com/clusterpolicy_v1.json" ["ClusterPolicy"]="nvidia.com/clusterpolicy_v1.json"
["Plan"]="upgrade.cattle.io/plan_v1.json"
) )
EXIT_CODE=0 EXIT_CODE=0
@@ -62,29 +66,33 @@ jobs:
while IFS= read -r file; do while IFS= read -r file; do
[ -z "$file" ] && continue [ -z "$file" ] && continue
echo "=== Validating: $file ===" echo "=== Validating: $file ==="
KIND=$(yq -r '.kind // ""' "$file" 2>/dev/null || echo "") MANIFESTS=$(yq e '.[]' "$file" | jq -c 'select(.kind != null)')
if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then for manifest in "${MANIFESTS[@]}"; do
echo "Found $KIND - using custom schema" KIND=$(echo $manifest | yq -r '.kind // ""')
SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
if ! /kubeconform \ if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then
-schema-location "$SCHEMA_URL" \ echo "Found $KIND - using custom schema"
-cache "$KUBECONFORM_CACHE_DIR" \ SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
-output json \
"$file"; then if ! /kubeconform \
EXIT_CODE=1 -schema-location "$SCHEMA_URL" \
-cache "$KUBECONFORM_CACHE_DIR" \
-output json \
"$manifest"; then
EXIT_CODE=1
fi
else
echo "Validating with default schemas"
if ! /kubeconform \
-schema-location default \
-cache "$KUBECONFORM_CACHE_DIR" \
-output json \
"$manifest"; then
EXIT_CODE=1
fi
fi fi
else done
echo "Validating with default schemas"
if ! /kubeconform \
-schema-location default \
-cache "$KUBECONFORM_CACHE_DIR" \
-output json \
"$file"; then
EXIT_CODE=1
fi
fi
echo "" echo ""
done <<< "${ALL_CHANGED_FILES}" done <<< "${ALL_CHANGED_FILES}"