Fix bug 1529: Give warning when removing unexisting chart
[osm/N2VC.git] / n2vc / k8s_helm_base_conn.py
index af22ecc..2225be3 100644 (file)
@@ -293,6 +293,7 @@ class K8sHelmBaseConnector(K8sConnector):
             kdu_model: str,
             paths: dict,
             env: dict,
+            kdu_instance: str,
             atomic: bool = True,
             timeout: float = 300,
             params: dict = None,
@@ -313,23 +314,6 @@ class K8sHelmBaseConnector(K8sConnector):
                 version = str(parts[1])
                 kdu_model = parts[0]
 
-        # generate a name for the release. Then, check if already exists
-        kdu_instance = None
-        while kdu_instance is None:
-            kdu_instance = self._generate_release_name(kdu_model)
-            try:
-                result = await self._status_kdu(
-                    cluster_id=cluster_id,
-                    kdu_instance=kdu_instance,
-                    namespace=namespace,
-                    show_error_log=False,
-                )
-                if result is not None:
-                    # instance already exists: generate a new one
-                    kdu_instance = None
-            except K8sException:
-                pass
-
         command = self._get_install_command(kdu_model, kdu_instance, namespace,
                                             params_str, version, atomic, timeout)
 
@@ -389,8 +373,6 @@ class K8sHelmBaseConnector(K8sConnector):
             self.log.error(msg)
             raise K8sException(msg)
 
-        return kdu_instance
-
     async def upgrade(
         self,
         cluster_uuid: str,
@@ -611,8 +593,8 @@ class K8sHelmBaseConnector(K8sConnector):
         # look for instance to obtain namespace
         instance_info = await self.get_instance_info(cluster_uuid, kdu_instance)
         if not instance_info:
-            raise K8sException("kdu_instance {} not found".format(kdu_instance))
-
+            self.log.warning(("kdu_instance {} not found".format(kdu_instance)))
+            return True
         # init env, paths
         paths, env = self._init_paths_env(
             cluster_name=cluster_id, create_if_not_exist=True
@@ -1377,7 +1359,8 @@ class K8sHelmBaseConnector(K8sConnector):
         return params_str
 
     @staticmethod
-    def _generate_release_name(chart_name: str):
+    def generate_kdu_instance_name(**kwargs):
+        chart_name = kwargs["kdu_model"]
         # check embeded chart (file or dir)
         if chart_name.startswith("/"):
             # extract file or directory name