forked from opendatahub-io/data-science-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(sdk): Add custom task definition support (kubeflow#526)
* add custom task template support * fix typo * fix lint * update cel example to use official custom task * add troubleshooting for example
- Loading branch information
Showing
10 changed files
with
353 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Using Tekton Custom Task on KFP | ||
|
||
This example shows how to define any Tekton Custom Task on KFP-Tekton and handle the custom task inputs and outputs. | ||
|
||
## prerequisites | ||
- Install [KFP Tekton prerequisites](/samples/README.md) | ||
|
||
## Instructions | ||
1. Install the Condtion custom task controller for computing runtime conditions for this example. Make sure to setup GOPATH and [ko](https://github.com/google/ko) before running the commands below. | ||
```shell | ||
git clone https://github.com/tektoncd/experimental/ | ||
cd experimental/cel | ||
ko apply -f config/ | ||
``` | ||
|
||
2. Compile the flip-coin pipeline using the compiler inside the python code. The kfp-tekton SDK will produce a Tekton pipeline yaml definition in the same directory called `tekton-custom-task.yaml`. | ||
``` | ||
# Compile the python code | ||
python tekton-custom-task.py | ||
``` | ||
Then, upload the `tekton-custom-task.yaml` file to the Kubeflow pipeline dashboard with Tekton Backend to run this pipeline. | ||
## Troubleshooting | ||
Make sure the Tekton deployment enabled custom task as instructed in the KFP-Tekton deployment. | ||
```shell | ||
kubectl patch cm feature-flags -n tekton-pipelines \ | ||
-p '{"data":{"disable-home-env-overwrite":"true","disable-working-directory-overwrite":"true", "enable-custom-tasks": "true"}}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2021 kubeflow.org | ||
# | ||
# 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 kfp | ||
from kfp import dsl | ||
from kfp_tekton.tekton import CEL_ConditionOp | ||
|
||
|
||
def flip_coin_op(): | ||
"""Flip a coin and output heads or tails randomly.""" | ||
return dsl.ContainerOp( | ||
name='Flip coin', | ||
image='python:alpine3.6', | ||
command=['sh', '-c'], | ||
arguments=['python -c "import random; result = \'heads\' if random.randint(0,1) == 0 ' | ||
'else \'tails\'; print(result)" | tee /tmp/output'], | ||
file_outputs={'output': '/tmp/output'} | ||
) | ||
|
||
|
||
def print_op(msg): | ||
"""Print a message.""" | ||
return dsl.ContainerOp( | ||
name='Print', | ||
image='alpine:3.6', | ||
command=['echo', msg], | ||
) | ||
|
||
|
||
@dsl.pipeline( | ||
name='Tekton custom task on Kubeflow Pipeline', | ||
description='Shows how to use Tekton custom task with KFP' | ||
) | ||
def custom_task_pipeline(): | ||
flip = flip_coin_op() | ||
cel_condition = CEL_ConditionOp("'%s' == 'heads'" % flip.output) | ||
print_op('Condition output is %s' % cel_condition.output) | ||
|
||
|
||
if __name__ == '__main__': | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(custom_task_pipeline, __file__.replace('.py', '.yaml')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.