Skip to content

Commit a7f2b04

Browse files
authored
fix(sdk): Fix inline spec for iterateParamPassStyle and itemPassStyle (kubeflow#1087)
* cheerypick(sdk): Fix counter param cherrypick (kubeflow#1080) (kubeflow#1082) * fix nested loop counter param bug * Update _tekton_handler.py * fix inline spec for new features * Update _tekton_handler.py
1 parent 1a70d22 commit a7f2b04

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

sdk/python/kfp_tekton/compiler/_tekton_handler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,15 @@ def _handle_tekton_custom_task(custom_task: dict, workflow: dict, recursive_task
244244

245245
# add loop special fields
246246
custom_task_cr['kind'] = 'PipelineLoop'
247-
if custom_task[custom_task_key]['spec'].get('parallelism') is not None:
248-
custom_task_cr['spec']['parallelism'] = custom_task[custom_task_key]['spec']['parallelism']
249-
# remove from pipeline run spec
250-
del custom_task[custom_task_key]['spec']['parallelism']
247+
248+
def process_inline_cr_field(field_name):
249+
if custom_task[custom_task_key]['spec'].get(field_name) is not None:
250+
custom_task_cr['spec'][field_name] = custom_task[custom_task_key]['spec'][field_name]
251+
# remove from pipeline run spec
252+
del custom_task[custom_task_key]['spec'][field_name]
253+
process_fields = ['parallelism', 'iterateParamPassStyle', 'itemPassStyle']
254+
for process_field in process_fields:
255+
process_inline_cr_field(process_field)
251256
if custom_task[custom_task_key].get('iteration_number') is not None:
252257
# enumerate() is used, TektonLoopIterationNumber is injected, get its name and remove it from params
253258
custom_task_cr['spec']['iterationNumberParam'] = custom_task[custom_task_key]['iteration_number']

sdk/python/tests/compiler/testdata/loop_with_numeric.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ spec:
5858
value: $(params.my_pipe_param)
5959
- name: to
6060
value: $(params.end)
61-
iterateParamPassStyle: inline
6261
taskSpec:
6362
apiVersion: custom.tekton.dev/v1alpha1
6463
kind: PipelineLoop
@@ -108,7 +107,6 @@ spec:
108107
value: $(params.my_pipe_param)
109108
- name: to
110109
value: '2'
111-
itemPassStyle: file
112110
taskSpec:
113111
apiVersion: custom.tekton.dev/v1alpha1
114112
kind: PipelineLoop
@@ -150,10 +148,12 @@ spec:
150148
annotations:
151149
pipelines.kubeflow.org/component_spec_digest: '{"name":
152150
"my-in-coop1", "outputs": [], "version": "my-in-coop1@sha256=42f0c6a60c7e435441b8afaeb382a771a9741fe3aabb203748fdbd72b25f1628"}'
151+
itemPassStyle: file
153152
iterateNumeric: loop-item-param-3
154153
metadata:
155154
labels:
156155
pipelines.kubeflow.org/cache_enabled: "true"
156+
iterateParamPassStyle: inline
157157
iterateNumeric: loop-item-param-1
158158
metadata:
159159
labels:

sdk/python/tests/compiler/testdata/loop_with_numeric_noninlined.yaml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ metadata:
3232
"type": "Integer"}], "name": "my-pipeline"}'
3333
tekton.dev/resource_templates: '[{"apiVersion": "custom.tekton.dev/v1alpha1",
3434
"kind": "PipelineLoop", "metadata": {"name": "my-pipeline-for-loop-2"}, "spec":
35-
{"iterateNumeric": "loop-item-param-1", "pipelineSpec": {"params": [{"name":
36-
"loop-item-param-1", "type": "string"}, {"name": "my_pipe_param", "type": "string"}],
37-
"tasks": [{"name": "my-in-coop1", "params": [{"name": "loop-item-param-1", "value":
38-
"$(params.loop-item-param-1)"}, {"name": "my_pipe_param", "value": "$(params.my_pipe_param)"}],
39-
"taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest":
35+
{"iterateNumeric": "loop-item-param-1", "iterateParamPassStyle": "inline", "pipelineSpec":
36+
{"params": [{"name": "loop-item-param-1", "type": "string"}, {"name": "my_pipe_param",
37+
"type": "string"}], "tasks": [{"name": "my-in-coop1", "params": [{"name": "loop-item-param-1",
38+
"value": "$(params.loop-item-param-1)"}, {"name": "my_pipe_param", "value":
39+
"$(params.my_pipe_param)"}], "taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest":
4040
"{\"name\": \"my-in-coop1\", \"outputs\": [], \"version\": \"my-in-coop1@sha256=42f0c6a60c7e435441b8afaeb382a771a9741fe3aabb203748fdbd72b25f1628\"}"},
4141
"labels": {"pipelines.kubeflow.org/cache_enabled": "true"}}, "params": [{"name":
4242
"loop-item-param-1", "type": "string"}, {"name": "my_pipe_param", "type": "string"}],
4343
"steps": [{"args": ["set -e\necho op1 \"$0\" \"$1\"\n", "$(inputs.params.loop-item-param-1)",
4444
"$(inputs.params.my_pipe_param)"], "command": ["sh", "-c"], "image": "library/bash:4.4.23",
45-
"name": "main"}]}}, {"itemPassStyle": "file", "name": "my-pipeline-for-loop-4",
46-
"params": [{"name": "from", "value": "1"}, {"name": "my_pipe_param", "value":
47-
"$(params.my_pipe_param)"}, {"name": "to", "value": "2"}], "taskRef": {"apiVersion":
48-
"custom.tekton.dev/v1alpha1", "kind": "PipelineLoop", "name": "my-pipeline-for-loop-4"}}]}}},
49-
{"apiVersion": "custom.tekton.dev/v1alpha1", "kind": "PipelineLoop", "metadata":
50-
{"name": "my-pipeline-for-loop-4"}, "spec": {"iterateNumeric": "loop-item-param-3",
51-
"pipelineSpec": {"params": [{"name": "loop-item-param-3", "type": "string"},
52-
{"name": "my_pipe_param", "type": "string"}], "tasks": [{"name": "my-in-coop1-2",
53-
"params": [{"name": "loop-item-param-3", "value": "$(params.loop-item-param-3)"},
54-
{"name": "my_pipe_param", "value": "$(params.my_pipe_param)"}], "taskSpec":
55-
{"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest":
56-
"{\"name\": \"my-in-coop1\", \"outputs\": [], \"version\": \"my-in-coop1@sha256=42f0c6a60c7e435441b8afaeb382a771a9741fe3aabb203748fdbd72b25f1628\"}"},
45+
"name": "main"}]}}, {"name": "my-pipeline-for-loop-4", "params": [{"name": "from",
46+
"value": "1"}, {"name": "my_pipe_param", "value": "$(params.my_pipe_param)"},
47+
{"name": "to", "value": "2"}], "taskRef": {"apiVersion": "custom.tekton.dev/v1alpha1",
48+
"kind": "PipelineLoop", "name": "my-pipeline-for-loop-4"}}]}}}, {"apiVersion":
49+
"custom.tekton.dev/v1alpha1", "kind": "PipelineLoop", "metadata": {"name": "my-pipeline-for-loop-4"},
50+
"spec": {"itemPassStyle": "file", "iterateNumeric": "loop-item-param-3", "pipelineSpec":
51+
{"params": [{"name": "loop-item-param-3", "type": "string"}, {"name": "my_pipe_param",
52+
"type": "string"}], "tasks": [{"name": "my-in-coop1-2", "params": [{"name":
53+
"loop-item-param-3", "value": "$(params.loop-item-param-3)"}, {"name": "my_pipe_param",
54+
"value": "$(params.my_pipe_param)"}], "taskSpec": {"metadata": {"annotations":
55+
{"pipelines.kubeflow.org/component_spec_digest": "{\"name\": \"my-in-coop1\",
56+
\"outputs\": [], \"version\": \"my-in-coop1@sha256=42f0c6a60c7e435441b8afaeb382a771a9741fe3aabb203748fdbd72b25f1628\"}"},
5757
"labels": {"pipelines.kubeflow.org/cache_enabled": "true"}}, "params": [{"name":
5858
"loop-item-param-3", "type": "string"}, {"name": "my_pipe_param", "type": "string"}],
5959
"steps": [{"args": ["set -e\necho op1 \"$0\" \"$1\"\n", "$(inputs.params.loop-item-param-3)",
@@ -91,4 +91,3 @@ spec:
9191
value: $(params.my_pipe_param)
9292
- name: to
9393
value: $(params.end)
94-
iterateParamPassStyle: inline

0 commit comments

Comments
 (0)