X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=n2vc%2Fk8s_helm3_conn.py;h=68ad37e236157d39eb4d970eeb70f8972cbfccca;hb=227153dbd708538f04622a2c59722c2270b7bd5d;hp=f79816d6c014cf1a0f54467bd95360ca0dfee7cc;hpb=137dc9e1040534b64b19f4b556ced242e798356b;p=osm%2FN2VC.git diff --git a/n2vc/k8s_helm3_conn.py b/n2vc/k8s_helm3_conn.py index f79816d..68ad37e 100644 --- a/n2vc/k8s_helm3_conn.py +++ b/n2vc/k8s_helm3_conn.py @@ -71,6 +71,7 @@ class K8sHelm3Connector(K8sHelmBaseConnector): self, cluster_uuid: str, kdu_model: str, + kdu_instance: str, atomic: bool = True, timeout: float = 300, params: dict = None, @@ -91,26 +92,39 @@ class K8sHelm3Connector(K8sHelmBaseConnector): # for helm3 if namespace does not exist must create it if namespace and namespace != "kube-system": - namespaces = await self._get_namespaces(cluster_id) - if namespace not in namespaces: - await self._create_namespace(cluster_id, namespace) - - kdu_instance = await self._install_impl(cluster_id, - kdu_model, - paths, - env, - atomic=atomic, - timeout=timeout, - params=params, - db_dict=db_dict, - kdu_name=kdu_name, - namespace=namespace) + if not await self._namespace_exists(cluster_id, namespace): + try: + await self._create_namespace(cluster_id, namespace) + except Exception as e: + if not await self._namespace_exists(cluster_id, namespace): + err_msg = ( + "namespace {} does not exist in cluster_id {} " + "error message: ".format( + namespace, e + ) + ) + self.log.error(err_msg) + raise K8sException(err_msg) + + await self._install_impl( + cluster_id, + kdu_model, + paths, + env, + kdu_instance, + atomic=atomic, + timeout=timeout, + params=params, + db_dict=db_dict, + kdu_name=kdu_name, + namespace=namespace, + ) # sync fs self.fs.reverse_sync(from_path=cluster_id) self.log.debug("Returning kdu_instance {}".format(kdu_instance)) - return kdu_instance + return True async def inspect_kdu(self, kdu_model: str, repo_url: str = None) -> str: @@ -204,8 +218,16 @@ class K8sHelm3Connector(K8sHelmBaseConnector): return paths, env - async def _get_namespaces(self, - cluster_id: str): + async def _namespace_exists(self, cluster_id, namespace) -> bool: + self.log.debug( + "checking if namespace {} exists cluster_id {}".format( + namespace, cluster_id + ) + ) + namespaces = await self._get_namespaces(cluster_id) + return namespace in namespaces if namespaces else False + + async def _get_namespaces(self, cluster_id: str): self.log.debug("get namespaces cluster_id {}".format(cluster_id))