Skip to content

Commit e636e83

Browse files
Updated the V2 pipeline test to be more robust (#3129)
* Updated the V2 pipeline test to be more robust Signed-off-by: kunal-511 <[email protected]> * Updated the version end to end test Signed-off-by: kunal-511 <[email protected]> * added quotes Signed-off-by: kunal-511 <[email protected]> * Updated the v2 test to make it use simple approach Signed-off-by: kunal-511 <[email protected]> * Updated experiment name Signed-off-by: kunal-511 <[email protected]> * Added some logs and simplified the pipeline Signed-off-by: kunal-511 <[email protected]> * making the pipeline more minimal Signed-off-by: kunal-511 <[email protected]> * removed the logs Signed-off-by: kunal-511 <[email protected]> * Updated test name Signed-off-by: kunal-511 <[email protected]> * Update pipeline_test.yaml Signed-off-by: Julius von Kohout <[email protected]> --------- Signed-off-by: kunal-511 <[email protected]> Signed-off-by: Julius von Kohout <[email protected]> Co-authored-by: Julius von Kohout <[email protected]>
1 parent 48211a4 commit e636e83

File tree

4 files changed

+106
-71
lines changed

4 files changed

+106
-71
lines changed

.github/workflows/full_kubeflow_integration_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ jobs:
122122
run: |
123123
pip3 install -U "kfp>=2.13.0"
124124
TOKEN="$(kubectl -n $KF_PROFILE create token default-editor)"
125-
python3 tests/gh-actions/test_pipeline.py run_pipeline "${TOKEN}" "${KF_PROFILE}"
125+
python3 tests/gh-actions/test_pipeline_v2.py run_pipeline "${TOKEN}" "${KF_PROFILE}"
126126
127127
- name: Test Pipeline Access with Unauthorized Token
128128
run: |
129129
kubectl create namespace test-unauthorized
130130
kubectl create serviceaccount test-unauthorized -n test-unauthorized
131131
UNAUTHORIZED_TOKEN=$(kubectl -n test-unauthorized create token test-unauthorized)
132-
python3 tests/gh-actions/test_pipeline.py test_unauthorized_access "$UNAUTHORIZED_TOKEN" "${KF_PROFILE}"
132+
python3 tests/gh-actions/test_pipeline_v2.py test_unauthorized_access "$UNAUTHORIZED_TOKEN" "${KF_PROFILE}"
133133
134134
- name: Test Volumes Web Application API
135135
run: ./tests/gh-actions/test_volumes_web_application.sh "${KF_PROFILE}"

.github/workflows/pipeline_test.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
- common/cert-manager/**
1212
- common/oauth2-proxy/**
1313
- common/istio*/**
14-
- tests/gh-actions/test_pipeline.py
1514
- tests/gh-actions/test_pipeline_v1.py
15+
- tests/gh-actions/test_pipeline_v2.py
1616
- experimental/security/PSS/*
1717

1818
env:
@@ -64,6 +64,9 @@ jobs:
6464
fi
6565
kubectl get secret mlpipeline-minio-artifact -n "$KF_PROFILE" -o json | jq -r '.data | keys[] as $k | "\($k): \(. | .[$k] | @base64d)"' | tr '\n' ' '
6666
67+
- name: Wait for All Pods to be Ready
68+
run: kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout 60s --field-selector=status.phase!=Succeeded
69+
6770
- name: Port forward
6871
run: ./tests/gh-actions/port_forward_gateway.sh
6972

@@ -75,18 +78,16 @@ jobs:
7578
7679
- name: V2 Pipeline Test
7780
run: |
78-
pip3 install -U kfp==2.13.0
81+
pip3 install "kfp>=2.13.0"
7982
TOKEN="$(kubectl -n $KF_PROFILE create token default-editor)"
80-
python3 tests/gh-actions/test_pipeline.py run_pipeline "${TOKEN}" "${KF_PROFILE}"
83+
python3 tests/gh-actions/test_pipeline_v2.py run_pipeline "${TOKEN}" "${KF_PROFILE}"
8184
82-
- name: Fail to list pipelines with unauthorized ServiceAccount Token
85+
- name: Test unauthorized access
8386
run: |
84-
pip3 install -U kfp==2.13.0
8587
TOKEN="$(kubectl -n default create token default)"
86-
python3 tests/gh-actions/test_pipeline.py test_unauthorized_access "${TOKEN}" "${KF_PROFILE}"
88+
python3 tests/gh-actions/test_pipeline_v2.py test_unauthorized_access "${TOKEN}" "${KF_PROFILE}"
8789
echo "Test succeeded. Token from unauthorized ServiceAccount cannot list pipelines in $KF_PROFILE namespace."
8890
89-
9091
- name: Apply Pod Security Standards baseline levels for static namespaces
9192
run: ./tests/gh-actions/enable_baseline_PSS.sh
9293

tests/gh-actions/test_pipeline.py

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
3+
import kfp
4+
import sys
5+
import time
6+
from kfp import dsl
7+
from kfp_server_api.exceptions import ApiException
8+
9+
10+
@dsl.component
11+
def hello_world_op() -> str:
12+
print("Hello World from Kubeflow Pipelines V2!")
13+
return "Hello World"
14+
15+
16+
@dsl.pipeline(
17+
name="hello-world-v2",
18+
description="A very simple hello world pipeline"
19+
)
20+
def hello_world_pipeline():
21+
hello_world_op()
22+
23+
24+
def run_pipeline(token, namespace):
25+
client = kfp.Client(host="http://localhost:8080/pipeline", existing_token=token)
26+
27+
try:
28+
pipelines = client.list_pipelines()
29+
print(f"Successfully connected to KFP server, found {len(pipelines.pipelines)} pipelines")
30+
31+
experiment = client.create_experiment("v2-pipeline-test", namespace=namespace)
32+
print(f"Created experiment: v2-pipeline-test in namespace {namespace}")
33+
34+
run = client.create_run_from_pipeline_func(
35+
pipeline_func=hello_world_pipeline,
36+
experiment_name="v2-pipeline-test",
37+
run_name="v2-test-run",
38+
arguments={},
39+
namespace=namespace
40+
)
41+
42+
run_id = run.run_id
43+
44+
for _ in range(30):
45+
status = client.get_run(run_id=run_id).state
46+
47+
if status == "SUCCEEDED":
48+
return
49+
elif status not in ["PENDING", "RUNNING"]:
50+
print(f"Pipeline failed with status: {status}")
51+
52+
pods = client._get_k8s_client().list_namespaced_pod(
53+
namespace=namespace,
54+
label_selector=f"pipeline/runid={run_id}"
55+
)
56+
57+
print(f"Found {len(pods.items)} pods for this run")
58+
for pod in pods.items:
59+
print(f"Pod {pod.metadata.name}: {pod.status.phase}")
60+
61+
sys.exit(1)
62+
63+
time.sleep(10)
64+
65+
sys.exit(1)
66+
67+
except Exception as exception:
68+
print(f"Error in pipeline execution: {exception}")
69+
sys.exit(1)
70+
71+
72+
def test_unauthorized_access(token, namespace):
73+
client = kfp.Client(host="http://localhost:8080/pipeline", existing_token=token)
74+
75+
try:
76+
pipeline = client.list_runs(namespace=namespace)
77+
sys.exit(1)
78+
except ApiException as exception:
79+
if exception.status != 403:
80+
sys.exit(1)
81+
82+
83+
if __name__ == "__main__":
84+
if len(sys.argv) < 3:
85+
sys.exit(1)
86+
87+
action = sys.argv[1]
88+
token = sys.argv[2]
89+
namespace = sys.argv[3]
90+
91+
if action == "run_pipeline":
92+
run_pipeline(token, namespace)
93+
elif action == "test_unauthorized_access":
94+
test_unauthorized_access(token, namespace)
95+
else:
96+
sys.exit(1)

0 commit comments

Comments
 (0)