Skip to content

Commit 2ec7b6e

Browse files
authored
fix(bug): fix underscore param by checking pipeline param instead of task param (kubeflow#1077)
* fix underscore param by checking pipeline param instead of task param * update test cases
1 parent b4e322a commit 2ec7b6e

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

sdk/python/kfp_tekton/compiler/_tekton_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ def _handle_tekton_custom_task(custom_task: dict, workflow: dict, recursive_task
315315
'$(params.%s)' % param_result[1]))
316316
else:
317317
new_param_ref = '%s-%s' % param_result
318-
# Nested task reference name must be the same as the one in the params
318+
# Nested task reference name must be the same as the one in the pipeline params
319319
# Otherwise, use the default param ref since it will be generated
320320
# by the custom task functions such as condition and loop
321-
for i in task.get('params', []):
321+
for i in custom_task_cr['spec']['pipelineSpec'].get('params', []):
322322
if sanitize_k8s_name(i['name']) == new_param_ref:
323323
new_param_ref = i['name']
324324
break

sdk/python/tests/compiler/testdata/nested_loop_with_underscore.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,56 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from kfp import dsl
15+
import itertools
16+
import yaml
17+
from kfp import dsl, components
1618
from kfp.components import load_component_from_text
1719
from kfp_tekton.compiler import TektonCompiler
20+
from kfp_tekton.tekton import TEKTON_CUSTOM_TASK_IMAGES
21+
22+
23+
ARTIFACT_FETCHER_IMAGE_NAME = "fetcher/image:latest"
24+
TEKTON_CUSTOM_TASK_IMAGES = TEKTON_CUSTOM_TASK_IMAGES.append(ARTIFACT_FETCHER_IMAGE_NAME)
25+
26+
_artifact_fetcher_no = 0
27+
28+
29+
def artifact_fetcher(**artifact_paths: str):
30+
'''A containerOp template resolving some artifacts, given their paths.'''
31+
global _artifact_fetcher_no
32+
template_yaml = {
33+
'name': f'artifact-fetcher-{_artifact_fetcher_no}',
34+
'description': 'Artifact Fetch',
35+
'inputs': [
36+
{'name': name, 'type': 'String'}
37+
for name in artifact_paths.keys()
38+
],
39+
'outputs': [
40+
{'name': name, 'type': 'Artifact'}
41+
for name in artifact_paths.keys()
42+
],
43+
'implementation': {
44+
'container': {
45+
'image': ARTIFACT_FETCHER_IMAGE_NAME,
46+
'command': ['sh', '-c'], # irrelevant
47+
'args': [
48+
'--apiVersion', 'fetcher.tekton.dev/v1alpha1',
49+
'--kind', 'FETCHER',
50+
'--name', 'artifact_fetcher',
51+
*itertools.chain(*[
52+
(f'--{name}', {'inputValue': name})
53+
for name in artifact_paths.keys()
54+
])
55+
]
56+
}
57+
}
58+
}
59+
_artifact_fetcher_no += 1
60+
template_str = yaml.dump(template_yaml, Dumper=yaml.SafeDumper)
61+
template = components.load_component_from_text(template_str)
62+
op = template(**artifact_paths)
63+
op.add_pod_annotation("valid_container", "false")
64+
return op
1865

1966

2067
class Coder:
@@ -57,6 +104,7 @@ def double_loop_with_underscore(param_a: list = [1, 2, 3], param_b: list = ["a",
57104
with dsl.ParallelFor(param_a):
58105
with dsl.ParallelFor(param_b):
59106
op1 = PrintOp('print-1', f"print {op0.output}")
107+
op2 = artifact_fetcher(path=op0.output)
60108

61109

62110
if __name__ == '__main__':

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ spec:
150150
"print-1", "outputs": [{"description": "Represents an
151151
output paramter.", "name": "output_value", "type": "String"}],
152152
"version": "print-1@sha256=3b81342bc143f625b58ebdb01e7c83b145880dee807be35c1e16fdb835d46580"}'
153+
- name: artifact-fetcher-0
154+
params:
155+
- name: path
156+
value: $(params.print-0-output_value)
157+
taskRef:
158+
name: artifact_fetcher
159+
apiVersion: fetcher.tekton.dev/v1alpha1
160+
kind: FETCHER
153161
iterateParam: param_b-loop-item
154162
metadata:
155163
labels:

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ metadata:
5757
"print-0-output_value", "type": "string"}], "results": [{"description": "/tmp/outputs/output_value/data",
5858
"name": "output-value", "type": "string"}], "steps": [{"command": ["sh", "-c",
5959
"set -e\necho $0 > $1\n", "print $(inputs.params.print-0-output_value)", "$(results.output-value.path)"],
60-
"image": "alpine:3.6", "name": "main"}]}}]}}}]'
60+
"image": "alpine:3.6", "name": "main"}]}}, {"name": "artifact-fetcher-1", "params":
61+
[{"name": "path", "value": "$(params.print-0-output_value)"}], "taskRef": {"apiVersion":
62+
"fetcher.tekton.dev/v1alpha1", "kind": "FETCHER", "name": "artifact_fetcher"}}]}}}]'
6163
labels:
6264
pipelines.kubeflow.org/pipelinename: ''
6365
pipelines.kubeflow.org/generation: ''

0 commit comments

Comments
 (0)