From 891732a9f4f1381a49e506cb9d39132b328aaa1c Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 14 Jul 2020 10:29:00 +0000 Subject: [PATCH 1/1] fix bugs 1117 and 1142 at deleting k8scluster helm-chart bug 1142: When helm is not going to be uninstalled, do not check for kdu releases bug 1117: When helm is going to be unistalled with kdu releases, just warn and skip uninstall helm. This happens because kdu release has been installed outside the scope of OSM. NBI already checks that there is not OSM kdu deployments upon k8scluster deletion, denying the operation if any. Change-Id: Icee2125b790c562130e13dd8c619d1c94c64c0fe Signed-off-by: tierno --- n2vc/k8s_helm_conn.py | 55 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/n2vc/k8s_helm_conn.py b/n2vc/k8s_helm_conn.py index a900d97..e3b51ba 100644 --- a/n2vc/k8s_helm_conn.py +++ b/n2vc/k8s_helm_conn.py @@ -280,40 +280,39 @@ class K8sHelmConnector(K8sConnector): ) -> bool: namespace, cluster_id = self._get_namespace_cluster_id(cluster_uuid) - self.log.debug( - "Resetting K8s environment. cluster uuid: {}".format(cluster_id) - ) + self.log.debug("Resetting K8s environment. cluster uuid: {} uninstall={}" + .format(cluster_id, uninstall_sw)) # get kube and helm directories _kube_dir, helm_dir, config_filename, _cluster_dir = self._get_paths( cluster_name=cluster_id, create_if_not_exist=False ) - # uninstall releases if needed - releases = await self.instances_list(cluster_uuid=cluster_uuid) - if len(releases) > 0: - if force: - for r in releases: - try: - kdu_instance = r.get("Name") - chart = r.get("Chart") - self.log.debug( - "Uninstalling {} -> {}".format(chart, kdu_instance) - ) - await self.uninstall( - cluster_uuid=cluster_uuid, kdu_instance=kdu_instance - ) - except Exception as e: - self.log.error( - "Error uninstalling release {}: {}".format(kdu_instance, e) - ) - else: - msg = ( - "Cluster has releases and not force. Cannot reset K8s " - "environment. Cluster uuid: {}" - ).format(cluster_id) - self.log.error(msg) - raise K8sException(msg) + # uninstall releases if needed. + if uninstall_sw: + releases = await self.instances_list(cluster_uuid=cluster_uuid) + if len(releases) > 0: + if force: + for r in releases: + try: + kdu_instance = r.get("Name") + chart = r.get("Chart") + self.log.debug( + "Uninstalling {} -> {}".format(chart, kdu_instance) + ) + await self.uninstall( + cluster_uuid=cluster_uuid, kdu_instance=kdu_instance + ) + except Exception as e: + self.log.error( + "Error uninstalling release {}: {}".format(kdu_instance, e) + ) + else: + msg = ( + "Cluster uuid: {} has releases and not force. Leaving K8s helm environment" + ).format(cluster_id) + self.log.warn(msg) + uninstall_sw = False # Allow to remove k8s cluster without removing Tiller if uninstall_sw: -- 2.17.1