Skip to content

Commit

Permalink
remove ContainerOp from test cases - part 3
Browse files Browse the repository at this point in the history
eliminate the usage of ContainerOp in testcases and
update the testcase accordingly, including filenames starting
with `o` to `u`

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
  • Loading branch information
yhwang committed Aug 9, 2021
1 parent 37d0021 commit 4a8c3aa
Show file tree
Hide file tree
Showing 58 changed files with 1,362 additions and 635 deletions.
55 changes: 40 additions & 15 deletions sdk/python/tests/compiler/testdata/opsgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,54 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import kfp.dsl as dsl
from kfp import dsl, components


@dsl.graph_component
def echo1_graph_component(text1):
dsl.ContainerOp(
name='echo1-task1',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo "$0"', text1])
def echo1_graph_component(text1: str):
components.load_component_from_text("""
name: echo1-task1
description: echo task
inputs:
- {name: text, type: String}
implementation:
container:
image: library/bash:4.4.23
command:
- sh
- -c
args:
- echo
- {inputValue: text}
""")(text=text1)


@dsl.graph_component
def echo2_graph_component(text2):
dsl.ContainerOp(
name='echo2-task1',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo "$0"', text2])
def echo2_graph_component(text2: str):
components.load_component_from_text("""
name: echo2-task1
description: echo task
inputs:
- {name: text, type: String}
implementation:
container:
image: library/bash:4.4.23
command:
- sh
- -c
args:
- echo
- {inputValue: text}
""")(text=text2)


@dsl.pipeline()
def opsgroups_pipeline(text1='message 1', text2='message 2'):
@dsl.pipeline(name='opsgroups-pipeline')
def opsgroups_pipeline(text1: str = 'message 1', text2: str = 'message 2'):
step1_graph_component = echo1_graph_component(text1)
step2_graph_component = echo2_graph_component(text2)
step2_graph_component.after(step1_graph_component)


if __name__ == '__main__':
from kfp_tekton.compiler import TektonCompiler
TektonCompiler().compile(opsgroups_pipeline, __file__.replace('.py', '.yaml'))
129 changes: 103 additions & 26 deletions sdk/python/tests/compiler/testdata/opsgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,116 @@ metadata:
tekton.dev/artifact_items: '{"echo1-task1": [], "echo2-task1": []}'
sidecar.istio.io/inject: "false"
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "message 1", "name":
"text1", "optional": true}, {"default": "message 2", "name": "text2", "optional":
true}], "name": "Opsgroups pipeline"}'
"text1", "optional": true, "type": "String"}, {"default": "message 2", "name":
"text2", "optional": true, "type": "String"}], "name": "opsgroups-pipeline"}'
spec:
params:
- {name: text1, value: message 1}
- {name: text2, value: message 2}
- name: text1
value: message 1
- name: text2
value: message 2
pipelineSpec:
params:
- {name: text1, default: message 1}
- {name: text2, default: message 2}
- name: text1
default: message 1
- name: text2
default: message 2
tasks:
- name: echo1-task1
- name: opsgroups-pipeline-4f58a-raph-component-1
params:
- {name: text1, value: $(params.text1)}
- name: just_one_iteration
value:
- '1'
- name: text1
value: $(params.text1)
taskSpec:
steps:
- name: main
args: [echo "$0", $(inputs.params.text1)]
command: [sh, -c]
image: library/bash:4.4.23
params:
- {name: text1}
timeout: 0s
- name: echo2-task1
apiVersion: custom.tekton.dev/v1alpha1
kind: PipelineLoop
spec:
pipelineSpec:
params:
- name: just_one_iteration
type: string
- name: text1
type: string
tasks:
- name: echo1-task1
params:
- name: text1
value: $(params.text1)
taskSpec:
steps:
- name: main
args:
- echo
- $(inputs.params.text1)
command:
- sh
- -c
image: library/bash:4.4.23
params:
- name: text1
type: string
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
pipelines.kubeflow.org/component_spec: '{"description": "echo
task", "implementation": {"container": {"args": ["echo", {"inputValue":
"text"}], "command": ["sh", "-c"], "image": "library/bash:4.4.23"}},
"inputs": [{"name": "text", "type": "String"}], "name": "echo1-task1"}'
tekton.dev/template: ''
timeout: 0s
iterateParam: just_one_iteration
- runAfter: []
name: opsgroups-pipeline-4f58a-raph-component-2
params:
- {name: text2, value: $(params.text2)}
- name: just_one_iteration
value:
- '1'
- name: text2
value: $(params.text2)
taskSpec:
steps:
- name: main
args: [echo "$0", $(inputs.params.text2)]
command: [sh, -c]
image: library/bash:4.4.23
params:
- {name: text2}
timeout: 0s
apiVersion: custom.tekton.dev/v1alpha1
kind: PipelineLoop
spec:
pipelineSpec:
params:
- name: just_one_iteration
type: string
- name: text2
type: string
tasks:
- name: echo2-task1
params:
- name: text2
value: $(params.text2)
taskSpec:
steps:
- name: main
args:
- echo
- $(inputs.params.text2)
command:
- sh
- -c
image: library/bash:4.4.23
params:
- name: text2
type: string
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
pipelines.kubeflow.org/component_spec: '{"description": "echo
task", "implementation": {"container": {"args": ["echo", {"inputValue":
"text"}], "command": ["sh", "-c"], "image": "library/bash:4.4.23"}},
"inputs": [{"name": "text", "type": "String"}], "name": "echo2-task1"}'
tekton.dev/template: ''
timeout: 0s
iterateParam: just_one_iteration
timeout: 0s
64 changes: 43 additions & 21 deletions sdk/python/tests/compiler/testdata/parallel_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,59 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from kfp import dsl
from kfp import dsl, components


def gcs_download_op(url):
return dsl.ContainerOp(
name='GCS - Download',
image='google/cloud-sdk:279.0.0',
command=['sh', '-c'],
arguments=['gsutil cat $0 | tee $1', url, '/tmp/results.txt'],
file_outputs={
'data': '/tmp/results.txt',
}
)
def gcs_download_op(url: str):
return components.load_component_from_text("""
name: gcs-download
description: GCS - Download
inputs:
- {name: url, type: String}
outputs:
- {name: data, type: String}
implementation:
container:
image: google/cloud-sdk:279.0.0
command:
- sh
- -c
args:
- |
gsutil cat $0 | tee $1
- {inputValue: url}
- {outputPath: data}
""")(url=url)


def echo2_op(text1, text2):
return dsl.ContainerOp(
name='echo',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo "Text 1: $0"; echo "Text 2: $1"', text1, text2]
)
def echo2_op(text1: str, text2: str):
return components.load_component_from_text("""
name: echo
description: echo
inputs:
- {name: input1, type: String}
- {name: input2, type: String}
implementation:
container:
image: library/bash:4.4.23
command:
- sh
- -c
args:
- |
echo "Text 1: $0"; echo "Text 2: $1"
- {inputValue: input1}
- {inputValue: input2}
""")(input1=text1, input2=text2)


@dsl.pipeline(
name='Parallel pipeline',
name='parallel-pipeline',
description='Download two messages in parallel and prints the concatenated result.'
)
def download_and_join(
url1='gs://ml-pipeline-playground/shakespeare1.txt',
url2='gs://ml-pipeline-playground/shakespeare2.txt'
url1: str = 'gs://ml-pipeline-playground/shakespeare1.txt',
url2: str = 'gs://ml-pipeline-playground/shakespeare2.txt'
):
"""A three-step pipeline with the first two steps running in parallel."""

Expand Down
Loading

0 comments on commit 4a8c3aa

Please sign in to comment.