3
3
[ " $CI " != " " ] && set -e
4
4
set -uo pipefail
5
5
6
- schemaOutputPath=" /tmp/otomi/kubernetes-json-schema/master "
6
+ schemaOutputPath=" /tmp/otomi/kubernetes-json-schema"
7
7
outputPath=" /tmp/otomi/generated-crd-schemas"
8
8
schemasBundleFile=" $outputPath /all.json"
9
9
k8sResourcesPath=" /tmp/otomi/kubeval-fixtures"
10
10
extractCrdSchemaJQFile=$( mktemp -u)
11
- exitcode=1
11
+ exitcode=0
12
12
13
13
. bin/common.sh
14
14
15
+ readonly k8s_version=" v$( get_k8s_version) "
16
+
15
17
cleanup () {
16
18
[ $exitcode -eq 0 ] && echo " Validation Success" || echo " Validation Failed"
17
19
rm -rf $extractCrdSchemaJQFile
18
- rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
20
+ rm -rf $k8sResourcesPath -rf $outputPath $schemaOutputPath
19
21
exit $exitcode
20
22
}
21
23
trap cleanup EXIT ERR
22
24
23
25
run_setup () {
24
- exitcode=1
25
- local version=" v$( get_k8s_version) .0"
26
26
rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
27
27
mkdir -p $k8sResourcesPath $outputPath $schemaOutputPath
28
28
echo " " > $schemasBundleFile
29
29
# use standalone schemas
30
- tar -xzf " schemas/${version} -standalone.tar.gz" -C $schemaOutputPath
31
- tar -xzf " schemas/generated-crd-schemas.tar.gz" -C " $schemaOutputPath /$version -standalone"
30
+ tar -xzf " schemas/$k8s_version -standalone.tar.gz" -C " $schemaOutputPath / "
31
+ tar -xzf " schemas/generated-crd-schemas.tar.gz" -C " $schemaOutputPath /$k8s_version -standalone"
32
32
33
33
# loop over .spec.versions[] and generate one file for each version
34
34
cat << 'EOF ' >$extractCrdSchemaJQFile
@@ -66,11 +66,10 @@ process_crd() {
66
66
}
67
67
68
68
validate_templates () {
69
- local version=" v$( get_k8s_version) .0"
70
69
71
70
run_setup
72
71
# generate_manifests
73
- echo " Generating Kubernetes ${version} Manifests for ${CLOUD} -${CLUSTER} ."
72
+ echo " Generating Kubernetes $k8s_version Manifests for ${CLOUD} -${CLUSTER} ."
74
73
75
74
hf -f helmfile.tpl/helmfile-init.yaml template --skip-deps --output-dir=" $k8sResourcesPath " > /dev/null
76
75
hf template --skip-deps --output-dir=" $k8sResourcesPath " > /dev/null
@@ -88,19 +87,22 @@ validate_templates() {
88
87
done
89
88
# create schema in canonical format for each extracted file
90
89
for json in $( jq -s -r ' .[] | .filename' $schemasBundleFile ) ; do
91
- jq " select(.filename==\" $json \" )" $schemasBundleFile | jq ' .schema' > " $schemaOutputPath /$version -standalone/$json "
90
+ jq " select(.filename==\" $json \" )" $schemasBundleFile | jq ' .schema' > " $schemaOutputPath /$k8s_version -standalone/$json "
92
91
done
93
92
94
93
# validate_resources
95
- echo " Validating resources against Kubernetes version: $version "
94
+ echo " Validating resources against Kubernetes version: $k8s_version "
96
95
local kubevalSchemaLocation=" file://${schemaOutputPath} "
97
96
local skipKinds=" CustomResourceDefinition"
98
97
local skipFilenames=" crd,knative-services"
99
- {
100
- set +o pipefail
101
- kubeval --quiet --skip-kinds $skipKinds --ignored-filename-patterns $skipFilenames --force-color -d $k8sResourcesPath --schema-location $kubevalSchemaLocation --kubernetes-version $( echo $version | sed ' s/v//' ) | grep -Ev ' PASS\b'
102
- set -o pipefail
103
- } && exitcode=0
98
+ local tmp_out=$( mktemp -u)
99
+ set +o pipefail
100
+ kubeval --quiet --skip-kinds $skipKinds --ignored-filename-patterns $skipFilenames \
101
+ --force-color -d $k8sResourcesPath --schema-location $kubevalSchemaLocation \
102
+ --kubernetes-version $( echo $k8s_version | sed ' s/v//' ) | tee $tmp_out | grep -Ev ' PASS\b'
103
+ set -o pipefail
104
+ grep -q " ERROR" $tmp_out && exitcode=1
105
+ rm $tmp_out
104
106
}
105
107
106
108
if [ " ${1-} " != " " ]; then
0 commit comments