@@ -267,91 +267,59 @@ jobs:
267267 \"
268268 "
269269
270- - name : Run Python tests (in-cluster)
270+ - name : Fetch OAuth token from inside cluster (runner starts ephemeral curl pod)
271+ env :
272+ REALM : test
273+ CLIENT_ID : vertica
274+ CLIENT_SECRET : P9f8350QQIUhFfK1GF5sMhq4Dm3P6Sbs
275+ run : |
276+ set -euo pipefail
277+ TOKEN_ENDPOINT="http://keycloak.keycloak.svc.cluster.local:8080/realms/${REALM}/protocol/openid-connect/token"
278+
279+ RAW_JSON=$(kubectl -n keycloak run --rm -i --restart=Never \
280+ --image=curlimages/curl:7.92.0 --command -- sh -c "
281+ curl -s -w '\n%{http_code}' -X POST '${TOKEN_ENDPOINT}' \
282+ -d 'grant_type=client_credentials' \
283+ -d 'client_id=${CLIENT_ID}' \
284+ -d 'client_secret=${CLIENT_SECRET}'
285+ ")
286+
287+ HTTP_CODE=$(printf "%s" "$RAW_JSON" | tail -n1)
288+ BODY=$(printf "%s" "$RAW_JSON" | sed '$d')
289+
290+ echo "Token endpoint HTTP status: $HTTP_CODE"
291+ if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -ge 300 ]; then
292+ echo "Failed to get token; response (truncated):"
293+ printf "%.1024s\n" "$BODY"
294+ exit 1
295+ fi
296+
297+ TOKEN=$(printf "%s" "$BODY" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("access_token",""))')
298+
299+ if [ -z "$TOKEN" ]; then
300+ echo "No access_token found; full body:"
301+ echo "$BODY"
302+ exit 1
303+ fi
304+
305+ printf "%s" "$TOKEN" > access_token.txt
306+ echo "Access token saved to access_token.txt"
307+
308+ - name : Copy token into python test pod
271309 run : |
272310 NS=my-verticadb-operator
273- SVC=verticadb-sample-defaultsubcluster
274- LOCATOR="${SVC}.${NS}.svc.cluster.local:5433"
275-
276- WAIT_TIMEOUT=300
277- INTERVAL=5
278- deadline=$((SECONDS + WAIT_TIMEOUT))
279- while [ $SECONDS -lt $deadline ]; do
280- addrs=$(kubectl -n ${NS} get endpoints ${SVC} -o jsonpath='{.subsets[*].addresses[*].ip}' || true)
281- [ -n "$addrs" ] && break || sleep ${INTERVAL}
282- done
283-
284- kubectl -n ${NS} run py-test-runner --image=python:3.11-slim --restart=Never -- sleep infinity
285- kubectl -n ${NS} wait --for=condition=Ready pod/py-test-runner --timeout=120s
286-
287- kubectl -n ${NS} exec -i pod/py-test-runner -- mkdir -p /workspace
288- tar cf - . | kubectl -n ${NS} exec -i pod/py-test-runner -- tar xf - -C /workspace
289-
290- kubectl -n ${NS} exec -i pod/py-test-runner -- bash -lc "
291- set -euo pipefail
292- cd /workspace
293- python -m pip install --upgrade pip
294- pip install tox pytest || true
295- "
296-
297- kubectl -n ${NS} exec -i pod/py-test-runner -- bash -lc "
298- set -euo pipefail
299- TOKEN_ENDPOINT='http://keycloak.keycloak.svc.cluster.local:8080/realms/${REALM}/protocol/openid-connect/token'
300- MAX_RETRIES=6
301- SLEEP=3
302- attempt=0
303- BODY=''
304- HTTP_CODE=0
305-
306- while [ \$attempt -lt \$MAX_RETRIES ]; do
307- RAW=\$(kubectl -n keycloak run --rm -i --restart=Never \
308- --image=curlimages/curl:7.92.0 --command -- sh -c \"\
309- curl -s -w '\\\\n%{http_code}' -X POST '\${TOKEN_ENDPOINT}' \
310- -d 'client_id=${CLIENT_ID}' \
311- -d 'username=${USER}' \
312- -d 'password=${PASSWORD}' \
313- -d 'grant_type=password' \
314- -d 'client_secret=${CLIENT_SECRET}'\" ) || true
315-
316- HTTP_CODE=\$(printf '%s' \"\$RAW\" | tail -n1)
317- BODY=\$(printf '%s' \"\$RAW\" | sed '\$d')
318-
319- echo \"Token attempt \$((attempt+1)) HTTP: \$HTTP_CODE\"
320- printf 'Resp (trunc 1024): %.1024s\n' \"\$BODY\"
321-
322- if [ \"\$HTTP_CODE\" -ge 200 ] && [ \"\$HTTP_CODE\" -lt 300 ]; then
323- break
324- fi
325- attempt=\$((attempt+1))
326- sleep \$SLEEP
327- done
328-
329- if [ -z \"\$BODY\" ]; then
330- echo 'Empty response from Keycloak; failing'
331- exit 1
332- fi
333-
334- TOKEN=\$(printf '%s' \"\$BODY\" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get(\"access_token\",\"\"))' || true)
335-
336- if [ -z \"\$TOKEN\" ]; then
337- echo 'Failed to retrieve access_token; full response:'
338- echo \"\$BODY\"
339- exit 1
340- fi
341-
342- printf '%s' \"\$TOKEN\" > /workspace/access_token.txt
343- echo 'Access token retrieved and saved to /workspace/access_token.txt'
344- "
311+ kubectl -n ${NS} cp access_token.txt pod/py-test-runner:/workspace/access_token.txt
345312
313+ - name : Run tests inside python pod
314+ run : |
315+ NS=my-verticadb-operator
346316 kubectl -n ${NS} exec -i pod/py-test-runner -- bash -lc "
347317 set -euo pipefail
348318 cd /workspace
349319 export VP_TEST_OAUTH_ACCESS_TOKEN=\$(cat access_token.txt)
350- tox -e py || pytest -v || true
320+ tox -e py
351321 "
352322
353- kubectl -n ${NS} delete pod py-test-runner --ignore-not-found=true
354-
355323 - name : Uninstall MinIO
356324 if : always()
357325 run : |
0 commit comments