diff options
author | Jack Lucas <jflucas@research.att.com> | 2018-04-17 13:15:46 +0000 |
---|---|---|
committer | Jack Lucas <jflucas@research.att.com> | 2018-04-17 13:24:51 +0000 |
commit | 8ada177fc4c093acc5028a4134f77dcef8ee9837 (patch) | |
tree | df1ceeec8d7055ca87b734e2aadb25607fa3dee4 /k8s/k8sclient/k8sclient.py | |
parent | fe5179575191dd40af3d9e4a8d4bd0144e4d08de (diff) |
Support for /var/run/secrets/kubernetes.io
Change-Id: If259892dd332981654bcad6b1e07037afbf31c7d
Issue-ID: DCAEGEN2-447
Signed-off-by: Jack Lucas <jflucas@research.att.com>
Diffstat (limited to 'k8s/k8sclient/k8sclient.py')
-rw-r--r-- | k8s/k8sclient/k8sclient.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/k8s/k8sclient/k8sclient.py b/k8s/k8sclient/k8sclient.py index a61fafa..017dd36 100644 --- a/k8s/k8sclient/k8sclient.py +++ b/k8s/k8sclient/k8sclient.py @@ -32,8 +32,27 @@ def _create_exposed_service_name(component_name): return ("x{0}".format(component_name))[:63] def _configure_api(): - #TODO: real configuration - config.load_kube_config(os.path.join(os.environ["HOME"], '.kube/config')) + # Look for a kubernetes config file in ~/.kube/config + kubepath = os.path.join(os.environ["HOME"], '.kube/config') + if os.path.exists(kubepath): + config.load_kube_config(kubepath) + else: + # Maybe we're running in a k8s container and we can use info provided by k8s + # We would like to use: + # config.load_incluster_config() + # but this looks into os.environ for kubernetes host and port, and from + # the plugin those aren't visible. So we use the InClusterConfigLoader class, + # where we can set the environment to what we like. + # This is probably brittle! Maybe there's a better alternative. + localenv = { + config.incluster_config.SERVICE_HOST_ENV_NAME : "kubernetes.default.svc.cluster.local", + config.incluster_config.SERVICE_PORT_ENV_NAME : "443" + } + config.incluster_config.InClusterConfigLoader( + token_filename=config.incluster_config.SERVICE_TOKEN_FILENAME, + cert_filename=config.incluster_config.SERVICE_CERT_FILENAME, + environ=localenv + ).load_and_set() def _create_container_object(name, image, always_pull, env={}, container_ports=[], volume_mounts = []): # Set up environment variables |