Skip to content

Commit

Permalink
feat(sdk): DSL - Added support for volatile components (#4104)
Browse files Browse the repository at this point in the history
Volatile components do not reuse the cached results by default.
The pipeline authors can re-enable cache reuse if they want.
  • Loading branch information
Ark-kun authored and Bobgy committed Jul 8, 2020
1 parent 7a0df42 commit 07ebc27
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions components/diagnostics/diagnose_me/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ description: |-
Raises:
RuntimeError: If configuration is not setup properly and
HALT_ON_ERROR flag is set.
metadata:
annotations:
volatile_component: "true"
inputs:
- name: bucket
type: String
Expand Down
3 changes: 3 additions & 0 deletions components/git/clone/component.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Git clone
description: Creates a shallow clone of the specified repo branch
metadata:
annotations:
volatile_component: "true"
inputs:
- {name: Repo URI, type: URI}
- {name: Branch, type: String, default: master}
Expand Down
3 changes: 3 additions & 0 deletions components/google-cloud/storage/list/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ inputs:
- {name: GCS path, type: URI, description: 'GCS path for listing. For recursive listing use the "gs://bucket/path/**" syntax".'}
outputs:
- {name: Paths}
metadata:
annotations:
volatile_component: 'true'
implementation:
container:
image: google/cloud-sdk
Expand Down
6 changes: 5 additions & 1 deletion sdk/python/kfp/dsl/_component_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ def _create_container_op_from_component_and_arguments(
task.container.add_env_variable(k8s_client.V1EnvVar(name=name, value=value))

if component_spec.metadata:
for key, value in (component_spec.metadata.annotations or {}).items():
annotations = component_spec.metadata.annotations or {}
for key, value in annotations.items():
task.add_pod_annotation(key, value)
for key, value in (component_spec.metadata.labels or {}).items():
task.add_pod_label(key, value)
# Disabling the caching for the volatile components by default
if annotations.get('volatile_component', 'false') == 'true':
task.execution_options.caching_strategy.max_cache_staleness = 'P0D'

return task
15 changes: 15 additions & 0 deletions sdk/python/tests/dsl/component_bridge_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ def test_passing_component_metadata_to_container_op(self):
self.assertEqual(task1.pod_annotations['key1'], 'value1')
self.assertEqual(task1.pod_labels['key1'], 'value1')

def test_volatile_components(self):
component_text = textwrap.dedent('''\
metadata:
annotations:
volatile_component: "true"
implementation:
container:
image: busybox
'''
)
task_factory1 = load_component_from_text(text=component_text)

task1 = task_factory1()
self.assertEqual(task1.execution_options.caching_strategy.max_cache_staleness, 'P0D')

def test_type_compatibility_check_not_failing_when_disabled(self):
component_a = textwrap.dedent('''\
outputs:
Expand Down

0 comments on commit 07ebc27

Please sign in to comment.