Skip to content

Commit

Permalink
2682: Support a custom kube config location in K8sJobHelper (kubeflow…
Browse files Browse the repository at this point in the history
  • Loading branch information
pahask8 authored and Jeffwan committed Dec 9, 2020
1 parent df6c8bc commit 337734b
Showing 1 changed file with 18 additions and 9 deletions.
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

0 comments on commit 337734b

Please sign in to comment.