-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add tekton loop dsl extension skeleton #799
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,57 @@ | ||
# 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.dsl as dsl | ||
from kfp import components | ||
from kfp_tekton import tekton | ||
|
||
op1_yaml = '''\ | ||
name: 'my-in-coop1' | ||
inputs: | ||
- {name: item, type: Integer} | ||
- {name: my_pipe_param, type: Integer} | ||
implementation: | ||
container: | ||
image: library/bash:4.4.23 | ||
command: ['sh', '-c'] | ||
args: | ||
- | | ||
set -e | ||
echo op1 "$0" "$1" | ||
- {inputValue: item} | ||
- {inputValue: my_pipe_param} | ||
''' | ||
|
||
|
||
@dsl.pipeline(name='my-pipeline') | ||
def pipeline(my_pipe_param: int = 10): | ||
loop_args = [1, 2] | ||
# The DSL above should produce the same result and the DSL in the bottom | ||
# with dsl.ParallelFor(loop_args, parallelism=1) as item: | ||
# op1_template = components.load_component_from_text(op1_yaml) | ||
# op1 = op1_template(item, my_pipe_param) | ||
# condi_1 = tekton.CEL_ConditionOp(f"{item} == 0").output | ||
# with dsl.Condition(condi_1 == 'true'): | ||
# tekton.Break() | ||
with tekton.Loop.sequential(loop_args) as item: | ||
op1_template = components.load_component_from_text(op1_yaml) | ||
op1 = op1_template(item, my_pipe_param) | ||
condi_1 = tekton.CEL_ConditionOp(f"{item} == 1").output | ||
with dsl.Condition(condi_1 == 'true'): | ||
tekton.Break() | ||
|
||
|
||
if __name__ == '__main__': | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(pipeline, __file__.replace('.py', '.yaml')) |
135 changes: 135 additions & 0 deletions
135
sdk/python/tests/compiler/testdata/tekton_loop_dsl.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# 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. | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: my-pipeline | ||
annotations: | ||
tekton.dev/output_artifacts: '{}' | ||
tekton.dev/input_artifacts: '{}' | ||
tekton.dev/artifact_bucket: mlpipeline | ||
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000 | ||
tekton.dev/artifact_endpoint_scheme: http:// | ||
tekton.dev/artifact_items: '{"my-in-coop1": [], "pipelineloop-break-operation": | ||
[]}' | ||
sidecar.istio.io/inject: "false" | ||
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME | ||
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "10", "name": "my_pipe_param", | ||
"optional": true, "type": "Integer"}], "name": "my-pipeline"}' | ||
spec: | ||
params: | ||
- name: my_pipe_param | ||
value: '10' | ||
pipelineSpec: | ||
params: | ||
- name: my_pipe_param | ||
default: '10' | ||
tasks: | ||
- name: my-pipeline-for-loop-2 | ||
params: | ||
- name: loop-item-param-1 | ||
value: '[1, 2]' | ||
- name: my_pipe_param | ||
value: $(params.my_pipe_param) | ||
taskSpec: | ||
apiVersion: custom.tekton.dev/v1alpha1 | ||
kind: PipelineLoop | ||
spec: | ||
pipelineSpec: | ||
params: | ||
- name: loop-item-param-1 | ||
type: string | ||
- name: my_pipe_param | ||
type: string | ||
tasks: | ||
- name: my-in-coop1 | ||
params: | ||
- name: loop-item-param-1 | ||
value: $(params.loop-item-param-1) | ||
- name: my_pipe_param | ||
value: $(params.my_pipe_param) | ||
taskSpec: | ||
steps: | ||
- name: main | ||
args: | ||
- | | ||
set -e | ||
echo op1 "$0" "$1" | ||
- $(inputs.params.loop-item-param-1) | ||
- $(inputs.params.my_pipe_param) | ||
command: | ||
- sh | ||
- -c | ||
image: library/bash:4.4.23 | ||
params: | ||
- name: loop-item-param-1 | ||
type: string | ||
- name: my_pipe_param | ||
type: string | ||
metadata: | ||
labels: | ||
pipelines.kubeflow.org/pipelinename: '' | ||
pipelines.kubeflow.org/generation: '' | ||
pipelines.kubeflow.org/cache_enabled: "true" | ||
annotations: | ||
pipelines.kubeflow.org/component_spec: '{"implementation": {"container": | ||
{"args": ["set -e\necho op1 \"$0\" \"$1\"\n", {"inputValue": | ||
"item"}, {"inputValue": "my_pipe_param"}], "command": ["sh", | ||
"-c"], "image": "library/bash:4.4.23"}}, "inputs": [{"name": | ||
"item", "type": "Integer"}, {"name": "my_pipe_param", "type": | ||
"Integer"}], "name": "my-in-coop1"}' | ||
tekton.dev/template: '' | ||
timeout: 525600m | ||
- name: condition-cel | ||
params: | ||
- name: outcome | ||
value: $(params.loop-item-param-1) == 1 | ||
taskRef: | ||
name: cel_condition | ||
apiVersion: cel.tekton.dev/v1alpha1 | ||
kind: CEL | ||
timeout: 525600m | ||
- name: pipelineloop-break-operation | ||
taskSpec: | ||
steps: | ||
- name: main | ||
args: | ||
- break loop | ||
command: | ||
- sh | ||
- -c | ||
- | | ||
echo "$0" | ||
image: busybox | ||
metadata: | ||
labels: | ||
pipelines.kubeflow.org/pipelinename: '' | ||
pipelines.kubeflow.org/generation: '' | ||
pipelines.kubeflow.org/cache_enabled: "true" | ||
annotations: | ||
pipelines.kubeflow.org/component_spec: '{"description": "Break | ||
Operation using PipelineLoop", "implementation": {"container": | ||
{"args": ["break loop"], "command": ["sh", "-c", "echo \"$0\"\n"], | ||
"image": "busybox"}}, "name": "pipelineloop-break-operation"}' | ||
tekton.dev/template: '' | ||
when: | ||
- input: $(tasks.condition-cel.results.outcome) | ||
operator: in | ||
values: | ||
- "true" | ||
timeout: 525600m | ||
parallelism: 1 | ||
iterateParam: loop-item-param-1 | ||
timeout: 525600m |
79 changes: 79 additions & 0 deletions
79
sdk/python/tests/compiler/testdata/tekton_loop_dsl_noninlined.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 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. | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: my-pipeline | ||
annotations: | ||
tekton.dev/output_artifacts: '{}' | ||
tekton.dev/input_artifacts: '{}' | ||
tekton.dev/artifact_bucket: mlpipeline | ||
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000 | ||
tekton.dev/artifact_endpoint_scheme: http:// | ||
tekton.dev/artifact_items: '{"my-in-coop1": [], "pipelineloop-break-operation": | ||
[]}' | ||
sidecar.istio.io/inject: "false" | ||
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME | ||
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "10", "name": "my_pipe_param", | ||
"optional": true, "type": "Integer"}], "name": "my-pipeline"}' | ||
tekton.dev/resource_templates: '[{"apiVersion": "custom.tekton.dev/v1alpha1", | ||
"kind": "PipelineLoop", "metadata": {"name": "my-pipeline-for-loop-2"}, "spec": | ||
{"iterateParam": "loop-item-param-1", "parallelism": 1, "pipelineSpec": {"params": | ||
[{"name": "loop-item-param-1", "type": "string"}, {"name": "my_pipe_param", | ||
"type": "string"}], "tasks": [{"name": "my-in-coop1", "params": [{"name": "loop-item-param-1", | ||
"value": "$(params.loop-item-param-1)"}, {"name": "my_pipe_param", "value": | ||
"$(params.my_pipe_param)"}], "taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec": | ||
"{\"implementation\": {\"container\": {\"args\": [\"set -e\\necho op1 \\\"$0\\\" | ||
\\\"$1\\\"\\n\", {\"inputValue\": \"item\"}, {\"inputValue\": \"my_pipe_param\"}], | ||
\"command\": [\"sh\", \"-c\"], \"image\": \"library/bash:4.4.23\"}}, \"inputs\": | ||
[{\"name\": \"item\", \"type\": \"Integer\"}, {\"name\": \"my_pipe_param\", | ||
\"type\": \"Integer\"}], \"name\": \"my-in-coop1\"}", "tekton.dev/template": | ||
""}, "labels": {"pipelines.kubeflow.org/cache_enabled": "true", "pipelines.kubeflow.org/generation": | ||
"", "pipelines.kubeflow.org/pipelinename": ""}}, "params": [{"name": "loop-item-param-1", | ||
"type": "string"}, {"name": "my_pipe_param", "type": "string"}], "steps": [{"args": | ||
["set -e\necho op1 \"$0\" \"$1\"\n", "$(inputs.params.loop-item-param-1)", "$(inputs.params.my_pipe_param)"], | ||
"command": ["sh", "-c"], "image": "library/bash:4.4.23", "name": "main"}]}, | ||
"timeout": "525600m"}, {"name": "condition-cel", "params": [{"name": "outcome", | ||
"value": "$(params.loop-item-param-1) == 1"}], "taskRef": {"apiVersion": "cel.tekton.dev/v1alpha1", | ||
"kind": "CEL", "name": "cel_condition"}, "timeout": "525600m"}, {"name": "pipelineloop-break-operation", | ||
"taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec": | ||
"{\"description\": \"Break Operation using PipelineLoop\", \"implementation\": | ||
{\"container\": {\"args\": [\"break loop\"], \"command\": [\"sh\", \"-c\", \"echo | ||
\\\"$0\\\"\\n\"], \"image\": \"busybox\"}}, \"name\": \"pipelineloop-break-operation\"}", | ||
"tekton.dev/template": ""}, "labels": {"pipelines.kubeflow.org/cache_enabled": | ||
"true", "pipelines.kubeflow.org/generation": "", "pipelines.kubeflow.org/pipelinename": | ||
""}}, "steps": [{"args": ["break loop"], "command": ["sh", "-c", "echo \"$0\"\n"], | ||
"image": "busybox", "name": "main"}]}, "timeout": "525600m", "when": [{"input": | ||
"$(tasks.condition-cel.results.outcome)", "operator": "in", "values": ["true"]}]}]}}}]' | ||
spec: | ||
params: | ||
- name: my_pipe_param | ||
value: '10' | ||
pipelineSpec: | ||
params: | ||
- name: my_pipe_param | ||
default: '10' | ||
tasks: | ||
- name: my-pipeline-for-loop-2 | ||
taskRef: | ||
apiVersion: custom.tekton.dev/v1alpha1 | ||
kind: PipelineLoop | ||
name: my-pipeline-for-loop-2 | ||
params: | ||
- name: loop-item-param-1 | ||
value: '[1, 2]' | ||
- name: my_pipe_param | ||
value: $(params.my_pipe_param) | ||
timeout: 525600m |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I did not follow how the break happens here. Seems it's just a normal task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pugangxa I think it's related to issue #800.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, right now the pipeline loop break only works when the
last-loop-task
is skipped. However, the proposedBreak()
DSL is to break when the condition is met. So I opened #800 to add a new break features to break when theBreak()
task is being executed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I just overlooked that issue. Then it makes sense. Thanks for all your explanation.