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
TMP_DOC="/tmp/doc_${i}_$$.yaml"
yq eval-all ".[$i]" "$file" > "$TMP_DOC"
if [[ ! -s "$TMP_DOC" ]] || grep -q '^\s*$' "$TMP_DOC"; then
echo "Skipping empty or invalid document $i in $file"
rm -f "$TMP_DOC"
continue
fi
KIND=$(yq eval ".kind // \"\"" "$TMP_DOC")
if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then
echo "Found $KIND - using custom schema" echo "Found $KIND in document $i - using custom schema"
SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}" SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
if ! /kubeconform \ if ! /kubeconform \
-schema-location "$SCHEMA_URL" \ -schema-location "$SCHEMA_URL" \
-cache "$KUBECONFORM_CACHE_DIR" \ -cache "$KUBECONFORM_CACHE_DIR" \
-output json \ -output json \
"$file"; then "$TMP_DOC"; then
EXIT_CODE=1 EXIT_CODE=1
fi fi
else else
echo "Validating with default schemas" echo "Validating document $i with default schemas"
if ! /kubeconform \ if ! /kubeconform \
-schema-location default \ -schema-location default \
-cache "$KUBECONFORM_CACHE_DIR" \ -cache "$KUBECONFORM_CACHE_DIR" \
-output json \ -output json \
"$file"; then "$TMP_DOC"; then
EXIT_CODE=1 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