Skip to content

Commit 466cde6

Browse files
authored
fix(sdk): Update custom task arg parsing for dash arguments (kubeflow#1114)
1 parent fb32672 commit 466cde6

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed

sdk/python/kfp_tekton/compiler/compiler.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,12 +1025,18 @@ def map_cel_vars(a):
10251025
container_args = i.get('args', [])
10261026
custom_task_command = {}
10271027
container_command = i.get('command', [])
1028-
for index, item in enumerate(container_args):
1029-
if item.startswith('--'):
1030-
custom_task_args[item[2:]] = container_args[index + 1]
1031-
for index, item in enumerate(container_command):
1032-
if item.startswith('--'):
1033-
custom_task_command[item[2:]] = container_command[index + 1]
1028+
1029+
def find_parameter(arg_list, arg_task_list):
1030+
skip_index = False
1031+
for index, item in enumerate(arg_list):
1032+
if skip_index:
1033+
skip_index = False
1034+
continue
1035+
if item.startswith('--'):
1036+
arg_task_list[item[2:]] = arg_list[index + 1]
1037+
skip_index = True
1038+
find_parameter(container_args, custom_task_args)
1039+
find_parameter(container_command, custom_task_command)
10341040
non_param_keys = ['name', 'apiVersion', 'kind', 'taskSpec', 'taskRef']
10351041
task_params = []
10361042
command_params = []

sdk/python/tests/compiler/compiler_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ def test_custom_task_output_workflow(self):
134134
from .testdata.custom_task_output import uppercase_vs_lowercase
135135
self._test_pipeline_workflow(uppercase_vs_lowercase, 'custom_task_output.yaml', skip_noninlined=True)
136136

137+
def test_custom_task_dash_args_workflow(self):
138+
"""
139+
Test compiling a custom task with dash arguments workflow.
140+
"""
141+
from .testdata.custom_task_dash_args import pipeline_dash_args
142+
self._test_pipeline_workflow(pipeline_dash_args, 'custom_task_dash_args.yaml', skip_noninlined=True)
143+
137144
def test_parallel_join_workflow(self):
138145
"""
139146
Test compiling a parallel join workflow.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2023 kubeflow.org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
from kfp import dsl
17+
from kfp.components import load_component_from_text
18+
19+
20+
@dsl.pipeline()
21+
def pipeline_dash_args():
22+
cel_run_bash_script = load_component_from_text(r"""
23+
name: cel-run-bash-script
24+
inputs: []
25+
outputs:
26+
- {name: env-variables}
27+
implementation:
28+
container:
29+
image: aipipeline/cel-eval:latest
30+
command: [cel]
31+
args: [--apiVersion, custom.tekton.dev/v1alpha1, --kind, VariableStore, --name,
32+
1234567-var-store, --lit_0, '---', --taskSpec,
33+
'{}']
34+
fileOutputs: {}
35+
""")()
36+
37+
cel_run_bash_script.add_pod_annotation("valid_container", "false")
38+
39+
40+
if __name__ == '__main__':
41+
from kfp_tekton.compiler import TektonCompiler as Compiler
42+
from kfp_tekton.compiler.pipeline_utils import TektonPipelineConf
43+
tekton_pipeline_conf = TektonPipelineConf()
44+
tekton_pipeline_conf.set_tekton_inline_spec(True)
45+
Compiler().compile(pipeline_dash_args, __file__.replace('.py', '.yaml'), tekton_pipeline_conf=tekton_pipeline_conf, type_check=False)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2021 kubeflow.org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: tekton.dev/v1beta1
16+
kind: PipelineRun
17+
metadata:
18+
name: pipeline-dash-args
19+
annotations:
20+
tekton.dev/output_artifacts: '{}'
21+
tekton.dev/input_artifacts: '{}'
22+
tekton.dev/artifact_bucket: mlpipeline
23+
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
24+
tekton.dev/artifact_endpoint_scheme: http://
25+
tekton.dev/artifact_items: '{}'
26+
sidecar.istio.io/inject: "false"
27+
tekton.dev/template: ''
28+
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME
29+
pipelines.kubeflow.org/pipeline_spec: '{"name": "Pipeline dash args"}'
30+
labels:
31+
pipelines.kubeflow.org/pipelinename: ''
32+
pipelines.kubeflow.org/generation: ''
33+
spec:
34+
pipelineSpec:
35+
tasks:
36+
- name: cel-run-bash-script
37+
params:
38+
- name: lit_0
39+
value: '---'
40+
taskSpec:
41+
apiVersion: custom.tekton.dev/v1alpha1
42+
kind: VariableStore
43+
spec: {}
44+
metadata:
45+
labels:
46+
pipelines.kubeflow.org/cache_enabled: "true"
47+
annotations:
48+
valid_container: "false"
49+
pipelines.kubeflow.org/component_spec_digest: '{"name": "cel-run-bash-script",
50+
"outputs": [{"name": "env-variables"}], "version": "cel-run-bash-script@sha256=ea3b98e707ecd49f3cd88c4abde7b9dedc0154dd4c1b10a3a3feff3b85fd82ad"}'

0 commit comments

Comments
 (0)