forked from openshift-knative/eventing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e-common.sh
285 lines (234 loc) · 9.69 KB
/
e2e-common.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/env bash
if [[ -n "${ARTIFACT_DIR:-}" ]]; then
BUILD_NUMBER=${BUILD_NUMBER:-$(head -c 128 < /dev/urandom | base64 | fold -w 8 | head -n 1)}
ARTIFACTS="${ARTIFACT_DIR}/build-${BUILD_NUMBER}"
export ARTIFACTS
mkdir -p "${ARTIFACTS}"
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export EVENTING_NAMESPACE="${EVENTING_NAMESPACE:-knative-eventing}"
export SYSTEM_NAMESPACE=$EVENTING_NAMESPACE
export ZIPKIN_NAMESPACE=$EVENTING_NAMESPACE
export KNATIVE_DEFAULT_NAMESPACE=$EVENTING_NAMESPACE
export CONFIG_TRACING_CONFIG="test/config/config-tracing.yaml"
export SKIP_GENERATE_RELEASE=${SKIP_GENERATE_RELEASE:-false}
export EVENTING_TEST_IMAGE_TEMPLATE=$(cat <<-END
{{- with .Name }}
{{- if eq . "event-flaker"}}$KNATIVE_EVENTING_TEST_EVENT_FLAKER{{end -}}
{{- if eq . "event-library"}}$KNATIVE_EVENTING_TEST_EVENT_LIBRARY{{end -}}
{{- if eq . "event-sender"}}$KNATIVE_EVENTING_TEST_EVENT_SENDER{{end -}}
{{- if eq . "eventshub"}}$KNATIVE_EVENTING_TEST_EVENTSHUB{{end -}}
{{- if eq . "heartbeats"}}$KNATIVE_EVENTING_TEST_HEARTBEATS{{end -}}
{{- if eq . "performance"}}$KNATIVE_EVENTING_TEST_PERFORMANCE{{end -}}
{{- if eq . "print"}}$KNATIVE_EVENTING_TEST_PRINT{{end -}}
{{- if eq . "recordevents"}}$KNATIVE_EVENTING_TEST_RECORDEVENTS{{end -}}
{{- if eq . "request-sender"}}$KNATIVE_EVENTING_TEST_REQUEST_SENDER{{end -}}
{{- if eq . "wathola-fetcher"}}$KNATIVE_EVENTING_TEST_WATHOLA_FETCHER{{end -}}
{{- if eq . "wathola-forwarder"}}$KNATIVE_EVENTING_TEST_WATHOLA_FORWARDER{{end -}}
{{- if eq . "wathola-receiver"}}$KNATIVE_EVENTING_TEST_WATHOLA_RECEIVER{{end -}}
{{- if eq . "wathola-sender"}}$KNATIVE_EVENTING_TEST_WATHOLA_SENDER{{end -}}
{{end -}}
END
)
function scale_up_workers(){
local cluster_api_ns="openshift-machine-api"
oc get machineset -n ${cluster_api_ns} --show-labels
# Get the name of the first machineset that has at least 1 replica
local machineset
machineset=$(oc get machineset -n ${cluster_api_ns} -o custom-columns="name:{.metadata.name},replicas:{.spec.replicas}" | grep " 1" | head -n 1 | awk '{print $1}')
# Bump the number of replicas to 6 (+ 1 + 1 == 8 workers)
oc patch machineset -n ${cluster_api_ns} "${machineset}" -p '{"spec":{"replicas":6}}' --type=merge
wait_until_machineset_scales_up ${cluster_api_ns} "${machineset}" 6
}
# Waits until the machineset in the given namespaces scales up to the
# desired number of replicas
# Parameters: $1 - namespace
# $2 - machineset name
# $3 - desired number of replicas
function wait_until_machineset_scales_up() {
echo -n "Waiting until machineset $2 in namespace $1 scales up to $3 replicas"
for _ in {1..150}; do # timeout after 15 minutes
local available
available=$(oc get machineset -n "$1" "$2" -o jsonpath="{.status.availableReplicas}")
if [[ ${available} -eq $3 ]]; then
echo -e "\nMachineSet $2 in namespace $1 successfully scaled up to $3 replicas"
return 0
fi
echo -n "."
sleep 6
done
echo - "Error: timeout waiting for machineset $2 in namespace $1 to scale up to $3 replicas"
return 1
}
# Loops until duration (car) is exceeded or command (cdr) returns non-zero
function timeout_non_zero() {
SECONDS=0; TIMEOUT=$1; shift
while eval $*; do
sleep 5
[[ $SECONDS -gt $TIMEOUT ]] && echo "ERROR: Timed out" && return 1
done
return 0
}
function install_serverless(){
header "Installing Serverless Operator"
KNATIVE_EVENTING_MANIFESTS_DIR="${SCRIPT_DIR}/release/artifacts"
export KNATIVE_EVENTING_MANIFESTS_DIR
GO111MODULE=off go get -u github.com/openshift-knative/hack/cmd/sobranch
local release
release=$(yq r "${SCRIPT_DIR}/project.yaml" project.tag)
release=${release/knative-/}
so_branch=$( $(go env GOPATH)/bin/sobranch --upstream-version "${release}")
local operator_dir=/tmp/serverless-operator
git clone --branch "${so_branch}" https://github.com/openshift-knative/serverless-operator.git $operator_dir || git clone --branch main https://github.com/openshift-knative/serverless-operator.git $operator_dir
export GOPATH=/tmp/go
local failed=0
pushd $operator_dir || return $?
export ON_CLUSTER_BUILDS=true
export DOCKER_REPO_OVERRIDE=image-registry.openshift-image-registry.svc:5000/openshift-marketplace
OPENSHIFT_CI="true" TRACING_BACKEND="zipkin" ENABLE_TRACING="true" make generated-files images install-tracing install-eventing || failed=$?
cat ${operator_dir}/olm-catalog/serverless-operator/manifests/serverless-operator.clusterserviceversion.yaml
popd || return $?
return $failed
}
function run_e2e_rekt_tests(){
header "Running E2E Reconciler Tests"
images_file=$(dirname $(realpath "$0"))/images.yaml
#allow skipping if test images aren't multiarch.
if [ "$SKIP_GENERATE_RELEASE" == false ]; then
make generate-release
fi
cat "${images_file}"
local test_name="${1:-}"
local run_command=""
local failed=0
if [ -n "$test_name" ]; then
local run_command="-run ^(${test_name})$"
fi
# check for test flags
RUN_FLAGS="-timeout=90m -parallel=20"
if [ -n "${EVENTING_TEST_FLAGS:-}" ]; then
RUN_FLAGS="${EVENTING_TEST_FLAGS}"
fi
go_test_e2e ${RUN_FLAGS} ./test/rekt --images.producer.file="${images_file}" || failed=$?
return $failed
}
function run_e2e_encryption_auth_tests(){
header "Running E2E Encryption and Auth Tests"
oc patch knativeeventing --type merge -n "${EVENTING_NAMESPACE}" knative-eventing --patch-file "${SCRIPT_DIR}/knative-eventing-encryption-auth.yaml"
images_file=$(dirname $(realpath "$0"))/images.yaml
#allow skipping if test images aren't multiarch.
if [ "$SKIP_GENERATE_RELEASE" == false ]; then
make generate-release
fi
cat "${images_file}"
oc wait --for=condition=Ready knativeeventing.operator.knative.dev knative-eventing -n "${EVENTING_NAMESPACE}" --timeout=900s || return $?
local regex="TLS|OIDC"
local test_name="${1:-}"
local run_command="-run ${regex}"
local failed=0
if [ -n "$test_name" ]; then
local run_command="-run ^(${test_name})$"
fi
# check for test flags
RUN_FLAGS="-timeout=1h -parallel=20 ${run_command}"
if [ -n "${EVENTING_TEST_FLAGS:-}" ]; then
RUN_FLAGS="${EVENTING_TEST_FLAGS}"
fi
go_test_e2e ${RUN_FLAGS} ./test/rekt --images.producer.file="${images_file}" || failed=$?
return $failed
}
function run_e2e_tests(){
header "Running E2E tests with Multi Tenant Channel Based Broker"
local test_name="${1:-}"
local run_command=""
local failed=0
local channels=messaging.knative.dev/v1:Channel,messaging.knative.dev/v1:InMemoryChannel
local sources=sources.knative.dev/v1beta2:PingSource,sources.knative.dev/v1:ApiServerSource,sources.knative.dev/v1:ContainerSource
local common_opts=" -channels=$channels -sources=$sources --kubeconfig $KUBECONFIG"
if [ -n "$test_name" ]; then
local run_command="-run ^(${test_name})$"
fi
# check for test flags
RUN_FLAGS="-timeout=50m -parallel=20"
if [ -n "${EVENTING_TEST_FLAGS:-}" ]; then
RUN_FLAGS="${EVENTING_TEST_FLAGS}"
fi
# check for test args
if [ -n "${EVENTING_TEST_ARGS:-}" ]; then
common_opts="${EVENTING_TEST_ARGS}"
fi
# execute tests
go_test_e2e ${RUN_FLAGS} ./test/e2e \
"$run_command" \
-imagetemplate="$TEST_IMAGE_TEMPLATE" \
${common_opts} || failed=$?
return $failed
}
function run_conformance_tests(){
header "Running Conformance tests with Multi Tenant Channel Based Broker"
local test_name="${1:-}"
local run_command=""
local failed=0
local channels=messaging.knative.dev/v1:Channel,messaging.knative.dev/v1:InMemoryChannel
local sources=sources.knative.dev/v1beta2:PingSource,sources.knative.dev/v1:ApiServerSource,sources.knative.dev/v1:ContainerSource
local common_opts=" -channels=$channels -sources=$sources --kubeconfig $KUBECONFIG"
if [ -n "$test_name" ]; then
local run_command="-run ^(${test_name})$"
fi
# check for test flags
RUN_FLAGS="-timeout=50m -parallel=12"
if [ -n "${EVENTING_TEST_FLAGS:-}" ]; then
RUN_FLAGS="${EVENTING_TEST_FLAGS}"
fi
# check for test args
if [ -n "${EVENTING_TEST_ARGS:-}" ]; then
common_opts="${EVENTING_TEST_ARGS}"
fi
# execute tests
go_test_e2e ${RUN_FLAGS} ./test/conformance \
"$run_command" \
-imagetemplate="$TEST_IMAGE_TEMPLATE" \
${common_opts} || failed=$?
return $failed
}
function run_e2e_rekt_experimental_tests(){
header "Running E2E experimental Tests"
local script_dir; script_dir="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
oc patch knativeeventing --type merge -n "${EVENTING_NAMESPACE}" knative-eventing --patch-file "${script_dir}/knative-eventing-experimental.yaml"
images_file=$(dirname $(realpath "$0"))/images.yaml
make generate-release
cat "${images_file}"
oc wait --for=condition=Ready knativeeventing.operator.knative.dev knative-eventing -n "${EVENTING_NAMESPACE}" --timeout=900s
local failed=0
# check for test flags
RUN_FLAGS="-timeout=1h -parallel=20"
if [ -n "${EVENTING_TEST_FLAGS:-}" ]; then
RUN_FLAGS="${EVENTING_TEST_FLAGS}"
fi
go_test_e2e ${RUN_FLAGS} ./test/experimental --images.producer.file="${images_file}" || failed=$?
return $failed
}
# Waits until the given object exists.
# Parameters: $1 - the kind of the object.
# $2 - object's name.
# $3 - namespace (optional).
function wait_until_object_exists() {
local KUBECTL_ARGS="get $1 $2"
local DESCRIPTION="$1 $2"
if [[ -n $3 ]]; then
KUBECTL_ARGS="get -n $3 $1 $2"
DESCRIPTION="$1 $3/$2"
fi
echo -n "Waiting until ${DESCRIPTION} exists"
for i in {1..250}; do # timeout after 5 minutes
if kubectl ${KUBECTL_ARGS} > /dev/null 2>&1; then
echo -e "\n${DESCRIPTION} exists"
return 0
fi
echo -n "."
sleep 2
done
echo -e "\n\nERROR: timeout waiting for ${DESCRIPTION} to exist"
kubectl ${KUBECTL_ARGS}
return 1
}