k8s_juju_conn.py: fix cloud name for k8s
[osm/N2VC.git] / n2vc / k8s_helm_conn.py
index f7ff853..01b448b 100644 (file)
@@ -102,6 +102,17 @@ class K8sHelmConnector(K8sConnector):
             namespace: str = 'kube-system',
             reuse_cluster_uuid=None
     ) -> (str, bool):
+        """
+        It prepares a given K8s cluster environment to run Charts on both sides:
+            client (OSM)
+            server (Tiller)
+
+        :param k8s_creds: credentials to access a given K8s cluster, i.e. a valid '.kube/config'
+        :param namespace: optional namespace to be used for helm. By default, 'kube-system' will be used
+        :param reuse_cluster_uuid: existing cluster uuid for reuse
+        :return: uuid of the K8s cluster and True if connector has installed some software in the cluster
+        (on error, an exception will be raised)
+        """
 
         cluster_uuid = reuse_cluster_uuid
         if not cluster_uuid:
@@ -770,6 +781,15 @@ class K8sHelmConnector(K8sConnector):
     def _generate_release_name(
             chart_name: str
     ):
+        # check embeded chart (file or dir)
+        if chart_name.startswith('/'):
+            # extract file or directory name
+            chart_name = chart_name[chart_name.rfind('/')+1:]
+        # check URL
+        elif '://' in chart_name:
+            # extract last portion of URL
+            chart_name = chart_name[chart_name.rfind('/')+1:]
+
         name = ''
         for c in chart_name:
             if c.isalpha() or c.isnumeric():
@@ -1105,7 +1125,10 @@ class K8sHelmConnector(K8sConnector):
             msg = 'Exception executing command: {} -> {}'.format(command, e)
             if show_error_log:
                 self.error(msg)
-            return '', -1
+            if raise_exception_on_error:
+                raise e
+            else:
+                return '', -1
 
     def _remote_exec(
             self,