# 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)
+ 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,
return paths, env
+ 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))