Skip to content

Commit 0d1b86f

Browse files
authored
chore(ci): droute with bastion pod - switch contexts and enhanced waiting in retries (#2599)
* Switch context instead of temp kubeconfig
1 parent 01b9728 commit 0d1b86f

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

.ibm/pipelines/utils.sh

+27-20
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,25 @@ save_all_pod_logs(){
3737

3838
droute_send() {
3939
if [[ "${OPENSHIFT_CI}" != "true" ]]; then return 0; fi
40-
temp_kubeconfig=$(mktemp) # Create temporary KUBECONFIG to open second `oc` session
40+
local original_context
41+
original_context=$(oc config current-context) # Save original context
4142
( # Open subshell
4243
if [ -n "${PULL_NUMBER:-}" ]; then
4344
set +e
4445
fi
45-
export KUBECONFIG="$temp_kubeconfig"
4646
local droute_version="1.2.2"
4747
local release_name=$1
4848
local project=$2
4949
local droute_project="droute"
5050
local metadata_output="data_router_metadata_output.json"
5151

52-
oc login --token="${RHDH_PR_OS_CLUSTER_TOKEN}" --server="${RHDH_PR_OS_CLUSTER_URL}"
52+
oc config set-credentials temp-user --token="${RHDH_PR_OS_CLUSTER_TOKEN}"
53+
oc config set-cluster temp-cluster --server="${RHDH_PR_OS_CLUSTER_URL}"
54+
oc config set-context temp-context --user=temp-user --cluster=temp-cluster
55+
oc config use-context temp-context
5356
oc whoami --show-server
57+
trap 'oc config use-context "$original_context"' RETURN
58+
5459
local droute_pod_name=$(oc get pods -n droute --no-headers -o custom-columns=":metadata.name" | grep ubi9-cert-rsync)
5560
local temp_droute=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "mktemp -d")
5661

@@ -97,19 +102,21 @@ droute_send() {
97102

98103
# Send test by rsync to bastion pod.
99104
local max_attempts=5
100-
local wait_seconds=4
105+
local wait_seconds_step=1
101106
for ((i = 1; i <= max_attempts; i++)); do
102107
echo "Attempt ${i} of ${max_attempts} to rsync test resuls to bastion pod."
103108
if output=$(oc rsync --progress=true --include="${metadata_output}" --include="${JUNIT_RESULTS}" --exclude="*" -n "${droute_project}" "${ARTIFACT_DIR}/${project}/" "${droute_project}/${droute_pod_name}:${temp_droute}/" 2>&1); then
104109
echo "$output"
105110
break
106-
fi
107-
if ((i == max_attempts)); then
111+
elif ((i == max_attempts)); then
108112
echo "Failed to rsync test results after ${max_attempts} attempts."
109113
echo "Last rsync error details:"
110114
echo "${output}"
111115
echo "Troubleshooting steps:"
112116
echo "1. Restart $droute_pod_name in $droute_project project/namespace"
117+
return 1
118+
else
119+
sleep $((wait_seconds_step * i))
113120
fi
114121
done
115122

@@ -120,33 +127,33 @@ droute_send() {
120127
&& ${temp_droute}/droute-linux-amd64 version"
121128

122129
# Send test results through DataRouter and save the request ID.
123-
local max_attempts=5
124-
local wait_seconds=1
130+
local max_attempts=10
131+
local wait_seconds_step=1
125132
for ((i = 1; i <= max_attempts; i++)); do
126133
echo "Attempt ${i} of ${max_attempts} to send test results through Data Router."
127-
if output=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
134+
output=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
128135
${temp_droute}/droute-linux-amd64 send --metadata ${temp_droute}/${metadata_output} \
129136
--url '${DATA_ROUTER_URL}' \
130137
--username '${DATA_ROUTER_USERNAME}' \
131138
--password '${DATA_ROUTER_PASSWORD}' \
132139
--results '${temp_droute}/${JUNIT_RESULTS}' \
133-
--verbose" 2>&1); then
134-
if DATA_ROUTER_REQUEST_ID=$(echo "$output" | grep "request:" | awk '{print $2}') &&
135-
[ -n "$DATA_ROUTER_REQUEST_ID" ]; then
136-
echo "Test results successfully sent through Data Router."
137-
echo "Request ID: $DATA_ROUTER_REQUEST_ID"
138-
break
139-
fi
140-
fi
141-
142-
if ((i == max_attempts)); then
140+
--verbose" 2>&1)
141+
if DATA_ROUTER_REQUEST_ID=$(echo "$output" | grep "request:" | awk '{print $2}') &&
142+
[ -n "$DATA_ROUTER_REQUEST_ID" ]; then
143+
echo "Test results successfully sent through Data Router."
144+
echo "Request ID: $DATA_ROUTER_REQUEST_ID"
145+
break
146+
elif ((i == max_attempts)); then
143147
echo "Failed to send test results after ${max_attempts} attempts."
144148
echo "Last Data Router error details:"
145149
echo "${output}"
146150
echo "Troubleshooting steps:"
147151
echo "1. Restart $droute_pod_name in $droute_project project/namespace"
148152
echo "2. Check the Data Router documentation: https://spaces.redhat.com/pages/viewpage.action?pageId=115488042"
149153
echo "3. Ask for help at Slack: #forum-dno-datarouter"
154+
return 1
155+
else
156+
sleep $((wait_seconds_step * i))
150157
fi
151158
done
152159

@@ -180,7 +187,7 @@ droute_send() {
180187
set -e
181188
fi
182189
) # Close subshell
183-
rm -f "$temp_kubeconfig" # Destroy temporary KUBECONFIG
190+
oc config use-context "$original_context" # Restore original context
184191
oc whoami --show-server
185192
}
186193

e2e-tests/playwright/e2e/plugins/kubernetes-actions/kubernetes-actions.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, test } from "@playwright/test";
1+
import { expect, Page, test } from "@playwright/test";
22
import { Common, setupBrowser } from "../../../utils/common";
33
import { UIhelper } from "../../../utils/ui-helper";
44
import { KubeClient } from "../../../utils/kube-client";
@@ -36,6 +36,9 @@ test.describe("Test Kubernetes Actions plugin", () => {
3636
await page.waitForSelector(
3737
`${UI_HELPER_ELEMENTS.MuiTypography}:has-text("second")`,
3838
);
39+
await expect(
40+
page.locator(`${UI_HELPER_ELEMENTS.MuiTypography}:has-text("Error")`),
41+
).not.toBeVisible();
3942
await kubeClient.getNamespaceByName(namespace);
4043
});
4144

0 commit comments

Comments
 (0)