Support for /var/run/secrets/kubernetes.io 53/43353/1
authorJack Lucas <jflucas@research.att.com>
Tue, 17 Apr 2018 13:15:46 +0000 (13:15 +0000)
committerJack Lucas <jflucas@research.att.com>
Tue, 17 Apr 2018 13:24:51 +0000 (13:24 +0000)
Change-Id: If259892dd332981654bcad6b1e07037afbf31c7d
Issue-ID: DCAEGEN2-447
Signed-off-by: Jack Lucas <jflucas@research.att.com>
k8s/k8s-node-type.yaml
k8s/k8sclient/k8sclient.py
k8s/pom.xml
k8s/setup.py

index 31d4248..7086701 100644 (file)
@@ -25,7 +25,7 @@ plugins:
   k8s:
     executor: 'central_deployment_agent'
     package_name: k8splugin
-    package_version: 1.0.1
+    package_version: 1.1.0
 
 data_types:
 
index a61fafa..017dd36 100644 (file)
@@ -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
index ededd75..afcf45a 100644 (file)
@@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
   <groupId>org.onap.dcaegen2.platform.plugins</groupId>
   <artifactId>k8s</artifactId>
   <name>k8s-plugin</name>
-  <version>1.0.1-SNAPSHOT</version>
+  <version>1.1.0-SNAPSHOT</version>
   <url>http://maven.apache.org</url>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
index 2d17dc4..1d15ff5 100644 (file)
@@ -23,7 +23,7 @@ from setuptools import setup
 setup(
     name='k8splugin',
     description='Cloudify plugin for containerized components deployed using Kubernetes',
-    version="1.0.1",
+    version="1.1.0",
     author='J. F. Lucas, Michael Hwang, Tommy Carpenter',
     packages=['k8splugin','k8sclient','msb','configure'],
     zip_safe=False,