Skip to content

Commit 607ba83

Browse files
committed
Fix invalid yq option causing hive development config generation failure
It seems that -y is no longer accepted by yq. Cleaned up scripts by moving some functions into hack/util.sh Fixed sourcing path Remove unnecessary variable name references * A name ref for the image variable caused an interesting problem when running yq as a container. yq image assignment was attempting to overwrite hive_image. Passing the variable as a value mitigated this.
1 parent 1e6e79b commit 607ba83

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

hack/hive/hive-generate-config.sh

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ main() {
2525
kustomize_bin
2626
hive_repo_clone tmpdir
2727
hive_repo_hash_checkout tmpdir \
28-
hive_image_commit_hash
28+
"$hive_image_commit_hash"
2929
generate_hive_config kustomize_bin \
30-
hive_operator_namespace \
31-
hive_image \
30+
"$hive_operator_namespace" \
31+
"$hive_image" \
3232
tmpdir
3333

3434
log "Hive config generated."
@@ -81,7 +81,7 @@ hive_repo_clone() {
8181

8282
hive_repo_hash_checkout() {
8383
local -n tmpd="$1"
84-
local -n commit="$2"
84+
local commit="$2"
8585
log "starting"
8686
log "Attempting to use commit: $commit"
8787

@@ -94,10 +94,11 @@ hive_repo_hash_checkout() {
9494
popd 1> /dev/null
9595
}
9696

97+
# generate_hive_config()
9798
generate_hive_config() {
9899
local -n kustomize="$1"
99-
local -n namespace="$2"
100-
local -n image="$3"
100+
local namespace="$2"
101+
local image="$3"
101102
local -n tmpd="$4"
102103
log "starting"
103104

@@ -117,28 +118,17 @@ generate_hive_config() {
117118
mv "$tmpd/hive-deployment.yaml" ./hack/hive/hive-config/
118119

119120
# ensure the hive deployment uses the pull secret
120-
yq -yi 'select(.kind == "ServiceAccount").imagePullSecrets = [{"name": "hive-global-pull-secret"}]' ./hack/hive/hive-config/hive-deployment.yaml
121+
yq -i 'select(.kind == "ServiceAccount").imagePullSecrets = [{"name": "hive-global-pull-secret"}]' ./hack/hive/hive-config/hive-deployment.yaml
121122

122123
if [ -d ./hack/hive/hive-config/crds ]; then
123124
rm -rf ./hack/hive/hive-config/crds
124125
fi
125126
cp -R "$tmpd/config/crds" ./hack/hive/hive-config/
126127
}
127128

128-
if [ ! -f go.mod ] || [ ! -d ".git" ]; then
129-
echo "this script must by run from the repo's root directory"
130-
exit 1
131-
fi
132-
133-
declare -r util_script="hack/util.sh"
134-
if [ -f $util_script ]; then
135-
# shellcheck source=util.sh
136-
source "$util_script"
137-
fi
138-
139-
cleanup() {
140-
local tmpd="$1"
141-
[ -d "$tmpd" ] && rm -fr "$tmpd"
142-
}
129+
declare -r util_lib="hack/util.sh"
130+
[ -f "$util_lib" ] || "$(echo "$util_lib not found. Are you in the ARO-RP repository root?"; exit 1)"
131+
# shellcheck source=../util.sh
132+
. "$util_lib"
143133

144134
main "$@"

hack/util.sh

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1-
#!/bin/bash
1+
# shellcheck shell=bash
22

3-
if [ "${DEBUG:-false}" == true ]; then
4-
set -x
5-
fi
3+
# declare -r __hack_util_sourced="true"
4+
declare -r __hack_util_sourced="true"
65

6+
[ "${DEBUG:-false}" == true ] && set -x
7+
8+
# log()
79
# log is a wrapper for echo that includes the function name
8-
# Args
9-
# 1) msg - string
10-
# 2) stack_level - int; optional, defaults to calling function
10+
#
11+
# args:
12+
# * 1) msg - string
13+
# * 2) stack_level - int; optional, defaults to calling function
1114
log() {
1215
local -r msg="${1:-"log message is empty"}"
1316
local -r stack_level="${2:-1}"
17+
1418
echo "${FUNCNAME[${stack_level}]}: ${msg}"
1519
}
1620

17-
# abort is a wrapper for log that exits with an error code
21+
# abort is a wrapper for log followed by exit code 1
22+
#
23+
# args:
24+
# * 1) message - string; error message passed to log
1825
abort() {
1926
local -ri origin_stacklevel=2
27+
2028
log "${1}" "$origin_stacklevel"
2129
log "Exiting"
2230
exit 1
23-
}
31+
}
32+
33+
# cleanup() {
34+
# Deletes all files and directories provided.
35+
#
36+
# args:
37+
# * @) tmp - array; files and/or directories to be deleted
38+
cleanup() {
39+
# shellcheck disable=SC2068
40+
for tmp in $@; do
41+
if [[ -d "$tmp" || -f "$tmp" ]]; then
42+
log "Deleting $tmp"
43+
rm -fr "$tmp"
44+
fi
45+
done
46+
}

0 commit comments

Comments
 (0)