Skip to content

Commit 70056f4

Browse files
committed
ci: Ensure e2e setup errors fail tests, add retries during e2e setup
Setting up the correct configuration values like `enable-api-fields` is not optional since many tests depend on these values at runtime. If a test requires non-default config values which failed to be set, the failure may not cause an e2e test to fail for some time and the test failure message will cause confusion; the configuration being correct during setup is a given. By ensuring a failure in any of the configuration setup functions results in the test suite failing, we ensure the tests will only run against the expected configuration. This change ensures that if the e2e test configuration fails, the tests will not continue. Fixing that improves the clarity of some flaky failures, but it doesn't reduce the flakiness itself. To reduce failures during e2e environment configuration, this change also implements a retry mechanism to each of the set configuration functions. This reduces flakiness due to network connectivity or race conditions during environment setup. If all config retries are exhausted with failure, then the tests will fail as above.
1 parent 4d978f9 commit 70056f4

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

test/e2e-common.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@
1818

1919
source $(git rev-parse --show-toplevel)/vendor/github.com/tektoncd/plumbing/scripts/e2e-tests.sh
2020

21+
# Run the given five times or until it succeeds.
22+
# Sleeps 5 seconds after earch retry.
23+
# example usage: `with_retries ping fakeserver.com`
24+
function with_retries() (
25+
set +eo pipefail
26+
27+
success=""
28+
for retry in 1 2 3 4 5; do
29+
"$@"
30+
success="$?"
31+
if [ "${success}" -eq "0" ]; then
32+
break
33+
fi
34+
sleep 5
35+
[[ "${retry}" != "5" ]] && echo "Retrying..."
36+
done
37+
38+
return "${success}"
39+
)
40+
2141
function install_pipeline_crd() {
2242
echo ">> Deploying Tekton Pipelines"
2343
local ko_target="$(mktemp)"

test/e2e-tests.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ ENABLE_PARAM_ENUM=${ENABLE_PARAM_ENUM:="false"}
3434
ENABLE_ARTIFACTS=${ENABLE_ARTIFACTS:="false"}
3535
ENABLE_CONCISE_RESOLVER_SYNTAX=${ENABLE_CONCISE_RESOLVER_SYNTAX:="false"}
3636
ENABLE_KUBERNETES_SIDECAR=${ENABLE_KUBERNETES_SIDECAR:="false"}
37-
failed=0
3837

3938
# Script entry point.
4039

@@ -49,7 +48,6 @@ install_pipeline_crd
4948
export SYSTEM_NAMESPACE=tekton-pipelines
5049
set +x
5150

52-
failed=0
5351

5452
function add_spire() {
5553
local gate="$1"
@@ -59,7 +57,6 @@ function add_spire() {
5957
install_spire
6058
patch_pipeline_spire
6159
kubectl apply -n tekton-pipelines -f "$DIR"/testdata/spire/config-spire.yaml
62-
failed=0
6360
fi
6461
}
6562

@@ -72,7 +69,7 @@ function set_feature_gate() {
7269
printf "Setting feature gate to %s\n", ${gate}
7370
jsonpatch=$(printf "{\"data\": {\"enable-api-fields\": \"%s\"}}" $1)
7471
echo "feature-flags ConfigMap patch: ${jsonpatch}"
75-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
72+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
7673
}
7774

7875
function set_result_extraction_method() {
@@ -84,7 +81,7 @@ function set_result_extraction_method() {
8481
printf "Setting results-from to %s\n", ${method}
8582
jsonpatch=$(printf "{\"data\": {\"results-from\": \"%s\"}}" $1)
8683
echo "feature-flags ConfigMap patch: ${jsonpatch}"
87-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
84+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
8885
}
8986

9087
function set_keep_pod_on_cancel() {
@@ -96,7 +93,7 @@ function set_keep_pod_on_cancel() {
9693
printf "Setting keep-pod-on-cancel to %s\n", ${method}
9794
jsonpatch=$(printf "{\"data\": {\"keep-pod-on-cancel\": \"%s\"}}" $1)
9895
echo "feature-flags ConfigMap patch: ${jsonpatch}"
99-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
96+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
10097
}
10198

10299
function set_cel_in_whenexpression() {
@@ -107,7 +104,7 @@ function set_cel_in_whenexpression() {
107104
fi
108105
jsonpatch=$(printf "{\"data\": {\"enable-cel-in-whenexpression\": \"%s\"}}" $1)
109106
echo "feature-flags ConfigMap patch: ${jsonpatch}"
110-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
107+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
111108
}
112109

113110
function set_enable_param_enum() {
@@ -119,7 +116,7 @@ function set_enable_param_enum() {
119116
printf "Setting enable-param-enum to %s\n", ${method}
120117
jsonpatch=$(printf "{\"data\": {\"enable-param-enum\": \"%s\"}}" $1)
121118
echo "feature-flags ConfigMap patch: ${jsonpatch}"
122-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
119+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
123120
}
124121

125122
function set_enable_artifacts() {
@@ -131,7 +128,7 @@ function set_enable_artifacts() {
131128
printf "Setting enable-artifacts to %s\n", ${method}
132129
jsonpatch=$(printf "{\"data\": {\"enable-artifacts\": \"%s\"}}" $1)
133130
echo "feature-flags ConfigMap patch: ${jsonpatch}"
134-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
131+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
135132
}
136133

137134
function set_enable_concise_resolver_syntax() {
@@ -143,7 +140,7 @@ function set_enable_concise_resolver_syntax() {
143140
printf "Setting enable-concise-resolver-syntax to %s\n", ${method}
144141
jsonpatch=$(printf "{\"data\": {\"enable-concise-resolver-syntax\": \"%s\"}}" $1)
145142
echo "feature-flags ConfigMap patch: ${jsonpatch}"
146-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
143+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
147144
}
148145

149146
function set_enable_kubernetes_sidecar() {
@@ -155,40 +152,43 @@ function set_enable_kubernetes_sidecar() {
155152
printf "Setting enable-kubernetes-sidecar to %s\n", ${method}
156153
jsonpatch=$(printf "{\"data\": {\"enable-kubernetes-sidecar\": \"%s\"}}" $1)
157154
echo "feature-flags ConfigMap patch: ${jsonpatch}"
158-
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
155+
with_retries kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
159156
}
160157

161158
function set_default_sidecar_log_polling_interval() {
162159
# Sets the default-sidecar-log-polling-interval in the config-defaults ConfigMap to 0ms for e2e tests
163160
echo "Patching config-defaults ConfigMap: setting default-sidecar-log-polling-interval to 0ms"
164161
jsonpatch='{"data": {"default-sidecar-log-polling-interval": "0ms"}}'
165-
kubectl patch configmap config-defaults -n tekton-pipelines -p "$jsonpatch"
162+
with_retries kubectl patch configmap config-defaults -n tekton-pipelines -p "$jsonpatch"
166163
}
167164

168165
function run_e2e() {
169166
# Run the integration tests
170167
header "Running Go e2e tests"
171168
# Skip ./test/*.go tests if SKIP_GO_E2E_TESTS == true
172169
if [ "${SKIP_GO_E2E_TESTS}" != "true" ]; then
173-
go_test_e2e -timeout=${E2E_GO_TEST_TIMEOUT} ./test/... || failed=1
170+
go_test_e2e -timeout=${E2E_GO_TEST_TIMEOUT} ./test/...
174171
fi
175172

176173
# Run these _after_ the integration tests b/c they don't quite work all the way
177174
# and they cause a lot of noise in the logs, making it harder to debug integration
178175
# test failures.
179176
if [ "${RUN_YAML_TESTS}" == "true" ]; then
180-
go_test_e2e -mod=readonly -tags=examples -timeout=${E2E_GO_TEST_TIMEOUT} ./test/ || failed=1
177+
go_test_e2e -mod=readonly -tags=examples -timeout=${E2E_GO_TEST_TIMEOUT} ./test/
181178
fi
182179

183180
if [ "${RUN_FEATUREFLAG_TESTS}" == "true" ]; then
184-
go_test_e2e -mod=readonly -tags=featureflags -timeout=${E2E_GO_TEST_TIMEOUT} ./test/ || failed=1
181+
go_test_e2e -mod=readonly -tags=featureflags -timeout=${E2E_GO_TEST_TIMEOUT} ./test/
185182
fi
186183
}
187184

185+
set -eo pipefail
186+
trap '[[ "$?" == "0" ]] || fail_test' EXIT
187+
188188
add_spire "$PIPELINE_FEATURE_GATE"
189189
set_feature_gate "$PIPELINE_FEATURE_GATE"
190190
set_result_extraction_method "$RESULTS_FROM"
191-
set_keep_pod_on_cancel "$KEEP_POD_ON_CANCEL"
191+
set_keep_pod_on_cancel "$KEEP_POD_ON_CANCEL"
192192
set_cel_in_whenexpression "$ENABLE_CEL_IN_WHENEXPRESSION"
193193
set_enable_param_enum "$ENABLE_PARAM_ENUM"
194194
set_enable_artifacts "$ENABLE_ARTIFACTS"
@@ -197,5 +197,4 @@ set_enable_kubernetes_sidecar "$ENABLE_KUBERNETES_SIDECAR"
197197
set_default_sidecar_log_polling_interval
198198
run_e2e
199199

200-
(( failed )) && fail_test
201200
success

0 commit comments

Comments
 (0)