include-system-upgrade-in-kubeconform-validation #203

Closed
aggarwalakshun wants to merge 12 commits from include-system-upgrade-in-kubeconform-validation into main
3 changed files with 37 additions and 26 deletions

View File

@@ -53,40 +53,49 @@ 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
export KUBECONFORM_CACHE_DIR="/tmp/kubeconform-cache" export KUBECONFORM_CACHE_DIR="/tmp/kubeconform-cache"
mkdir -p "$KUBECONFORM_CACHE_DIR" mkdir -p "$KUBECONFORM_CACHE_DIR"
while IFS= read -r file; do for file in ${ALL_CHANGED_FILES}; do
[ -z "$file" ] && continue [ -z "$file" ] && continue
echo "=== Validating: $file ===" echo "=== Validating: $file ==="
KIND=$(yq -r '.kind // ""' "$file" 2>/dev/null || echo "") DOC_COUNT=$(yq eval-all '...' "$file" | grep -c '^---')
for i in $(seq 0 $((DOC_COUNT - 1))); do
if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then TMP_DOC="/tmp/doc_${i}_$$.yaml"
echo "Found $KIND - using custom schema" yq eval-all ".[$i]" "$file" > "$TMP_DOC"
SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}" if [[ ! -s "$TMP_DOC" ]] || grep -q '^\s*$' "$TMP_DOC"; then
echo "Skipping empty or invalid document $i in $file"
if ! /kubeconform \ rm -f "$TMP_DOC"
-schema-location "$SCHEMA_URL" \ continue
-cache "$KUBECONFORM_CACHE_DIR" \
-output json \
"$file"; then
EXIT_CODE=1
fi fi
else KIND=$(yq eval ".kind // \"\"" "$TMP_DOC")
echo "Validating with default schemas" if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then
if ! /kubeconform \ echo "Found $KIND in document $i - using custom schema"
-schema-location default \ SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
-cache "$KUBECONFORM_CACHE_DIR" \ if ! /kubeconform \
-output json \ -schema-location "$SCHEMA_URL" \
"$file"; then -cache "$KUBECONFORM_CACHE_DIR" \
EXIT_CODE=1 -output json \
"$TMP_DOC"; then
EXIT_CODE=1
fi
else
echo "Validating document $i with default schemas"
if ! /kubeconform \
-schema-location default \
-cache "$KUBECONFORM_CACHE_DIR" \
-output json \
"$TMP_DOC"; then
EXIT_CODE=1
fi
fi fi
fi rm -f "$TMP_DOC"
done
echo "" echo ""
done <<< "${ALL_CHANGED_FILES}" done
exit $EXIT_CODE exit $EXIT_CODE

View File

@@ -1,3 +1,4 @@
---
apiVersion: v1 apiVersion: v1
kind: Namespace kind: Namespace
metadata: metadata:

View File

@@ -1,3 +1,4 @@
---
# Server plan # Server plan
apiVersion: upgrade.cattle.io/v1 apiVersion: upgrade.cattle.io/v1
kind: Plan kind: Plan
@@ -16,7 +17,7 @@ spec:
serviceAccountName: system-upgrade serviceAccountName: system-upgrade
upgrade: upgrade:
image: rancher/k3s-upgrade image: rancher/k3s-upgrade
channel: https://update.k3s.io/v1-release/channels/stable channel: https://update.k3s.io/v1-release/channels/v1.33
--- ---
# Agent plan # Agent plan
apiVersion: upgrade.cattle.io/v1 apiVersion: upgrade.cattle.io/v1
@@ -39,4 +40,4 @@ spec:
serviceAccountName: system-upgrade serviceAccountName: system-upgrade
upgrade: upgrade:
image: rancher/k3s-upgrade image: rancher/k3s-upgrade
channel: https://update.k3s.io/v1-release/channels/stable channel: https://update.k3s.io/v1-release/channels/v1.33