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

Container builder #1774

Merged
merged 6 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 16 additions & 1 deletion sdk/python/kfp/compiler/_container_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,31 @@
import os
import uuid

SERVICEACCOUNT_NAMESPACE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
gaoning777 marked this conversation as resolved.
Show resolved Hide resolved

class ContainerBuilder(object):
"""
ContainerBuilder helps build a container image
"""
def __init__(self, gcs_staging, namespace):
def __init__(self, gcs_staging, namespace=None):
"""
Args:
gcs_staging (str): GCS blob that can store temporary build files
gaoning777 marked this conversation as resolved.
Show resolved Hide resolved
namespace (str): kubernetes namespace where the pod is launched,
default is the same namespace as the notebook service account in cluster
or 'kubeflow' if not in cluster
"""
if not gcs_staging.startswith('gs://'):
raise ValueError('Error: {} should be a GCS path.'.format(gcs_staging))
self._gcs_staging = gcs_staging
self._namespace = namespace
if namespace is None:
import os
if os.path.exists(SERVICEACCOUNT_NAMESPACE):
with open(SERVICEACCOUNT_NAMESPACE, 'r') as f:
self._namespace = f.read()
else:
self._namespace = 'kubeflow'

def _generate_kaniko_spec(self, context, docker_filename, target_image):
"""_generate_kaniko_yaml generates kaniko job yaml based on a template yaml """
Expand All @@ -39,6 +51,9 @@ def _generate_kaniko_spec(self, context, docker_filename, target_image):
'metadata': {
'generateName': 'kaniko-',
'namespace': self._namespace,
'annotations': {
'sidecar.istio.io/inject': 'false'
},
},
'kind': 'Pod',
'spec': {
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/kfp/compiler/_k8s_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def _configure_k8s(self):

def _create_k8s_job(self, yaml_spec):
""" _create_k8s_job creates a kubernetes job based on the yaml spec """
pod = k8s_client.V1Pod(metadata=k8s_client.V1ObjectMeta(generate_name=yaml_spec['metadata']['generateName']))
pod = k8s_client.V1Pod(metadata=k8s_client.V1ObjectMeta(generate_name=yaml_spec['metadata']['generateName'],
annotations=yaml_spec['metadata']['annotations']))
container = k8s_client.V1Container(name = yaml_spec['spec']['containers'][0]['name'],
image = yaml_spec['spec']['containers'][0]['image'],
args = yaml_spec['spec']['containers'][0]['args'],
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/tests/compiler/testdata/kaniko.basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ kind: Pod
metadata:
generateName: kaniko-
namespace: default
annotations:
sidecar.istio.io/inject: 'false'
spec:
restartPolicy: Never
serviceAccountName: default
Expand Down