|
| 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