add kubeconform action #168

Merged
aggarwalakshun merged 10 commits from kubeconform into main 2025-12-03 07:44:28 +00:00
Showing only changes of commit c65fef70ff - Show all commits

View File

@@ -2,7 +2,7 @@ name: Validate Kubernetes Manifests
on: on:
pull_request: pull_request:
branches: [ main] branches: [main]
jobs: jobs:
kubeconform: kubeconform:
@@ -12,20 +12,68 @@ jobs:
steps: steps:
- name: Setup environment - name: Setup environment
run: | run: |
pacman -Syu --noconfirm kubeconform git findutils pacman -Syu --noconfirm kubeconform git yq nodejs npm
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create kubeconform configuration
run: | run: |
git clone https://gitea.akshun-lab.cc/aggarwalakshun/k3s.git /mnt cat > /tmp/kubeconform-config.yaml << 'EOF'
schema_location:
- default
- "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json"
EOF
- name: Validate Manifests - name: Validate Manifests
run: | run: |
find /mnt -type f \( -name "*.yml" \) \ # Create a cache directory for schemas
-not -path "*/.gitea/*" \ mkdir -p /tmp/kubeconform-cache
-print0 | xargs -0 --no-run-if-empty kubeconform \
-verbose \ # Validate manifests with proper schema resolution
-summary \ find . -type f \( -name "*.yml" \) \
-schema-location default \ -not -path "./.gitea/*" \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/bitnami.com/sealedsecret_v1alpha1.json' \ -exec sh -c '
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/helm.toolkit.fluxcd.io/helmrelease_v2.json' \ for file do
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/metallb.io/ipaddresspool_v1beta1.json' \ echo "=== Validating: $file ==="
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/metallb.io/l2advertisement_v1beta1.json' \ if yq -e "select(.kind == \"HelmRelease\")" "$file" >/dev/null 2>&1; then
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/source.toolkit.fluxcd.io/helmrepository_v1.json' echo "Found HelmRelease - using fluxcd schema"
kubeconform \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/helm.toolkit.fluxcd.io/helmrelease_v2.json" \
-output json \
"$file"
elif yq -e "select(.kind == \"HelmRepository\")" "$file" >/dev/null 2>&1; then
echo "Found HelmRepository - using fluxcd schema"
kubeconform \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/source.toolkit.fluxcd.io/helmrepository_v1.json" \
-output json \
"$file"
elif yq -e "select(.kind == \"L2Advertisement\")" "$file" >/dev/null 2>&1; then
echo "Found L2Advertisement - using metallb schema"
kubeconform \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/metallb.io/l2advertisement_v1beta1.json" \
-output json \
"$file"
elif yq -e "select(.kind == \"IPAddressPool\")" "$file" >/dev/null 2>&1; then
echo "Found IPAddressPool - using metallb schema"
kubeconform \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/metallb.io/ipaddresspool_v1beta1.json" \
-output json \
"$file"
elif yq -e "select(.kind == \"SealedSecret\")" "$file" >/dev/null 2>&1; then
echo "Found SealedSecret - using bitnami schema"
kubeconform \
-schema-location "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/bitnami.com/sealedsecret_v1alpha1.json" \
-output json \
"$file"
else
echo "Validating with default schemas"
kubeconform \
-schema-location default \
-output json \
"$file"
fi
done
' sh {} +