@@ -25,14 +25,14 @@ function unexpectedError() {
25
25
echo " Unexpected error occured!!"
26
26
failed=1
27
27
28
- (( failed )) && fail_test
28
+ (( failed)) && fail_test
29
29
success
30
- }
30
+ }
31
31
32
32
function 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} "
36
36
}
37
37
38
38
# Simple header for logging purposes.
@@ -43,22 +43,26 @@ function header() {
43
43
44
44
function wait_until_pods_running() {
45
45
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
47
47
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
+
48
52
# All pods must be running
49
53
local not_running=$( echo " ${pods} " | grep -v Running | grep -v Completed | wc -l)
50
54
if [[ -n " ${pods} " && ${not_running} -eq 0 ]]; then
51
55
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 ' /' ' ' ) )
54
58
# All containers must be ready
55
59
[[ -z ${status[0]} ]] && all_ready=0 && break
56
60
[[ -z ${status[1]} ]] && all_ready=0 && break
57
61
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
58
62
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
59
63
[[ ${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
62
66
echo -e " \nAll pods are up:\n${pods} "
63
67
return 0
64
68
fi
@@ -79,8 +83,8 @@ function wait_until_object_exist() {
79
83
DESCRIPTION=" $1 $3 /$2 "
80
84
fi
81
85
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
84
88
echo -e " \n${DESCRIPTION} exist"
85
89
return 0
86
90
fi
@@ -101,8 +105,8 @@ function wait_until_object_doesnt_exist() {
101
105
DESCRIPTION=" $1 $3 /$2 "
102
106
fi
103
107
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
106
110
echo -e " \n${DESCRIPTION} dosen't exist"
107
111
return 0
108
112
fi
@@ -137,7 +141,6 @@ function dump_extra_cluster_state() {
137
141
kubectl -n openshift-gitops-operator logs $( get_app_pod argocd-operator openshift-gitops-operator) --all-containers=true
138
142
}
139
143
140
-
141
144
# Returns the name of the first pod of the given app.
142
145
# Parameters: $1 - app name.
143
146
# $2 - namespace (optional).
@@ -161,7 +164,6 @@ function fail_test() {
161
164
exit 1
162
165
}
163
166
164
-
165
167
function set_test_return_code() {
166
168
echo -n " $1 "
167
169
}
@@ -176,13 +178,13 @@ function success() {
176
178
exit 0
177
179
}
178
180
179
- function build_and_push_catalog_image(){
180
-
181
+ function build_and_push_catalog_image() {
182
+
181
183
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
184
186
else
185
- echo " >> skipping operator-sdk & olm installation"
187
+ echo " >> skipping operator-sdk & olm installation"
186
188
fi
187
189
188
190
echo " >> Building and pushing operator images"
@@ -199,15 +201,15 @@ function build_and_push_catalog_image(){
199
201
200
202
}
201
203
202
- function configure_operator(){
204
+ function configure_operator() {
203
205
header " Configuring OpenShift Gitops operator"
204
206
205
207
echo -e " Disabling default catalog sources"
206
208
kubectl patch operatorhub.config.openshift.io/cluster -p=' {"spec":{"disableAllDefaultSources":true}}' --type=merge
207
209
sleep 5
208
210
209
211
# 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
211
213
apiVersion: operators.coreos.com/v1alpha1
212
214
kind: CatalogSource
213
215
metadata:
@@ -222,18 +224,17 @@ spec:
222
224
interval: 30m
223
225
EOF
224
226
225
-
226
227
echo -e " Creating custom catalog source"
227
228
kubectl apply -f $TMP_DIR /catalog-source.yaml
228
229
229
230
echo " Waiting for pods in namespace openshift-marketplace to be ready"
230
231
# 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)
233
234
234
235
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
237
238
done
238
239
}
239
240
@@ -251,29 +252,29 @@ function uninstall_operator_resources() {
251
252
oc wait --for=delete $deployment -n openshift-gitops --timeout=5m || fail_test " Failed to delete deployment: $deployment in openshift-gitops namespace"
252
253
done
253
254
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"
255
256
256
257
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"
257
258
258
259
oc delete subscription gitops-operator -n openshift-gitops-operator --cascade=background || fail_test " Unable to delete subscription"
259
260
260
261
echo -e " >> Delete arogo resources accross all namespaces"
261
262
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
263
264
done
264
265
265
266
echo -e " >> Cleanup existing crds"
266
267
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
268
269
done
269
270
270
271
echo -e " >> Delete \" openshift-gitops\" project"
271
272
oc delete --ignore-not-found=true project openshift-gitops
272
273
}
273
274
274
275
function 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 ||
277
278
cat << EOF | oc apply -f -
278
279
apiVersion: operators.coreos.com/v1alpha1
279
280
kind: Subscription
@@ -287,24 +288,23 @@ spec:
287
288
source: $CATALOG_SOURCE
288
289
sourceNamespace: openshift-marketplace
289
290
EOF
290
-
291
- wait_until_pods_running " openshift-gitops-operator" || fail_test " openshift gitops Operator controller did not come up"
292
291
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"
295
296
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"
297
298
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
303
303
}
304
304
305
305
function get_operator_namespace() {
306
306
# TODO: parameterize namespace, operator can run in a namespace different from the namespace where tektonpipelines is installed
307
307
local operator_namespace=" argocd-operator"
308
308
[[ " ${TARGET} " == " openshift" ]] && operator_namespace=" openshift-gitops"
309
309
echo ${operator_namespace}
310
- }
310
+ }
0 commit comments