-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubeconform-checks.sh
executable file
·32 lines (25 loc) · 1.18 KB
/
kubeconform-checks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
set -eou pipefail
# Check if required tools are installed
for cmd in kubeconform yq kustomize kubectl jq; do
if ! command -v $cmd &> /dev/null; then
printf "Error: %s could not be found. Please install it first.\n" "$cmd"
exit 1
fi
done
# Get kubernetes minor version via kubectl
KUBERNETES_VERSION=$(kubectl version --client=true -o=json | jq -r '.clientVersion.gitVersion')
FLUX_VERSION=$(flux version --client | awk '{print $2}')
# Configuration
kubeconform_flags=("-skip=Secret")
kubeconform_config=("-strict" "-ignore-missing-schemas" "-schema-location" "default" "-schema-location" "/tmp/flux-schemas" "-schema-location" "/tmp/kubernetes-schemas" "-verbose" "-output" "pretty" "-exit-on-error")
function get_targets {
find kustomize -maxdepth 2 -name kustomization.yaml -exec dirname {} \; | sort
}
# Loop through each environment
for env in $(get_targets); do
printf "\n\nValidating kustomization in %s against Flux %s schemas and Kubernetes %s schemas\n" "${env#*/}" "${FLUX_VERSION}" "${KUBERNETES_VERSION}"
kustomize build "${env}" | kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}"
done
printf "\nValidation complete!\n"
exit 0