-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathrun-rollouts-e2e-tests.sh
executable file
·223 lines (157 loc) · 8.44 KB
/
run-rollouts-e2e-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# The goal of this script is to run the Argo Rollouts operator tests from the argo-rollouts-manager repo against gitops-operator:
# - Runs the cluster-scoped/namespace-scoped E2E tests of the Argo Rollouts operator
# - Runs the upstream E2E tests from the argo-rollouts repo
set -ex
function wait_until_pods_running() {
echo -n "Waiting until all pods in namespace $1 are up"
# Wait for there to be only a single Pod line in 'oc get pods' (there should be no more 'terminating' pods, etc)
timeout="true"
for i in {1..30}; do
local num_pods="$(oc get pods --no-headers -n $1 | grep openshift-gitops-operator-controller-manager | wc -l 2>/dev/null)"
# Check the number of lines
if [[ "$num_lines" == "1" ]]; then
echo "Waiting for a single Pod entry in Namespace '$1': $num_pods"
sleep 5
else
timeout="false"
break
fi
done
if [ "$timeout" == "true" ]; then
echo -e "\n\nERROR: timeout waiting for expected number of pods"
return 1
fi
for i in {1..150}; do # timeout after 5 minutes
local pods="$(oc get pods --no-headers -n $1 | grep openshift-gitops-operator-controller-manager 2>/dev/null)"
# write it to tempfile
TempFile=$(mktemp)
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
# All pods must be running
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
local all_ready=1
while read pod; do
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
# All containers must be ready
[[ -z ${status[0]} ]] && all_ready=0 && break
[[ -z ${status[1]} ]] && all_ready=0 && break
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
done <${TempFile}
if ((all_ready)); then
echo -e "\nAll pods are up:\n${pods}"
return 0
fi
fi
echo -n "."
sleep 2
done
echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}"
return 1
}
function enable_rollouts_cluster_scoped_namespaces() {
# This functions add this env var to operator:
# - CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES="argo-rollouts,test-rom-ns-1,rom-ns-1"
if ! [ -z $NON_OLM ]; then
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES="argo-rollouts,test-rom-ns-1,rom-ns-1"
elif [ -z $CI ]; then
oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
--type merge --patch '{"spec": {"config": {"env": [{"name": "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES", "value": "argo-rollouts,test-rom-ns-1,rom-ns-1"}]}}}'
else
oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
--type merge --patch '{"spec": {"config": {"env": [{"name": "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES", "value": "argo-rollouts,test-rom-ns-1,rom-ns-1"}]}}}'
fi
# Loop to wait until CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is added to the OpenShift GitOps Operator Deployment
for i in {1..30}; do
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be set"
break
else
echo "Waiting for CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be set"
sleep 5
fi
done
# Verify the variable is set
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is set."
else
echo "ERROR: CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was never set."
exit 1
fi
# Deployment is correct, now wait for Pods to start
wait_until_pods_running "openshift-gitops-operator"
}
function disable_rollouts_cluster_scope_namespaces() {
# Remove the env var we previously added to operator
if ! [ -z $NON_OLM ]; then
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=null
elif [ -z $CI ]; then
oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
else
oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
fi
# Loop to wait until CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is removed from the OpenShift GitOps Operator Deplyoment
for i in {1..30}; do
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "Waiting for CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be removed"
sleep 5
else
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES has been removed."
break
fi
done
# Verify it has been removed.
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "ERROR: CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was not successfully removed."
exit 1
else
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was successfuly removed."
fi
# Wait for Pods to reflect the removal of the env var
wait_until_pods_running "openshift-gitops-operator"
}
enable_rollouts_cluster_scoped_namespaces
trap disable_rollouts_cluster_scope_namespaces EXIT
ROLLOUTS_TMP_DIR=$(mktemp -d)
cd $ROLLOUTS_TMP_DIR
git clone https://github.com/argoproj-labs/argo-rollouts-manager
cd "$ROLLOUTS_TMP_DIR/argo-rollouts-manager"
# This commit value will be automatically updated by calling 'hack/upgrade-rollouts-manager/go-run.sh':
# - It should always point to the same argo-rollouts-manager commit that is referenced in go.mod of gitops-operator (which will usually be the most recent argo-rollouts-manager commit)
TARGET_ROLLOUT_MANAGER_COMMIT=bb5580b286c595f91dfc21382df494e5fb8f9a46
# This commit value will be automatically updated by calling 'hack/upgrade-rollouts-manager/go-run.sh':
# - It should always point to the same argo-rollouts-manager commit that is referenced in the version of argo-rollouts-manager that is in go.mod
TARGET_OPENSHIFT_ROUTE_ROLLOUT_PLUGIN_COMMIT=8b4125a7f9ecffb0247df91a4c890f88c0c523b7
git checkout $TARGET_ROLLOUT_MANAGER_COMMIT
# 1) Run E2E tests from argo-rollouts-manager repo
# We use 'DISABLE_METRICS=true' since metrics gathering only works when run directly via Rollouts E2E tests
DISABLE_METRICS=true make test-e2e
# Clean up old namespaces created by test
# NOTE: remove this once this is handled by 'make test-e2e' in argo-rollouts-manager repo
kubectl delete rolloutmanagers --all -n test-rom-ns-1 || true
cd "$ROLLOUTS_TMP_DIR/argo-rollouts-manager"
# 2) Run E2E tests from argoproj/argo-rollouts repo
SKIP_RUN_STEP=true hack/run-upstream-argo-rollouts-e2e-tests.sh
# 3) Run rollouts-plugin-trafficrouter-openshift E2E tests
kubectl delete ns argo-rollouts || true
kubectl wait --timeout=5m --for=delete namespace/argo-rollouts
kubectl create ns argo-rollouts
kubectl config set-context --current --namespace=argo-rollouts
cat << EOF > "$ROLLOUTS_TMP_DIR/rollout-manager.yaml"
apiVersion: argoproj.io/v1alpha1
kind: RolloutManager
metadata:
name: argo-rollout
namespace: argo-rollouts
spec: {}
EOF
kubectl apply -f "$ROLLOUTS_TMP_DIR/rollout-manager.yaml"
cd "$ROLLOUTS_TMP_DIR"
git clone https://github.com/argoproj-labs/rollouts-plugin-trafficrouter-openshift
cd "$ROLLOUTS_TMP_DIR/rollouts-plugin-trafficrouter-openshift"
git checkout $TARGET_OPENSHIFT_ROUTE_ROLLOUT_PLUGIN_COMMIT
make test-e2e