From 236866e12eeb70ec262b96d49f7d839f7d2ae3c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Romanowski Date: Wed, 12 Jun 2024 09:02:57 +0000 Subject: [PATCH] add tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh --- .github/workflows/kserve_m2m_test.yaml | 4 ++ .../notebook_controller_m2m_test.yaml | 8 +++- ...wait_for_kubeflow_m2m_oidc_configurator.sh | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100755 tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh diff --git a/.github/workflows/kserve_m2m_test.yaml b/.github/workflows/kserve_m2m_test.yaml index 3c5b8032ee..68b08c73b4 100644 --- a/.github/workflows/kserve_m2m_test.yaml +++ b/.github/workflows/kserve_m2m_test.yaml @@ -67,6 +67,10 @@ jobs: nohup kubectl port-forward --namespace istio-system svc/${INGRESS_GATEWAY_SERVICE} 8080:80 & while ! curl localhost:8080; do echo waiting for port-forwarding; sleep 1; done; echo port-forwarding ready + - name: Wait for the kubeflow-m2m-oidc-configurator Job + run: | + ./tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh + - name: Run kserve tests with m2m token from SA default/default run: | export KSERVE_INGRESS_HOST_PORT=localhost:8080 diff --git a/.github/workflows/notebook_controller_m2m_test.yaml b/.github/workflows/notebook_controller_m2m_test.yaml index 787ece93dd..04e7834c48 100644 --- a/.github/workflows/notebook_controller_m2m_test.yaml +++ b/.github/workflows/notebook_controller_m2m_test.yaml @@ -35,7 +35,7 @@ jobs: run: kustomize build common/kubeflow-namespace/base | kubectl apply -f - - name: Install Istio with ext auth - run: ./tests/gh-actions/install_istio_with_ext_auth.sh* + run: ./tests/gh-actions/install_istio_with_ext_auth.sh - name: Install kubeflow-istio-resources run: kustomize build common/istio-1-21/kubeflow-istio-resources/base | kubectl apply -f - @@ -58,6 +58,10 @@ jobs: nohup kubectl port-forward --namespace istio-system svc/${INGRESS_GATEWAY_SERVICE} 8080:80 & while ! curl localhost:8080; do echo waiting for port-forwarding; sleep 1; done; echo port-forwarding ready + - name: Wait for the kubeflow-m2m-oidc-configurator Job + run: | + ./tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh + - name: List notebooks over API with authorized SA Token run: | KF_PROFILE=kubeflow-user-example-com @@ -86,4 +90,4 @@ jobs: if test $STATUS_CODE -ne 403; then echo "Error, this call should fail to list notebooks in namespace ${KF_PROFILE}." exit 1 - fi \ No newline at end of file + fi diff --git a/tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh b/tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh new file mode 100755 index 0000000000..726ae62fca --- /dev/null +++ b/tests/gh-actions/wait_for_kubeflow_m2m_oidc_configurator.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +CRONJOB_NAME=kubeflow-m2m-oidc-configurator +NAMESPACE=istio-system + +# Function to get the latest Job created by the CronJob +get_latest_job() { + kubectl get jobs -n "${NAMESPACE}" \ + --sort-by=.metadata.creationTimestamp -o json \ + | jq --arg cronjob_name "${CRONJOB_NAME}" -r '.items[] | select(.metadata.ownerReferences[] | select(.name==$cronjob_name)) | .metadata.name' \ + | tail -n 1 +} + +# Wait until a Job is created +echo "Waiting for a Job to be created by the ${CRONJOB_NAME} CronJob..." +while true; do + JOB_NAME=$(get_latest_job) + if [[ -n "${JOB_NAME}" ]]; then + echo "Job ${JOB_NAME} created." + break + fi + sleep 5 + echo "Waiting..." +done + +# Wait for the Job to complete successfully +echo "Waiting for the Job ${JOB_NAME} to complete..." +while true; do + STATUS=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}') + if [[ "${STATUS}" == "True" ]]; then + echo "Job ${JOB_NAME} completed successfully." + break + fi + + FAILED=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.conditions[?(@.type=="Failed")].status}') + if [[ "${FAILED}" == "True" ]]; then + echo "Job ${JOB_NAME} failed." + exit 1 + fi + sleep 5 +done