Skip to content

Commit 96e573e

Browse files
authored
fix(sdk): update loop dsl to handle same argument in nested loop (kubeflow#1052)
* update loop dsl to handle same argument in nested loop * fix lint * fix sdk dependency
1 parent 98a2332 commit 96e573e

20 files changed

+505
-233
lines changed

sdk/python/kfp_tekton/tekton.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ def __init__(self,
352352
self.items_is_string = True
353353
else:
354354
super().__init__(loop_args=loop_args, parallelism=parallelism)
355+
self.loop_args = TektonLoopArguments(
356+
loop_args,
357+
code=self._next_id(),
358+
)
355359
self.items_is_string = False
356360

357361
self.separator = None

sdk/python/tests/compiler/compiler_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ def test_recur_cond_workflow(self):
190190
from .testdata.tekton_loop_dsl import pipeline
191191
self._test_pipeline_workflow(pipeline, 'tekton_loop_dsl.yaml')
192192

193+
def test_nested_loop_same_arg_workflow(self):
194+
"""
195+
Test compiling a nested loop with same argument workflow.
196+
"""
197+
from .testdata.nested_loop_same_arg import loop_multi
198+
self._test_pipeline_workflow(loop_multi, 'nested_loop_same_arg.yaml')
199+
193200
def test_loop_with_numeric_workflow(self):
194201
"""
195202
Test compiling a loop with numeric inputs in workflow.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ spec:
136136
value: $(context.pipelineRun.name)
137137
- name: pipelineRun-namespace
138138
value: $(context.pipelineRun.namespace)
139-
- name: any-sequencer-looped-for-loop-1
139+
- name: any-sequencer-looped-for-loop-2
140140
params:
141-
- name: param-loop-item
141+
- name: loop-item-param-1
142142
value: $(params.param)
143143
taskSpec:
144144
apiVersion: custom.tekton.dev/v1alpha1
145145
kind: PipelineLoop
146146
spec:
147147
pipelineSpec:
148148
params:
149-
- name: param-loop-item
149+
- name: loop-item-param-1
150150
type: string
151151
tasks:
152152
- name: print-10
@@ -234,7 +234,7 @@ spec:
234234
value: $(context.pipelineRun.name)
235235
- name: pipelineRun-namespace
236236
value: $(context.pipelineRun.namespace)
237-
iterateParam: param-loop-item
237+
iterateParam: loop-item-param-1
238238
metadata:
239239
labels:
240240
pipelines.kubeflow.org/cache_enabled: "true"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ metadata:
4242
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "[\"a\", \"b\",
4343
\"c\"]", "name": "param", "optional": true, "type": "JsonArray"}], "name": "any-sequencer-looped"}'
4444
tekton.dev/resource_templates: '[{"apiVersion": "custom.tekton.dev/v1alpha1",
45-
"kind": "PipelineLoop", "metadata": {"name": "any-sequencer-looped-for-loop-1"},
46-
"spec": {"iterateParam": "param-loop-item", "pipelineSpec": {"params": [{"name":
47-
"param-loop-item", "type": "string"}], "tasks": [{"name": "print-10", "taskSpec":
45+
"kind": "PipelineLoop", "metadata": {"name": "any-sequencer-looped-for-loop-2"},
46+
"spec": {"iterateParam": "loop-item-param-1", "pipelineSpec": {"params": [{"name":
47+
"loop-item-param-1", "type": "string"}], "tasks": [{"name": "print-10", "taskSpec":
4848
{"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest":
4949
"{\"name\": \"print-10\", \"outputs\": [{\"description\": \"Represents an output
5050
paramter.\", \"name\": \"output_value\", \"type\": \"String\"}], \"version\":
@@ -168,11 +168,11 @@ spec:
168168
value: $(context.pipelineRun.name)
169169
- name: pipelineRun-namespace
170170
value: $(context.pipelineRun.namespace)
171-
- name: any-sequencer-looped-for-loop-1
171+
- name: any-sequencer-looped-for-loop-2
172172
taskRef:
173173
apiVersion: custom.tekton.dev/v1alpha1
174174
kind: PipelineLoop
175-
name: any-sequencer-looped-for-loop-1
175+
name: any-sequencer-looped-for-loop-2
176176
params:
177-
- name: param-loop-item
177+
- name: loop-item-param-1
178178
value: $(params.param)

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,48 @@ spec:
5858
pipelines.kubeflow.org/component_spec_digest: '{"name": "Produce list",
5959
"outputs": [{"name": "data_list", "type": "List"}], "version": "Produce
6060
list@sha256=3d80b314916a06826def6fa78eab66cd69199497d7d92a8d199bd5d906706abe"}'
61-
- runAfter:
62-
- produce-list
63-
name: loop-with-enumerate-basic-for-loop-1
61+
- name: loop-with-enumerate-basic-for-loop-2
6462
params:
65-
- name: produce-list-data_list-loop-item
63+
- name: loop-item-param-1
6664
value: $(tasks.produce-list.results.data-list)
6765
taskSpec:
6866
apiVersion: custom.tekton.dev/v1alpha1
6967
kind: PipelineLoop
7068
spec:
7169
pipelineSpec:
7270
params:
73-
- name: iteration-number-2
71+
- name: iteration-number-3
7472
type: string
75-
- name: produce-list-data_list-loop-item
73+
- name: loop-item-param-1
7674
type: string
7775
tasks:
7876
- name: consume-data
7977
params:
80-
- name: iteration-number-2
81-
value: $(params.iteration-number-2)
82-
- name: produce-list-data_list-loop-item
83-
value: $(params.produce-list-data_list-loop-item)
78+
- name: iteration-number-3
79+
value: $(params.iteration-number-3)
80+
- name: loop-item-param-1
81+
value: $(params.loop-item-param-1)
8482
taskSpec:
8583
steps:
8684
- name: main
8785
command:
8886
- echo
89-
- $(inputs.params.iteration-number-2)
90-
- $(inputs.params.produce-list-data_list-loop-item)
87+
- $(inputs.params.iteration-number-3)
88+
- $(inputs.params.loop-item-param-1)
9189
image: busybox
9290
params:
93-
- name: iteration-number-2
91+
- name: iteration-number-3
9492
type: string
95-
- name: produce-list-data_list-loop-item
93+
- name: loop-item-param-1
9694
type: string
9795
metadata:
9896
labels:
9997
pipelines.kubeflow.org/cache_enabled: "true"
10098
annotations:
10199
pipelines.kubeflow.org/component_spec_digest: '{"name": "Consume
102100
data", "outputs": [], "version": "Consume data@sha256=748cfc9398fb5667535b2ae5940d7947826385c62858c6b1b637b527d9b57e6e"}'
103-
iterationNumberParam: iteration-number-2
104-
iterateParam: produce-list-data_list-loop-item
101+
iterationNumberParam: iteration-number-3
102+
iterateParam: loop-item-param-1
105103
metadata:
106104
labels:
107105
pipelines.kubeflow.org/cache_enabled: "true"

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@ metadata:
3131
pipelines.kubeflow.org/pipeline_spec: '{"description": "Test pipeline to verify
3232
functions of par loop.", "name": "loop-with-enumerate-basic"}'
3333
tekton.dev/resource_templates: '[{"apiVersion": "custom.tekton.dev/v1alpha1",
34-
"kind": "PipelineLoop", "metadata": {"name": "loop-with-enumerate-basic-for-loop-1"},
35-
"spec": {"iterateParam": "produce-list-data_list-loop-item", "iterationNumberParam":
36-
"iteration-number-2", "pipelineSpec": {"params": [{"name": "iteration-number-2",
37-
"type": "string"}, {"name": "produce-list-data_list-loop-item", "type": "string"}],
38-
"tasks": [{"name": "consume-data", "params": [{"name": "iteration-number-2",
39-
"value": "$(params.iteration-number-2)"}, {"name": "produce-list-data_list-loop-item",
40-
"value": "$(params.produce-list-data_list-loop-item)"}], "taskSpec": {"metadata":
41-
{"annotations": {"pipelines.kubeflow.org/component_spec_digest": "{\"name\":
42-
\"Consume data\", \"outputs\": [], \"version\": \"Consume data@sha256=748cfc9398fb5667535b2ae5940d7947826385c62858c6b1b637b527d9b57e6e\"}"},
34+
"kind": "PipelineLoop", "metadata": {"name": "loop-with-enumerate-basic-for-loop-2"},
35+
"spec": {"iterateParam": "loop-item-param-1", "iterationNumberParam": "iteration-number-3",
36+
"pipelineSpec": {"params": [{"name": "iteration-number-3", "type": "string"},
37+
{"name": "loop-item-param-1", "type": "string"}], "tasks": [{"name": "consume-data",
38+
"params": [{"name": "iteration-number-3", "value": "$(params.iteration-number-3)"},
39+
{"name": "loop-item-param-1", "value": "$(params.loop-item-param-1)"}], "taskSpec":
40+
{"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest":
41+
"{\"name\": \"Consume data\", \"outputs\": [], \"version\": \"Consume data@sha256=748cfc9398fb5667535b2ae5940d7947826385c62858c6b1b637b527d9b57e6e\"}"},
4342
"labels": {"pipelines.kubeflow.org/cache_enabled": "true"}}, "params": [{"name":
44-
"iteration-number-2", "type": "string"}, {"name": "produce-list-data_list-loop-item",
45-
"type": "string"}], "steps": [{"command": ["echo", "$(inputs.params.iteration-number-2)",
46-
"$(inputs.params.produce-list-data_list-loop-item)"], "image": "busybox", "name":
47-
"main"}]}}]}}}]'
43+
"iteration-number-3", "type": "string"}, {"name": "loop-item-param-1", "type":
44+
"string"}], "steps": [{"command": ["echo", "$(inputs.params.iteration-number-3)",
45+
"$(inputs.params.loop-item-param-1)"], "image": "busybox", "name": "main"}]}}]}}}]'
4846
labels:
4947
pipelines.kubeflow.org/pipelinename: ''
5048
pipelines.kubeflow.org/generation: ''
@@ -73,13 +71,11 @@ spec:
7371
pipelines.kubeflow.org/component_spec_digest: '{"name": "Produce list",
7472
"outputs": [{"name": "data_list", "type": "List"}], "version": "Produce
7573
list@sha256=3d80b314916a06826def6fa78eab66cd69199497d7d92a8d199bd5d906706abe"}'
76-
- runAfter:
77-
- produce-list
78-
name: loop-with-enumerate-basic-for-loop-1
74+
- name: loop-with-enumerate-basic-for-loop-2
7975
taskRef:
8076
apiVersion: custom.tekton.dev/v1alpha1
8177
kind: PipelineLoop
82-
name: loop-with-enumerate-basic-for-loop-1
78+
name: loop-with-enumerate-basic-for-loop-2
8379
params:
84-
- name: produce-list-data_list-loop-item
80+
- name: loop-item-param-1
8581
value: $(tasks.produce-list.results.data-list)

0 commit comments

Comments
 (0)