Last active
May 27, 2021 07:02
-
-
Save Becram/0d245d51d32ee9c00e878d31af56ebb9 to your computer and use it in GitHub Desktop.
Validate kustomization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -o errexit | |
echo "INFO - Downloading Flux OpenAPI schemas" | |
mkdir -p /tmp/flux-crd-schemas/master-standalone-strict | |
curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict | |
# mirror kustomize-controller build options | |
kustomize_flags="--load-restrictor=LoadRestrictionsNone" | |
kustomize_config="kustomization.yaml" | |
find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; | |
do | |
echo "INFO - Validating $file" | |
yq e 'true' "$file" > /dev/null | |
done | |
echo "INFO - Validating clusters" | |
find ./clusters -type f -name '*.yaml' -maxdepth 1 -print0 | while IFS= read -r -d $'\0' file; | |
do | |
kubeval ${file} --strict --ignore-missing-schemas --additional-schema-locations=file:///tmp/flux-crd-schemas | |
if [[ ${PIPESTATUS[0]} != 0 ]]; then | |
exit 1 | |
fi | |
done | |
echo "INFO - Validating kustomize overlays" | |
find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file; | |
do | |
echo "INFO - Validating kustomization ${file/%$kustomize_config}" | |
kustomize build "${file/%$kustomize_config}" $kustomize_flags | kubeval --ignore-missing-schemas --strict --additional-schema-locations=file:///tmp/flux-crd-schemas | |
if [[ ${PIPESTATUS[0]} != 0 ]]; then | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment