@@ -4,62 +4,61 @@ set -o errexit \
44 -o nounset
55
66main () {
7+ local -r hive_commit_override=" ${1:- } "
8+
9+ # This is the commit sha that the image was built from and ensures we use the correct configs for the release
10+ # Ensure it is the latest when testing pre production deployments
11+ local -r default_commit=" f48f47857f6a1dda25ad46957927ee6fe3afe1eb"
12+ if [ -z " $hive_commit_override " ]; then
13+ warn " Using default hive commit hash: $default_commit "
14+ warn " Hive commit hashes can be found here: https://quay.io/repository/redhat-user-workloads/crt-redhat-acm-tenant/hive-operator/hive?tab=tags"
15+ fi
16+ local -r hive_image_commit_hash=" ${hive_commit_override:- $default_commit } "
17+
18+ info " Using hive commit: $hive_image_commit_hash "
19+ # shellcheck disable=SC2034
20+
721 local -r tmpdir=" $( mktemp -d) "
822 # shellcheck disable=SC2064
923 trap " cleanup $tmpdir " EXIT
1024
11- # This is the commit sha that the image was built from and ensures we use the correct configs for the release
12- local -r default_commit=" 8796c4f534"
13- local -r hive_image_commit_hash=" ${1:- $default_commit } "
14- log " Using hive commit: $hive_image_commit_hash "
1525 # shellcheck disable=SC2034
16- local -r hive_operator_namespace=" hive"
26+ kustomize_bin=" $( which kustomize 2> /dev/null) " \
27+ || install_kustomize " $tmpdir " kustomize_bin
1728
18- # shellcheck disable=SC2034
19- local -r hive_image=" arointsvc.azurecr.io/redhat-services-prod/crt-redhat-acm-tenant/hive-operator/hive:${hive_image_commit_hash} "
29+ hive_repo_clone " $tmpdir "
2030
31+ hive_repo_hash_checkout " $tmpdir " " $hive_image_commit_hash "
2132
22- # shellcheck disable=SC2034
23- local kustomize_bin
24- install_kustomize tmpdir \
25- kustomize_bin
26- hive_repo_clone tmpdir
27- hive_repo_hash_checkout tmpdir \
28- " $hive_image_commit_hash "
33+ local -r hive_image=" arointsvc.azurecr.io/redhat-services-prod/crt-redhat-acm-tenant/hive-operator/hive:${hive_image_commit_hash} "
2934 generate_hive_config kustomize_bin \
30- " $hive_operator_namespace " \
35+ " $HIVE_OPERATOR_NS " \
3136 " $hive_image " \
32- tmpdir
37+ " $ tmpdir"
3338
34- log " Hive config generated."
39+ info " Hive config generated."
3540}
3641
3742install_kustomize () {
38- local -n tmpd=" $1 "
43+ local tmpd=" $1 "
3944 local -n kustomize=" $2 "
40- log " starting"
41-
42- if kustomize=" $( which kustomize 2> /dev/null) " ; then
43- return 0
44- fi
45+ info " starting"
4546
4647 pushd " $tmpd " 1> /dev/null
4748
4849 # This version is specified in the hive repo and is the only hard dependency for this script
4950 # https://github.com/openshift/hive/blob/master/vendor/github.com/openshift/build-machinery-go/make/targets/openshift/kustomize.mk#L7
5051 local -r kustomize_version=" 4.1.3"
51- log " kustomize not detected, downloading..."
52+ info " kustomize not detected, downloading..."
5253 if ! curl -s " https://raw.githubusercontent.com/kubernetes-sigs/kustomize/kustomize/v${kustomize_version} /hack/install_kustomize.sh" | bash -s " $kustomize_version " " $tmpd " 1> /dev/null; then
53- abort " error downloading kustomize"
54+ fatal " error downloading kustomize"
5455 fi
5556
56- if [ ! -d " ${HOME} /bin" ]; then
57- mkdir -p " ${HOME} /bin"
58- fi
57+ [ -d " ${HOME} /bin" ] || mkdir -p " ${HOME} /bin"
5958
6059 kustomize_new=" ${tmpd} /kustomize"
6160 kustomize_dest=" ${HOME} /bin/kustomize"
62- log " Installing $kustomize_new into $kustomize_dest "
61+ info " Installing $kustomize_new into $kustomize_dest "
6362 mv " $kustomize_new " " $kustomize_dest "
6463
6564 popd 1> /dev/null
@@ -68,27 +67,26 @@ install_kustomize() {
6867}
6968
7069hive_repo_clone () {
71- local -n tmpd=" $1 "
72- log " starting"
70+ local tmpd=" $1 "
71+ info " starting"
7372
7473 local -r repo=" https://github.com/openshift/hive.git"
75- log " Cloning $repo into $tmpd for config generation "
74+ info " Cloning $repo into $tmpd "
7675 if ! git clone " $repo " " $tmpd " ; then
77- log " error cloning the hive repo"
78- return 1
76+ fatal " error cloning the hive repo"
7977 fi
8078}
8179
8280hive_repo_hash_checkout () {
83- local -n tmpd=" $1 "
81+ local tmpd=" $1 "
8482 local commit=" $2 "
85- log " starting"
86- log " Attempting to use commit: $commit "
83+ info " starting"
84+ info " Attempting to use commit: $commit "
8785
8886 pushd " $tmpd " 1> /dev/null
89- git reset --hard " $commit "
90- if [ " $? " -ne 0 ] || [ " $( git rev-parse --short=" ${# commit} " HEAD ) " != " $commit " ]; then
91- abort " error resetting the hive repo to the correct git hash '${commit} '"
87+
88+ if git reset --hard " $commit " && [ " $( git rev-parse --short=" ${# commit} " HEAD ) " != " $commit " ]; then
89+ fatal " error resetting the hive repo to the correct git hash '${commit} '"
9290 fi
9391
9492 popd 1> /dev/null
@@ -99,36 +97,51 @@ generate_hive_config() {
9997 local -n kustomize=" $1 "
10098 local namespace=" $2 "
10199 local image=" $3 "
102- local -n tmpd=" $4 "
103- log " starting"
100+ local tmpd=" $4 "
101+ info " starting"
104102
105103 pushd " $tmpd " 1> /dev/null
106- # Create the hive operator install config using kustomize
107104 mkdir -p overlays/deploy
105+
106+ debug " copying template kustomization.yaml"
108107 cp overlays/template/kustomization.yaml overlays/deploy
109- pushd overlays/deploy >& /dev/null
108+ pushd overlays/deploy 1> /dev/null
109+ debug " Setting hive image."
110110 $kustomize edit set image registry.ci.openshift.org/openshift/hive-v4.0:hive=" $image "
111111 $kustomize edit set namespace " $namespace "
112- popd >& /dev/null
112+ popd 1> /dev/null
113113
114+ info " Building hive deployment"
114115 $kustomize build overlays/deploy > hive-deployment.yaml
115116
116- # return to the repo directory to copy the generated config from $TMPDIR
117117 popd 1> /dev/null
118- mv " $tmpd /hive-deployment.yaml" ./hack/hive/hive-config/
118+ mv " $tmpd /hive-deployment.yaml" " $HIVE_CONFIG "
119119
120- # ensure the hive deployment uses the pull secret
121- yq -i ' select(.kind == "ServiceAccount").imagePullSecrets = [{"name": "hive-global-pull-secret"}]' ./hack/ hive/hive-config/hive- deployment.yaml
120+ debug " Verifying hive deployment pull secret exists in deployment. "
121+ yq -i ' select(.kind == "ServiceAccount").imagePullSecrets = [{"name": "hive-global-pull-secret"}]' " $HIVE_CONFIG / hive- deployment.yaml"
122122
123- if [ -d ./hack/hive/hive-config/crds ]; then
124- rm -rf ./hack/hive/hive-config/crds
123+ crds_old=" $HIVE_CONFIG /crds"
124+ if [ -d " $crds_old " ]; then
125+ info " Deleting $crds_old "
126+ rm -rf " $HIVE_CONFIG /crds"
125127 fi
126- cp -R " $tmpd /config/crds" ./hack/hive/hive-config/
128+
129+ crds_new=" $tmpd /config/crds"
130+ info " Copying $crds_new into $HIVE_CONFIG "
131+ cp -R " $crds_new " " $HIVE_CONFIG /"
127132}
128133
134+ # declare -r source_file_not_found_err="not found. Are you in the ARO-RP repository root?"
135+ declare -r source_file_not_found_err=" not found. Are you in the ARO-RP repository root?"
136+
129137declare -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) "
138+ [ -f " $util_lib " ] || " $( echo " $util_lib $source_file_not_found_err " ; exit 1) "
131139# shellcheck source=../util.sh
132- . " $util_lib "
140+ [ " ${__hack_util_sourced:- ' false' } " == " false" ] || . " $util_lib "
141+
142+ declare -r hive_env=" hack/hive/hive.env"
143+ [ -f " $hive_env " ] || fatal " $hive_env $source_file_not_found_err "
144+ # shellcheck source=./hive.env
145+ [ " ${__hive_env_sourced:- ' false' } " == " false" ] || . " $hive_env "
133146
134147main " $@ "
0 commit comments