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

2682: Support a custom kube config location in K8sJobHelper #2683

Merged
merged 1 commit into from
Dec 18, 2019
Merged
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
27 changes: 18 additions & 9 deletions sdk/python/kfp/containers/_k8s_job_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from kubernetes import config
import time
import logging
import os


class K8sJobHelper(object):
Expand All @@ -27,17 +28,25 @@ def __init__(self):
raise Exception('K8sHelper __init__ failure')

def _configure_k8s(self):
try:
config.load_incluster_config()
logging.info('Initialized with in-cluster config.')
except:
logging.info('Cannot find in-cluster config, trying the local kubernetes config. ')
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)
except Exception as e:
raise RuntimeError('Can not load kube config from the file %s, error: %s', k8s_config_file, e)
else:
try:
config.load_kube_config()
logging.info('Found local kubernetes config. Initialized with kube_config.')
config.load_incluster_config()
logging.info('Initialized with in-cluster config.')
except:
raise RuntimeError('Forgot to run the gcloud command? Check out the link: \
https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl for more information')
logging.info('Cannot find in-cluster config, trying the local kubernetes config. ')
try:
config.load_kube_config()
logging.info('Found local kubernetes config. Initialized with kube_config.')
except:
raise RuntimeError('Forgot to run the gcloud command? Check out the link: \
https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl for more information')
self._api_client = k8s_client.ApiClient()
self._corev1 = k8s_client.CoreV1Api(self._api_client)
return True
Expand Down