Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2802: Set ImagePullPolicy per pipeline. #3534

Merged
merged 8 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/python/kfp/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ def _create_pipeline_workflow(self, args, pipeline, op_transformers=None, pipeli

if exit_handler:
workflow['spec']['onExit'] = exit_handler.name

if pipeline_conf.image_pull_policy != None and pipeline_conf.image_pull_policy in ["Always", "Never", "IfNotPresent"]:
for template in workflow["spec"]["templates"]:
if "container" in template:
template["container"]["imagePullPolicy"] = pipeline_conf.image_pull_policy
NikeNano marked this conversation as resolved.
Show resolved Hide resolved

return workflow

def _validate_exit_handler(self, pipeline):
Expand Down
12 changes: 11 additions & 1 deletion sdk/python/kfp/dsl/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self):
self.ttl_seconds_after_finished = -1
self.artifact_location = None
self.op_transformers = []
self.image_pull_policy = None

def set_image_pull_secrets(self, image_pull_secrets):
"""Configures the pipeline level imagepullsecret
Expand Down Expand Up @@ -126,6 +127,16 @@ def foo_pipeline(tag: str, pull_image_policy: str):
self.artifact_location = artifact_location
return self

def set_image_pull_policy(self, policy: str):
"""Configures the default image pull policy

Args:
policy: the pull policy, has to be one of: Always, Never, IfNotPresent.
For more info: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Container.md
NikeNano marked this conversation as resolved.
Show resolved Hide resolved
"""
self.image_pull_policy = policy
return self

def add_op_transformer(self, transformer):
"""Configures the op_transformers which will be applied to all ops in the pipeline.

Expand Down Expand Up @@ -254,4 +265,3 @@ def _set_metadata(self, metadata):
'''
self._metadata = metadata


22 changes: 22 additions & 0 deletions sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,28 @@ def some_pipeline():
container = template.get('container', None)
if container:
self.assertEqual(template['retryStrategy']['limit'], 5)

def test_image_pull_policy(self):
def some_op():
return dsl.ContainerOp(
name='sleep',
image='busybox',
command=['sleep 1'],
)

@dsl.pipeline(name='some_pipeline')
def some_pipeline():
task1 = some_op()
task2 = some_op()
task3 = some_op()

dsl.get_pipeline_conf().set_image_pull_policy(policy="Allways")
workflow_dict = compiler.Compiler()._compile(some_pipeline)
for template in workflow_dict['spec']['templates']:
container = template.get('container', None)
if container:
self.assertEqual(template['container']['imagePullPolicy'], "Allways")


def test_container_op_output_error_when_no_or_multiple_outputs(self):

Expand Down