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

feat(sdk): Surface kubernetes configuration in container builder #6095

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
7 changes: 5 additions & 2 deletions sdk/python/kfp/containers/_container_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ContainerBuilder(object):
ContainerBuilder helps build a container image
"""
def __init__(self, gcs_staging=None, default_image_name=None, namespace=None,
service_account='kubeflow-pipelines-container-builder', kaniko_executor_image=KANIKO_EXECUTOR_IMAGE_DEFAULT):
service_account='kubeflow-pipelines-container-builder', kaniko_executor_image=KANIKO_EXECUTOR_IMAGE_DEFAULT, k8s_client_configuration=None):
"""
Args:
gcs_staging (str): GCS bucket/blob that can store temporary build files,
Expand All @@ -71,13 +71,16 @@ def __init__(self, gcs_staging=None, default_image_name=None, namespace=None,
The default value is "kubeflow-pipelines-container-builder". It works with Kubeflow Pipelines clusters installed using Google Cloud Marketplace or Standalone with version > 0.4.0.
The service account should have permission to read and write from staging gcs path and upload built images to gcr.io.
kaniko_executor_image (str): Docker image used to run kaniko executor. Defaults to gcr.io/kaniko-project/executor:v0.10.0.
k8s_client_configuration (kubernetes.Configuration): Kubernetes client configuration object to be used when talking with Kubernetes API.
This is optional. If not specified, it will use the default configuration. This can be used to personalize the client used to talk to the Kubernetes server and change authentication parameters.
"""
self._gcs_staging = gcs_staging
self._gcs_staging_checked = False
self._default_image_name = default_image_name
self._namespace = namespace
self._service_account = service_account
self._kaniko_image = kaniko_executor_image
self._k8s_client_configuration = k8s_client_configuration

def _get_namespace(self):
if self._namespace is None:
Expand Down Expand Up @@ -183,7 +186,7 @@ def build(self, local_dir, docker_filename : str = 'Dockerfile', target_image=No
target_image=target_image)
logging.info('Start a kaniko job for build.')
from ._k8s_job_helper import K8sJobHelper
k8s_helper = K8sJobHelper()
k8s_helper = K8sJobHelper(self._k8s_client_configuration)
result_pod_obj = k8s_helper.run_job(kaniko_spec, timeout)
logging.info('Kaniko job complete.')

Expand Down
10 changes: 5 additions & 5 deletions sdk/python/kfp/containers/_k8s_job_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
class K8sJobHelper(object):
""" Kubernetes Helper """

def __init__(self):
if not self._configure_k8s():
def __init__(self, k8s_client_configuration=None):
if not self._configure_k8s(k8s_client_configuration):
raise Exception('K8sHelper __init__ failure')

def _configure_k8s(self):
def _configure_k8s(self, k8s_client_configuration=None):
k8s_config_file = os.environ.get('KUBECONFIG')
if k8s_config_file:
try:
logging.info('Loading kubernetes config from the file %s', k8s_config_file)
config.load_kube_config(config_file=k8s_config_file)
config.load_kube_config(config_file=k8s_config_file, client_configuration=k8s_client_configuration)
except Exception as e:
raise RuntimeError('Can not load kube config from the file %s, error: %s', k8s_config_file, e)
else:
Expand All @@ -42,7 +42,7 @@ def _configure_k8s(self):
except:
logging.info('Cannot find in-cluster config, trying the local kubernetes config. ')
try:
config.load_kube_config()
config.load_kube_config(client_configuration=k8s_client_configuration)
logging.info('Found local kubernetes config. Initialized with kube_config.')
except:
raise RuntimeError('Forgot to run the gcloud command? Check out the link: \
Expand Down