|
5 | 5 | # This script is meant to be run locally and in CI before the changes |
6 | 6 | # are merged on the main branch that's synced by Flux. |
7 | 7 |
|
8 | | -# Copyright 2020 The Flux authors. All rights reserved. |
| 8 | +# Copyright 2022 The Flux authors. All rights reserved. |
9 | 9 | # |
10 | 10 | # Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | # you may not use this file except in compliance with the License. |
|
24 | 24 | # the branch synced by Flux in-cluster. |
25 | 25 |
|
26 | 26 | # Prerequisites |
27 | | -# - yq v4.6 |
28 | | -# - kustomize v4.1 |
29 | | -# - kubeconform v0.4.12 |
30 | | - |
31 | | -type yq >/dev/null 2>&1 || { |
32 | | - echo >&2 "yq is not installed. Please install it to be able to run the script. Aborting." |
33 | | - exit 1 |
34 | | -} |
35 | | -type kustomize >/dev/null 2>&1 || { |
36 | | - echo >&2 "kustomize is not installed. Please install it to be able to run the script. Aborting." |
37 | | - exit 1 |
38 | | -} |
39 | | -type kubeconform >/dev/null 2>&1 || { |
40 | | - echo >&2 " kubeconform is not installed. Please install it to be able to run the script. Aborting." |
41 | | - exit 1 |
42 | | -} |
| 27 | +# - yq v4.30 |
| 28 | +# - kustomize v4.5 |
| 29 | +# - kubeconform v0.5.0 |
43 | 30 |
|
44 | 31 | set -o errexit |
45 | 32 |
|
46 | 33 | echo "INFO - Downloading Flux OpenAPI schemas" |
47 | 34 | mkdir -p /tmp/flux-crd-schemas/master-standalone-strict |
48 | 35 | curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict |
49 | 36 |
|
50 | | -find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; do |
51 | | - echo "INFO - Validating $file" |
52 | | - yq e 'true' "$file" >/dev/null |
| 37 | +find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; |
| 38 | + do |
| 39 | + echo "INFO - Validating $file" |
| 40 | + yq e 'true' "$file" > /dev/null |
53 | 41 | done |
54 | 42 |
|
55 | 43 | kubeconform_config=("-strict" "-ignore-missing-schemas" "-schema-location" "default" "-schema-location" "/tmp/flux-crd-schemas" "-verbose") |
56 | 44 |
|
57 | 45 | echo "INFO - Validating clusters" |
58 | | -find ./clusters -maxdepth 2 -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; do |
59 | | - kubeconform "${kubeconform_config[@]}" "${file}" |
60 | | - if [[ ${PIPESTATUS[0]} != 0 ]]; then |
61 | | - exit 1 |
62 | | - fi |
| 46 | +find ./clusters -maxdepth 2 -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; |
| 47 | + do |
| 48 | + kubeconform "${kubeconform_config[@]}" "${file}" |
| 49 | + if [[ ${PIPESTATUS[0]} != 0 ]]; then |
| 50 | + exit 1 |
| 51 | + fi |
63 | 52 | done |
64 | 53 |
|
65 | 54 | # mirror kustomize-controller build options |
66 | 55 | kustomize_flags=("--load-restrictor=LoadRestrictionsNone") |
67 | 56 | kustomize_config="kustomization.yaml" |
68 | 57 |
|
69 | 58 | echo "INFO - Validating kustomize overlays" |
70 | | -find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file; do |
71 | | - echo "INFO - Validating kustomization ${file/%$kustomize_config/}" |
72 | | - kustomize build "${file/%$kustomize_config/}" "${kustomize_flags[@]}" | |
73 | | - kubeconform "${kubeconform_config[@]}" |
74 | | - if [[ ${PIPESTATUS[0]} != 0 ]]; then |
75 | | - exit 1 |
76 | | - fi |
| 59 | +find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file; |
| 60 | + do |
| 61 | + echo "INFO - Validating kustomization ${file/%$kustomize_config}" |
| 62 | + kustomize build "${file/%$kustomize_config}" "${kustomize_flags[@]}" | \ |
| 63 | + kubeconform "${kubeconform_config[@]}" |
| 64 | + if [[ ${PIPESTATUS[0]} != 0 ]]; then |
| 65 | + exit 1 |
| 66 | + fi |
77 | 67 | done |
0 commit comments