Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Moved kubeflow-pipelines-samples-v2 to GitHub Actions #11048

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/kfp-samples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: KFP Samples

on:
push:
branches:
- master
pull_request:
paths:
- 'samples/**'
- 'backend/src/v2/**'
- '.github/workflows/kfp-samples.yml'

jobs:
samples:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Create KFP cluster
uses: ./.github/actions/kfp-cluster

- name: Forward API port
run: ./scripts/deploy/github/forward-port.sh "kubeflow" "ml-pipeline" 8888 8888

- name: Run Samples Tests
run: |
./backend/src/v2/test/sample-test.sh
15 changes: 0 additions & 15 deletions backend/src/v2/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ ENV_PATH?=.env
include $(ENV_PATH)
SHELL = /bin/bash

.PHONY: all
all: sample-test

.PHONY: sample-test
sample-test: upload
# The -u flag makes python output unbuffered, so that we can see real time log.
# Reference: https://stackoverflow.com/a/107717
export KF_PIPELINES_ENDPOINT=$(HOST) \
&& python -u sample_test.py \
--samples_config samples/test/config.yaml \
--context $(GCS_ROOT)/src/context.tar.gz \
--gcs_root $(GCS_ROOT)/data \
--gcr_root $(GCR_ROOT) \
--kfp_package_path "$(KFP_PACKAGE_PATH)"

.PHONY: integration-test
integration-test: upload
export KF_PIPELINES_ENDPOINT=$(HOST) \
Expand Down
2 changes: 2 additions & 0 deletions backend/src/v2/test/requirements-sample-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../../../../sdk/python
kfp[kubernetes]
16 changes: 6 additions & 10 deletions backend/src/v2/test/sample-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
# limitations under the License.

set -ex
source_root=$(pwd)

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)"
cd "${DIR}"
source "${DIR}/scripts/ci-env.sh"
pushd ./backend/src/v2/test

# Install required packages from commit
python3 -m pip install --upgrade pip
python3 -m pip install -r ./requirements-sample-test.txt

# TODO: remove deprecated dependency
python3 -m pip install -r $source_root/sdk/python/requirements-deprecated.txt
python3 -m pip install $source_root/sdk/python
popd

# Run sample test
ENV_PATH=kfp-ci.env make
# The -u flag makes python output unbuffered, so that we can see real time log.
# Reference: https://stackoverflow.com/a/107717
python3 -u ./samples/v2/sample_test.py
164 changes: 0 additions & 164 deletions backend/src/v2/test/sample_test.py

This file was deleted.

83 changes: 83 additions & 0 deletions samples/v2/sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2024 The Kubeflow Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import unittest
from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass
from pprint import pprint
from typing import List

import kfp
from kfp.dsl.graph_component import GraphComponent
import component_with_optional_inputs
import pipeline_with_env
import hello_world
import producer_consumer_param
import pipeline_container_no_input
import two_step_pipeline_containerized

_MINUTE = 60 # seconds
_DEFAULT_TIMEOUT = 5 * _MINUTE


@dataclass
class TestCase:
pipeline_func: GraphComponent
timeout: int = _DEFAULT_TIMEOUT


class SampleTest(unittest.TestCase):
_kfp_host_and_port = os.getenv('KFP_API_HOST_AND_PORT', 'http://localhost:8888')
_kfp_ui_and_port = os.getenv('KFP_UI_HOST_AND_PORT', 'http://localhost:8080')
_client = kfp.Client(host=_kfp_host_and_port, ui_host=_kfp_ui_and_port)

def test(self):
test_cases: List[TestCase] = [
TestCase(pipeline_func=hello_world.pipeline_hello_world),
TestCase(pipeline_func=producer_consumer_param.producer_consumer_param_pipeline),
TestCase(pipeline_func=pipeline_container_no_input.pipeline_container_no_input),
TestCase(pipeline_func=two_step_pipeline_containerized.two_step_pipeline_containerized),
TestCase(pipeline_func=component_with_optional_inputs.pipeline),
TestCase(pipeline_func=pipeline_with_env.pipeline_with_env),

# The following tests are not working. Tracking issue: https://github.com/kubeflow/pipelines/issues/11053
# TestCase(pipeline_func=pipeline_with_importer.pipeline_with_importer),
# TestCase(pipeline_func=pipeline_with_volume.pipeline_with_volume),
# TestCase(pipeline_func=pipeline_with_secret_as_volume.pipeline_secret_volume),
# TestCase(pipeline_func=pipeline_with_secret_as_env.pipeline_secret_env),
]

with ThreadPoolExecutor() as executor:
futures = [
executor.submit(self.run_test_case, test_case.pipeline_func, test_case.timeout)
for test_case in test_cases
]
for future in as_completed(futures):
future.result()

def run_test_case(self, pipeline_func: GraphComponent, timeout: int):
with self.subTest(pipeline=pipeline_func, msg=pipeline_func.name):
run_result = self._client.create_run_from_pipeline_func(pipeline_func=pipeline_func)

run_response = run_result.wait_for_run_completion(timeout)

pprint(run_response.run_details)
print("Run details page URL:")
print(f"{self._kfp_ui_and_port}/#/runs/details/{run_response.run_id}")

self.assertEqual(run_response.state, "SUCCEEDED")


if __name__ == '__main__':
unittest.main()
Loading