55# This script is meant to be run locally and in CI before the changes
66# are merged on the main branch that's synced by Flux.
77
8- # Copyright 2022 The Flux authors. All rights reserved.
8+ # Copyright 2023 The Flux authors. All rights reserved.
99#
1010# Licensed under the Apache License, Version 2.0 (the "License");
1111# you may not use this file except in compliance with the License.
1919# See the License for the specific language governing permissions and
2020# limitations under the License.
2121
22- # This script is meant to be run locally and in CI to validate the Kubernetes
23- # manifests (including Flux custom resources) before changes are merged into
24- # the branch synced by Flux in-cluster.
25-
2622# Prerequisites
27- # - yq v4.30
28- # - kustomize v4.5
29- # - kubeconform v0.5.0
23+ # - yq v4.34
24+ # - kustomize v5.0
25+ # - kubeconform v0.6
3026
3127set -o errexit
28+ set -o pipefail
29+
30+ # mirror kustomize-controller build options
31+ kustomize_flags=(" --load-restrictor=LoadRestrictionsNone" )
32+ kustomize_config=" kustomization.yaml"
33+
34+ # skip Kubernetes Secrets due to SOPS fields failing validation
35+ kubeconform_flags=(" -skip=Secret" )
36+ kubeconform_config=(" -strict" " -ignore-missing-schemas" " -schema-location" " default" " -schema-location" " /tmp/flux-crd-schemas" " -verbose" )
3237
3338echo " INFO - Downloading Flux OpenAPI schemas"
3439mkdir -p /tmp/flux-crd-schemas/master-standalone-strict
@@ -40,28 +45,22 @@ find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file;
4045 yq e ' true' " $file " > /dev/null
4146done
4247
43- kubeconform_config=(" -strict" " -ignore-missing-schemas" " -schema-location" " default" " -schema-location" " /tmp/flux-crd-schemas" " -verbose" )
44-
4548echo " INFO - Validating clusters"
4649find ./clusters -maxdepth 2 -type f -name ' *.yaml' -print0 | while IFS= read -r -d $' \0' file;
4750 do
48- kubeconform " ${kubeconform_config[@]} " " ${file} "
51+ kubeconform " ${kubeconform_flags[@]} " " ${ kubeconform_config[@]}" " ${file} "
4952 if [[ ${PIPESTATUS[0]} != 0 ]]; then
5053 exit 1
5154 fi
5255done
5356
54- # mirror kustomize-controller build options
55- kustomize_flags=(" --load-restrictor=LoadRestrictionsNone" )
56- kustomize_config=" kustomization.yaml"
57-
5857echo " INFO - Validating kustomize overlays"
5958find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $' \0' file;
6059 do
6160 echo " INFO - Validating kustomization ${file/% $kustomize_config } "
6261 kustomize build " ${file/% $kustomize_config } " " ${kustomize_flags[@]} " | \
63- kubeconform " ${kubeconform_config[@]} "
62+ kubeconform " ${kubeconform_flags[@]} " " ${ kubeconform_config[@]}"
6463 if [[ ${PIPESTATUS[0]} != 0 ]]; then
6564 exit 1
6665 fi
67- done
66+ done
0 commit comments