Skip to content

Commit 74402f0

Browse files
Merge pull request #995 from jstourac/kustomize2
[GHA] Enhance the checks for the kustomization.yaml files
2 parents 4c32c9c + fca93da commit 74402f0

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

.github/workflows/code-quality.yaml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,7 @@ jobs:
125125
echo "Hadolint done"
126126
127127
# This simply checks that the manifests and respective kustomization.yaml finishes without an error.
128-
# Version of the kustomize that operator use in runtime to apply these changes is determined by:
129-
# https://github.com/red-hat-data-services/rhods-operator/blob/7ccc405135f99c014982d7e297b8949e970dd750/go.mod#L28-L29
130-
# and then to match appropriate kustomize release https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv5.0.2
131128
- name: Check kustomize manifest
132129
id: kustomize-manifests
133130
run: |
134-
KUSTOMIZE_VERSION=5.0.2
135-
wget "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz"
136-
tar -xvf kustomize*
137-
138-
./kustomize version
139-
echo "----------------------------------------------------------"
140-
echo "Starting './kustomize build manifests/base'"
141-
echo "----------------------------------------------------------"
142-
./kustomize build manifests/base
143-
144-
echo "----------------------------------------------------------"
145-
echo "Starting './kustomize build manifests/overlays/additional'"
146-
echo "----------------------------------------------------------"
147-
./kustomize build manifests/overlays/additional
131+
./ci/kustomize.sh

ci/kustomize.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# This script serves to validate our kustomize files/manifests with respect of the given kustomize version.
4+
# We use this to verify that there is no warning and not errors
5+
#
6+
# Local execution: [KUSTOMIZE_VERSION=5.3.1] ./ci/kustomize.sh
7+
# Note: please execute from the root directory so that whole dir tree is checked
8+
#
9+
# In case of the PR on GitHub, this check is tied to GitHub actions automatically,
10+
# see `.github/workflows` directory.
11+
12+
13+
# The default kustomize version that is determined based on what is currently used in the [rhods|opendatahub]-operator in runtime:
14+
# https://github.com/red-hat-data-services/rhods-operator/blob/7ccc405135f99c014982d7e297b8949e970dd750/go.mod#L28-L29
15+
# and then to match appropriate kustomize release https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv5.0.3
16+
DEFAULT_KUSTOMIZE_VERSION=5.0.3
17+
18+
KUSTOMIZE_VERSION="${KUSTOMIZE_VERSION:-$DEFAULT_KUSTOMIZE_VERSION}"
19+
20+
function download_kustomize() {
21+
local tmp_dir="${1}"
22+
local kustomize_version="${2}"
23+
24+
local kustomize_tar="${tmp_dir}/kustomize-${kustomize_version}.tar.gz"
25+
local kustomize_bin="${tmp_dir}/kustomize-${kustomize_version}"
26+
27+
echo "---------------------------------------------------------------------------------"
28+
echo "Download kustomize '${kustomize_version}'"
29+
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"
31+
tar -C "${tmp_dir}" -xvf "${kustomize_tar}"
32+
mv "${tmp_dir}/kustomize" "${kustomize_bin}"
33+
34+
"${kustomize_bin}" version
35+
}
36+
37+
function execute_kustomize() {
38+
local tmp_dir="${1}"
39+
local kustomize_version="${2}"
40+
41+
local kustomize_stdout="${tmp_dir}/kustomize-${kustomize_version}-stdout.yaml"
42+
local kustomize_stderr="${tmp_dir}/kustomize-${kustomize_version}-stderr.txt"
43+
local kustomize_bin="${tmp_dir}/kustomize-${kustomize_version}"
44+
45+
echo "---------------------------------------------------------------------------------------------------"
46+
echo "Starting to run kustomize '${kustomize_version}' for each kustomization.yaml file except components"
47+
echo "---------------------------------------------------------------------------------------------------"
48+
# 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}"
50+
51+
echo "Let's print the STDERR:"
52+
cat "${kustomize_stderr}"
53+
}
54+
55+
function main() {
56+
local tmp_dir
57+
tmp_dir=$(mktemp --directory -t kustomize-XXXXXXXXXX)
58+
echo "Running in the following temporary directory: '${tmp_dir}'"
59+
60+
download_kustomize "${tmp_dir}" "${KUSTOMIZE_VERSION}" || return 1
61+
execute_kustomize "${tmp_dir}" "${KUSTOMIZE_VERSION}" || return 1
62+
}
63+
64+
# allows sourcing the script into interactive session without executing it
65+
if [[ "${0}" == "${BASH_SOURCE[0]}" ]]; then
66+
main $@
67+
fi

0 commit comments

Comments
 (0)