1414# https://github.com/red-hat-data-services/rhods-operator/blob/7ccc405135f99c014982d7e297b8949e970dd750/go.mod#L28-L29
1515# and then to match appropriate kustomize release https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv5.0.3
1616DEFAULT_KUSTOMIZE_VERSION=5.0.3
17+ # The latest kustomize version we want to check with to be sure we're prepared for the future
18+ THE_LATEST_KUSTOMIZE=5.6.0
1719
1820KUSTOMIZE_VERSION=" ${KUSTOMIZE_VERSION:- $DEFAULT_KUSTOMIZE_VERSION } "
1921
@@ -27,7 +29,30 @@ function download_kustomize() {
2729 echo " ---------------------------------------------------------------------------------"
2830 echo " Download kustomize '${kustomize_version} '"
2931 echo " ---------------------------------------------------------------------------------"
30- wget --output-document=" ${kustomize_tar} " " https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${kustomize_version} /kustomize_v${kustomize_version} _linux_amd64.tar.gz"
32+
33+ # Detect OS
34+ local uname_out
35+ uname_out=" $( uname -s) "
36+ case " ${uname_out} " in
37+ Linux* ) os=linux;;
38+ Darwin* ) os=darwin;;
39+ * ) echo " Unsupported OS: ${uname_out} " && return 1;;
40+ esac
41+
42+ # Detect architecture
43+ local arch
44+ arch=" $( uname -m) "
45+ case " ${arch} " in
46+ x86_64) arch=amd64;;
47+ arm64) arch=arm64;;
48+ aarch64) arch=arm64;;
49+ * ) echo " Unsupported architecture: ${arch} " && return 1;;
50+ esac
51+
52+ local download_url=" https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${kustomize_version} /kustomize_v${kustomize_version} _${os} _${arch} .tar.gz"
53+ echo " Downloading from: ${download_url} "
54+
55+ wget --output-document=" ${kustomize_tar} " " ${download_url} "
3156 tar -C " ${tmp_dir} " -xvf " ${kustomize_tar} "
3257 mv " ${tmp_dir} /kustomize" " ${kustomize_bin} "
3358
@@ -46,22 +71,72 @@ function execute_kustomize() {
4671 echo " Starting to run kustomize '${kustomize_version} ' for each kustomization.yaml file except components"
4772 echo " ---------------------------------------------------------------------------------------------------"
4873 # We don't want to execute kustomization on the components part as it's not intended to be used that way.
49- find . -name " kustomization.yaml" | xargs dirname | grep -v " components" | xargs -t -I {} " ${kustomize_bin} " build {} > " ${kustomize_stdout} " 2> " ${kustomize_stderr} "
74+ # This first run is for the actual execution to get the generated output and eventual errors/warnings.
75+ find . -name " kustomization.yaml" | xargs dirname | grep -v " components" | xargs -I {} " ${kustomize_bin} " build {} > " ${kustomize_stdout} " 2> " ${kustomize_stderr} "
76+ # This second run is with verbose output to see eventual errors/warnings together with which command they are present for easier debugging.
77+ find . -name " kustomization.yaml" | xargs dirname | grep -v " components" | xargs --verbose -I {} " ${kustomize_bin} " build {} > /dev/null
5078
5179 echo " Let's print the STDERR:"
5280 cat " ${kustomize_stderr} "
5381}
5482
83+ function check_the_results() {
84+ local tmp_dir=" ${1} "
85+ local kustomize_version_1=" ${2} "
86+ local kustomize_version_2=" ${3} "
87+
88+ local kustomize_stdout_1=" ${tmp_dir} /kustomize-${kustomize_version_1} -stdout.yaml"
89+ local kustomize_stderr_1=" ${tmp_dir} /kustomize-${kustomize_version_1} -stderr.txt"
90+ local kustomize_stdout_2=" ${tmp_dir} /kustomize-${kustomize_version_2} -stdout.yaml"
91+ local kustomize_stderr_2=" ${tmp_dir} /kustomize-${kustomize_version_2} -stderr.txt"
92+
93+ echo " ---------------------------------------------------------------------------------"
94+ echo " Checking the generated outputs - should be identical:"
95+ echo " - ${kustomize_stdout_1} "
96+ echo " - ${kustomize_stdout_2} "
97+ echo " ---------------------------------------------------------------------------------"
98+ diff -u " ${kustomize_stdout_1} " " ${kustomize_stdout_2} " || {
99+ echo " Generated files from kustomize differs between kustomize version ${kustomize_version_1} and ${kustomize_version_2} . Please check above!"
100+ return 1
101+ }
102+
103+ echo " ---------------------------------------------------------------------------------"
104+ echo " No log in STDERR outputs should be printed:"
105+ echo " - ${kustomize_stderr_1} "
106+ echo " - ${kustomize_stderr_2} "
107+ echo " ---------------------------------------------------------------------------------"
108+ if [ -s " ${kustomize_stderr_1} " ] || [ -s " ${kustomize_stderr_2} " ]; then
109+ echo " There were some logs generated to STDERR during the kustomize build. Please check the log above!"
110+ return 1
111+ fi
112+ }
113+
114+ function run_check() {
115+ local tmp_dir=" ${1} "
116+ local kustomize_version=" ${2} "
117+
118+ download_kustomize " ${tmp_dir} " " ${kustomize_version} " || return 1
119+ execute_kustomize " ${tmp_dir} " " ${kustomize_version} " || return 1
120+ }
121+
55122function main() {
123+ local ret_code=0
124+
56125 local tmp_dir
57126 tmp_dir=$( mktemp --directory -t kustomize-XXXXXXXXXX)
58127 echo " Running in the following temporary directory: '${tmp_dir} '"
59128
60- download_kustomize " ${tmp_dir} " " ${KUSTOMIZE_VERSION} " || return 1
61- execute_kustomize " ${tmp_dir} " " ${KUSTOMIZE_VERSION} " || return 1
129+ run_check " ${tmp_dir} " " ${KUSTOMIZE_VERSION} " || return 1
130+ run_check " ${tmp_dir} " " ${THE_LATEST_KUSTOMIZE} " || return 1
131+
132+ # --------------------------------------------------------------------------------------
133+
134+ check_the_results " ${tmp_dir} " " ${KUSTOMIZE_VERSION} " " ${THE_LATEST_KUSTOMIZE} " || return 1
135+
136+ exit " ${ret_code} "
62137}
63138
64139# allows sourcing the script into interactive session without executing it
65140if [[ " ${0} " == " ${BASH_SOURCE[0]} " ]]; then
66- main $@
141+ main " $@ "
67142fi
0 commit comments