+
+ def _obtain_namespace(self, kdu_instance: str, namespace: str = None) -> str:
+ """
+ Obtain the namespace/model name to use in the instantiation of a Juju Bundle in K8s. The default namespace is
+ the kdu_instance name. However, if the user passes the namespace where he wants to deploy the bundle,
+ that namespace will be used.
+
+ :param kdu_instance: the default KDU instance name
+ :param namespace: the namespace passed by the User
+ """
+
+ # deault the namespace/model name to the kdu_instance name TODO -> this should be the real return... But
+ # once the namespace is not passed in most methods, I had to do this in another way. But I think this should
+ # be the procedure in the future return namespace if namespace else kdu_instance
+
+ # TODO -> has referred above, this should be avoided in the future, this is temporary, in order to avoid
+ # compatibility issues
+ return (
+ namespace
+ if namespace
+ else self._obtain_namespace_from_db(kdu_instance=kdu_instance)
+ )
+
+ def _obtain_namespace_from_db(self, kdu_instance: str) -> str:
+ db_nsrs = self.db.get_one(
+ table="nsrs", q_filter={"_admin.deployed.K8s.kdu-instance": kdu_instance}
+ )
+ for k8s in db_nsrs["_admin"]["deployed"]["K8s"]:
+ if k8s.get("kdu-instance") == kdu_instance:
+ return k8s.get("namespace")
+ return ""