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

Add gcp secret parameter to container op #261

Merged
merged 6 commits into from
Nov 15, 2018
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
11 changes: 11 additions & 0 deletions sdk/python/kfp/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ def _op_to_template(self, op):
if op.cpu_request:
template['container']['resources']['requests']['cpu'] = op.cpu_request

if op.gcp_secret:
template['container']['env'] = {}
Copy link
Contributor

@Ark-kun Ark-kun Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  template['container']['env'] = [
    {
      'name': 'GOOGLE_APPLICATION_CREDENTIALS',
      'value': '/secret/gcp-credentials/user-gcp-sa.json',
    },
  ]
  template['container']['volumeMounts'] = [
    {
      'name': 'gcp-credentials',
      'mountPath': '/secret/gcp-credentials',
    },
  ]
  template['volumes'] = [
    {
      'name': 'gcp-credentials',
      'secret': {
        'secretName': op.gcp_secret,
      }
    },
  ]

template['container']['env']['name'] = 'GOOGLE_APPLICATION_CREDENTIALS'
template['container']['env']['value'] = '/secret/gcp-credentials/user-gcp-sa.json'
template['container']['volumeMounts'] = {}
template['container']['volumeMounts']['mountPath'] = '/secret/gcp-credentials'
template['container']['volumeMounts']['name'] = 'gcp-credentials'
template['volumes'] = {}
template['volumes']['name'] = 'gcp-credentials'
template['volumes']['secret'] = {}
template['volumes']['secret']['secretName'] = op.gcp_secret
return template

def _get_groups_for_ops(self, root_group):
Expand Down
7 changes: 5 additions & 2 deletions sdk/python/kfp/dsl/_container_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContainerOp(object):

def __init__(self, name: str, image: str, command: str=None, arguments: str=None,
file_inputs : Dict[_pipeline_param.PipelineParam, str]=None,
file_outputs : Dict[str, str]=None, is_exit_handler=False):
file_outputs : Dict[str, str]=None, gcp_secret: str=None, is_exit_handler=False):
"""Create a new instance of ContainerOp.

Args:
Expand All @@ -41,6 +41,8 @@ def __init__(self, name: str, image: str, command: str=None, arguments: str=None
file_outputs: Maps output labels to local file paths. At pipeline run time,
the value of a PipelineParam is saved to its corresponding local file. It's
one way for outside world to receive outputs of the container.
gcp_secret: Specifying what secret to mount to the container for accessing
GCP APIs.
is_exit_handler: Whether it is used as an exit handler.
"""

Expand All @@ -52,6 +54,7 @@ def __init__(self, name: str, image: str, command: str=None, arguments: str=None
self.image = image
self.command = command
self.arguments = arguments
self.gcp_secret = gcp_secret
self.is_exit_handler = is_exit_handler
self.memory_limit = None
self.memory_request = None
Expand Down Expand Up @@ -150,6 +153,6 @@ def set_cpu_limit(self, cpu):

self._validate_cpu_string(cpu)
self.cpu_limit = cpu

def __repr__(self):
return str({self.__class__.__name__: self.__dict__})
16 changes: 15 additions & 1 deletion sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ def test_operator_to_template(self):
msg2 = dsl.PipelineParam('msg2', value='value2')
op = dsl.ContainerOp(name='echo', image='image', command=['sh', '-c'],
arguments=['echo %s %s | tee /tmp/message.txt' % (msg1, msg2)],
file_outputs={'merged': '/tmp/message.txt'})
file_outputs={'merged': '/tmp/message.txt'}, gcp_secret='user-gcp-sa')
golden_output = {
'container': {
'image': 'image',
'args': [
'echo {{inputs.parameters.msg1}} {{inputs.parameters.msg2}} | tee /tmp/message.txt'
],
'command': ['sh', '-c'],
'env': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test running this pipeline?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create the secret in your cluster, compile a pipeline, submit it to the cluster and check for errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Alexey for testing it manually before merging

'name': 'GOOGLE_APPLICATION_CREDENTIALS',
'value': '/secret/gcp-credentials/user-gcp-sa.json'
},
'volumeMounts': {
'mountPath': '/secret/gcp-credentials',
'name': 'gcp-credentials'
}
},
'inputs': {'parameters':
[
Expand Down Expand Up @@ -90,6 +98,12 @@ def test_operator_to_template(self):
}
}
}]
},
'volumes': {
'name': 'gcp-credentials',
'secret': {
'secretName': 'user-gcp-sa'
}
}
}

Expand Down