Skip to content

Commit

Permalink
SDK - Containers - Getting namespace lazily (#2256)
Browse files Browse the repository at this point in the history
Class constructors should ideally do as little work as possible.
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Oct 10, 2019
1 parent 8dfa2d9 commit 25c01a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sdk/python/kfp/containers/_container_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ def __init__(self, gcs_staging=None, gcr_image_tag=None, namespace=None):
self._gcs_staging = gcs_staging
self._gcs_staging_checked = False
self._default_image_name = gcr_image_tag

# Configure the namespace
self._namespace = namespace
if namespace is None:

def _get_namespace(self):
if self._namespace is None:
# Configure the namespace
if os.path.exists(SERVICEACCOUNT_NAMESPACE):
with open(SERVICEACCOUNT_NAMESPACE, 'r') as f:
self._namespace = f.read()
else:
self._namespace = 'kubeflow'
return self._namespace

def _get_staging_location(self):
if self._gcs_staging_checked:
Expand Down Expand Up @@ -114,7 +116,7 @@ def _generate_kaniko_spec(self, context, docker_filename, target_image):
'apiVersion': 'v1',
'metadata': {
'generateName': 'kaniko-',
'namespace': self._namespace,
'namespace': self._get_namespace(),
'annotations': {
'sidecar.istio.io/inject': 'false'
},
Expand Down

0 comments on commit 25c01a1

Please sign in to comment.