@@ -25,14 +25,14 @@ function unexpectedError() {
2525 echo " Unexpected error occured!!"
2626 failed=1
2727
28- (( failed )) && fail_test
28+ (( failed)) && fail_test
2929 success
30- }
30+ }
3131
3232function make_banner() {
33- local msg=" $1$1$1$1 $2 $1$1$1$1 "
34- local border=" ${msg// [-0-9A-Za-z _.,\/()]/ $1 } "
35- echo -e " ${border} \n${msg} \n${border} "
33+ local msg=" $1$1$1$1 $2 $1$1$1$1 "
34+ local border=" ${msg// [-0-9A-Za-z _.,\/()]/ $1 } "
35+ echo -e " ${border} \n${msg} \n${border} "
3636}
3737
3838# Simple header for logging purposes.
@@ -43,22 +43,26 @@ function header() {
4343
4444function wait_until_pods_running() {
4545 echo -n " Waiting until all pods in namespace $1 are up"
46- for i in {1..150}; do # timeout after 5 minutes
46+ for i in {1..150}; do # timeout after 5 minutes
4747 local pods=" $( oc get pods --no-headers -n $1 2> /dev/null) "
48+ # write it to tempfile
49+ TempFile=$( mktemp)
50+ oc get pods --no-headers -n $1 2> /dev/null > $TempFile
51+
4852 # All pods must be running
4953 local not_running=$( echo " ${pods} " | grep -v Running | grep -v Completed | wc -l)
5054 if [[ -n " ${pods} " && ${not_running} -eq 0 ]]; then
5155 local all_ready=1
52- while read pod ; do
53- local status=(` echo -n ${pod} | cut -f2 -d' ' | tr ' /' ' ' ` )
56+ while read pod; do
57+ local status=($( echo ${pod} | cut -f2 -d' ' | tr ' /' ' ' ) )
5458 # All containers must be ready
5559 [[ -z ${status[0]} ]] && all_ready=0 && break
5660 [[ -z ${status[1]} ]] && all_ready=0 && break
5761 [[ ${status[0]} -lt 1 ]] && all_ready=0 && break
5862 [[ ${status[1]} -lt 1 ]] && all_ready=0 && break
5963 [[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
60- done <<< $( echo " ${pods} " | grep -v Completed)
61- if (( all_ready )) ; then
64+ done < ${TempFile}
65+ if (( all_ready)) ; then
6266 echo -e " \nAll pods are up:\n${pods} "
6367 return 0
6468 fi
@@ -79,8 +83,8 @@ function wait_until_object_exist() {
7983 DESCRIPTION=" $1 $3 /$2 "
8084 fi
8185 echo -n " Waiting until ${DESCRIPTION} exist"
82- for i in {1..150}; do # timeout after 5 minutes
83- if oc ${oc_ARGS} > /dev/null 2>&1 ; then
86+ for i in {1..150}; do # timeout after 5 minutes
87+ if oc ${oc_ARGS} > /dev/null 2>&1 ; then
8488 echo -e " \n${DESCRIPTION} exist"
8589 return 0
8690 fi
@@ -101,8 +105,8 @@ function wait_until_object_doesnt_exist() {
101105 DESCRIPTION=" $1 $3 /$2 "
102106 fi
103107 echo -n " Waiting until ${DESCRIPTION} doesn't exist"
104- for i in {1..150}; do # timeout after 5 minutes
105- if ! kubectl ${KUBECTL_ARGS} > /dev/null 2>&1 ; then
108+ for i in {1..150}; do # timeout after 5 minutes
109+ if ! kubectl ${KUBECTL_ARGS} > /dev/null 2>&1 ; then
106110 echo -e " \n${DESCRIPTION} dosen't exist"
107111 return 0
108112 fi
@@ -137,7 +141,6 @@ function dump_extra_cluster_state() {
137141 kubectl -n openshift-gitops-operator logs $( get_app_pod argocd-operator openshift-gitops-operator) --all-containers=true
138142}
139143
140-
141144# Returns the name of the first pod of the given app.
142145# Parameters: $1 - app name.
143146# $2 - namespace (optional).
@@ -161,7 +164,6 @@ function fail_test() {
161164 exit 1
162165}
163166
164-
165167function set_test_return_code() {
166168 echo -n " $1 "
167169}
@@ -176,13 +178,13 @@ function success() {
176178 exit 0
177179}
178180
179- function build_and_push_catalog_image(){
180-
181+ function build_and_push_catalog_image() {
182+
181183 if [ " $E2E_SKIP_BUILD_TOOL_INSTALLATION " = false ]; then
182- echo " >> Install operator-sdk & opm"
183- make operator-sdk opm
184+ echo " >> Install operator-sdk & opm"
185+ make operator-sdk opm
184186 else
185- echo " >> skipping operator-sdk & olm installation"
187+ echo " >> skipping operator-sdk & olm installation"
186188 fi
187189
188190 echo " >> Building and pushing operator images"
@@ -199,15 +201,15 @@ function build_and_push_catalog_image(){
199201
200202}
201203
202- function configure_operator(){
204+ function configure_operator() {
203205 header " Configuring OpenShift Gitops operator"
204206
205207 echo -e " Disabling default catalog sources"
206208 kubectl patch operatorhub.config.openshift.io/cluster -p=' {"spec":{"disableAllDefaultSources":true}}' --type=merge
207209 sleep 5
208210
209211 # echo -e "Copying artifacts [catalog source, image content source policy, mapping.txt]..."
210- cat << EOF > $TMP_DIR /catalog-source.yaml
212+ cat << EOF >$TMP_DIR /catalog-source.yaml
211213apiVersion: operators.coreos.com/v1alpha1
212214kind: CatalogSource
213215metadata:
@@ -222,18 +224,17 @@ spec:
222224 interval: 30m
223225EOF
224226
225-
226227 echo -e " Creating custom catalog source"
227228 kubectl apply -f $TMP_DIR /catalog-source.yaml
228229
229230 echo " Waiting for pods in namespace openshift-marketplace to be ready"
230231 # filtering out old catalog source pod that will be removed shortly
231- pods=$( kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name | \
232- grep gitops-operator | tail -1)
232+ pods=$( kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name |
233+ grep gitops-operator | tail -1)
233234
234235 for pod in ${pods} ; do
235- echo " Waiting for pod $pod in openshift-marketplace to be in ready state"
236- kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
236+ echo " Waiting for pod $pod in openshift-marketplace to be in ready state"
237+ kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
237238 done
238239}
239240
@@ -251,29 +252,29 @@ function uninstall_operator_resources() {
251252 oc wait --for=delete $deployment -n openshift-gitops --timeout=5m || fail_test " Failed to delete deployment: $deployment in openshift-gitops namespace"
252253 done
253254
254- oc delete $( oc get csv -n openshift-gitops-operator -o name| grep gitops) -n openshift-gitops-operator || fail_test " Unable to delete CSV"
255+ oc delete $( oc get csv -n openshift-gitops-operator -o name | grep gitops) -n openshift-gitops-operator || fail_test " Unable to delete CSV"
255256
256257 oc delete -n openshift-gitops-operator installplan $( oc get subscription gitops-operator -n openshift-gitops-operator -o jsonpath=' {.status.installplan.name}' ) || fail_test " Unable to delete installplan"
257258
258259 oc delete subscription gitops-operator -n openshift-gitops-operator --cascade=background || fail_test " Unable to delete subscription"
259260
260261 echo -e " >> Delete arogo resources accross all namespaces"
261262 for res in applications applicationsets appprojects argocds; do
262- oc delete --ignore-not-found=true ${res} .argoproj.io --all
263+ oc delete --ignore-not-found=true ${res} .argoproj.io --all
263264 done
264265
265266 echo -e " >> Cleanup existing crds"
266267 for res in applications applicationsets appprojects argocds; do
267- oc delete --ignore-not-found=true crds ${res} .argoproj.io
268+ oc delete --ignore-not-found=true crds ${res} .argoproj.io
268269 done
269270
270271 echo -e " >> Delete \" openshift-gitops\" project"
271272 oc delete --ignore-not-found=true project openshift-gitops
272273}
273274
274275function install_operator_resources() {
275- echo -e " >>Ensure Gitops subscription exists"
276- oc get subscription gitops-operator -n openshift-gitops-operator 2> /dev/null || \
276+ echo -e " >>Ensure Gitops subscription exists"
277+ oc get subscription gitops-operator -n openshift-gitops-operator 2> /dev/null ||
277278 cat << EOF | oc apply -f -
278279apiVersion: operators.coreos.com/v1alpha1
279280kind: Subscription
@@ -287,24 +288,23 @@ spec:
287288 source: $CATALOG_SOURCE
288289 sourceNamespace: openshift-marketplace
289290EOF
290-
291- wait_until_pods_running " openshift-gitops-operator" || fail_test " openshift gitops Operator controller did not come up"
292291
293- echo " >> Wait for GitopsService creation"
294- wait_until_object_exist " gitopsservices.pipelines.openshift.io" " cluster" " openshift-gitops" || fail_test " gitops service haven't created yet"
292+ wait_until_pods_running " openshift-gitops-operator" || fail_test " openshift gitops Operator controller did not come up"
293+
294+ echo " >> Wait for GitopsService creation"
295+ wait_until_object_exist " gitopsservices.pipelines.openshift.io" " cluster" " openshift-gitops" || fail_test " gitops service haven't created yet"
295296
296- wait_until_pods_running " openshift-gitops" || fail_test " argocd controller did not come up"
297+ wait_until_pods_running " openshift-gitops" || fail_test " argocd controller did not come up"
297298
298-
299- # Make sure that everything is cleaned up in the current namespace.
300- for res in applications applicationsets appprojects appprojects; do
301- oc delete --ignore-not-found=true ${res} .argoproj.io --all
302- done
299+ # Make sure that everything is cleaned up in the current namespace.
300+ for res in applications applicationsets appprojects appprojects; do
301+ oc delete --ignore-not-found=true ${res} .argoproj.io --all
302+ done
303303}
304304
305305function get_operator_namespace() {
306306 # TODO: parameterize namespace, operator can run in a namespace different from the namespace where tektonpipelines is installed
307307 local operator_namespace=" argocd-operator"
308308 [[ " ${TARGET} " == " openshift" ]] && operator_namespace=" openshift-gitops"
309309 echo ${operator_namespace}
310- }
310+ }
0 commit comments