Skip to content

Commit

Permalink
feat(sdk): SDK - Enable placeholders in task display names. Fixes kub…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun authored and Jeffwan committed Dec 9, 2020
1 parent 3094f16 commit a59b259
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sdk/python/kfp/compiler/_op_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def _outputs_to_json(op: BaseOp,
def _op_to_template(op: BaseOp):
"""Generate template given an operator inherited from BaseOp."""

# Display name
if op.display_name:
op.add_pod_annotation('pipelines.kubeflow.org/task_display_name', op.display_name)

# NOTE in-place update to BaseOp
# replace all PipelineParams with template var strings
processed_op = _process_base_ops(op)
Expand Down Expand Up @@ -270,10 +274,6 @@ def _op_to_template(op: BaseOp):
template['volumes'] = [convert_k8s_obj_to_json(volume) for volume in processed_op.volumes]
template['volumes'].sort(key=lambda x: x['name'])

# Display name
if processed_op.display_name:
template.setdefault('metadata', {}).setdefault('annotations', {})['pipelines.kubeflow.org/task_display_name'] = processed_op.display_name

if isinstance(op, dsl.ContainerOp) and op._metadata:
template.setdefault('metadata', {}).setdefault('annotations', {})['pipelines.kubeflow.org/component_spec'] = json.dumps(op._metadata.to_dict(), sort_keys=True)

Expand Down
10 changes: 10 additions & 0 deletions sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,16 @@ def some_pipeline():
template = workflow_dict['spec']['templates'][0]
self.assertEqual(template['metadata']['annotations']['pipelines.kubeflow.org/task_display_name'], 'Custom name')

def test_set_dynamic_display_name(self):
"""Test a pipeline with a customized task names."""

def some_pipeline(custom_name):
some_op().set_display_name(custom_name)

workflow_dict = kfp.compiler.Compiler()._compile(some_pipeline)
template = [template for template in workflow_dict['spec']['templates'] if 'container' in template][0]
self.assertNotIn('pipelineparam', template['metadata']['annotations']['pipelines.kubeflow.org/task_display_name'])

def test_set_parallelism(self):
"""Test a pipeline with parallelism limits."""
def some_op():
Expand Down

0 comments on commit a59b259

Please sign in to comment.