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 default_gcp_op #314

Merged
merged 8 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 2 additions & 3 deletions sdk/python/kfp/dsl/_container_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from . import _pipeline
from . import _pipeline_param
import re
from typing import Dict, List
from typing import Dict


class ContainerOp(object):
"""Represents an op implemented by a docker container image."""

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, gcp_secret: str=None, is_exit_handler=False):
file_outputs : Dict[str, str]=None, is_exit_handler=False):
"""Create a new instance of ContainerOp.

Args:
Expand Down Expand Up @@ -52,7 +52,6 @@ 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
15 changes: 15 additions & 0 deletions sdk/python/kfp/dsl/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .kubeflow_tfjob_launcher_op import kubeflow_tfjob_launcher_op
Copy link
Contributor

@Ark-kun Ark-kun Nov 20, 2018

Choose a reason for hiding this comment

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

Wrong import?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed. thx

47 changes: 47 additions & 0 deletions sdk/python/kfp/dsl/components/default_gcp_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from kfp import dsl
from typing import Dict
from kubernetes import client as k8s_client
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please move the kubernetes import inside the function?
Although we state that we require the kubernetes package, it's nice to be able to use most of our library without it.

Copy link
Member Author

Choose a reason for hiding this comment

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

done



def default_gcp_op(name: str, image: str, command: str = None,
arguments: str = None, file_inputs: Dict[dsl.PipelineParam, str] = None,
file_outputs: Dict[str, str] = None, is_exit_handler=False):
"""An operator that mounts the default GCP service account to the container.

The user-gcp-sa secret is created as part of the kubeflow deployment that
stores the access token for kubeflow user service account.

With this service account, the container has a range of GCP APIs to
access to. This service account is automatically created as part of the
kubeflow deployment.

For the list of the GCP APIs this service account can access to, check
https://github.com/kubeflow/kubeflow/blob/7b0db0d92d65c0746ac52b000cbc290dac7c62b1/deployment/gke/deployment_manager_configs/iam_bindings_template.yaml#L18

If you want to call the GCP APIs in a different project, grant the kf-user
service account access permission.
"""
return dsl.ContainerOp(name, image, command, arguments, file_inputs,
IronPan marked this conversation as resolved.
Show resolved Hide resolved
file_outputs, is_exit_handler). \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please move the dot to the next line?
You can use parentheses to allow line breaking without slashes: https://stackoverflow.com/questions/4768941/how-to-break-a-line-of-chained-methods-in-python

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

Choose a reason for hiding this comment

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

and thanks for the suggestion of parentheses. I think slash is not uncommon to see so maybe just use it for now? we can switch when we see it pain to read

add_volume(k8s_client.V1Volume(name='gcp-credentials',
secret=k8s_client.V1SecretVolumeSource(
secret_name='user-gcp-sa'))). \
add_volume_mount(k8s_client.V1VolumeMount(
mount_path='/secret/gcp-credentials', name='gcp-credentials')). \
add_env_variable(k8s_client.V1EnvVar(
name='GOOGLE_APPLICATION_CREDENTIALS',
value='/secret/gcp-credentials/user-gcp-sa.json'))