Bug 2000 fixed: the namespace for the Juju Bundle is now updated within the KDU insta... 09/11909/14
authorPedro Escaleira <escaleira@av.it.pt>
Thu, 21 Apr 2022 15:31:06 +0000 (16:31 +0100)
committerescaleira <escaleira@av.it.pt>
Mon, 30 May 2022 17:36:58 +0000 (19:36 +0200)
Change-Id: If0d863ad8a9c53c12a9385e68bf3bf9d4cb06682
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
osm_lcm/lcm_helm_conn.py
osm_lcm/lcm_utils.py
osm_lcm/ns.py

index 6fd3374..c8ba44d 100644 (file)
@@ -301,6 +301,10 @@ class LCMHelmConn(N2VCConnector, LcmBase):
         # not used for this connector
         pass
 
+    async def upgrade_charm(self, *args, **kwargs):
+        # not used for this connector
+        pass
+
     async def get_ee_ssh_public__key(
         self,
         ee_id: str,
index 235d485..4ec9d49 100644 (file)
@@ -169,8 +169,8 @@ class LcmBase:
     def update_db_2(self, item, _id, _desc):
         """
         Updates database with _desc information. If success _desc is cleared
-        :param item:
-        :param _id:
+        :param item: collection
+        :param _id: the _id to use in the query filter
         :param _desc: dictionary with the content to update. Keys are dot separated keys for
         :return: None. Exception is raised on error
         """
index c79d362..1cbd93a 100644 (file)
@@ -3201,9 +3201,45 @@ class NsLcm(LcmBase):
                     kdu_model=k8s_instance_info["kdu-model"],
                     kdu_name=k8s_instance_info["kdu-name"],
                 )
+
+            # Update the nsrs table with the kdu-instance value
             self.update_db_2(
-                "nsrs", nsr_id, {nsr_db_path + ".kdu-instance": kdu_instance}
+                item="nsrs",
+                _id=nsr_id,
+                _desc={nsr_db_path + ".kdu-instance": kdu_instance},
             )
+
+            # Update the nsrs table with the actual namespace being used, if the k8scluster-type is `juju` or
+            # `juju-bundle`. This verification is needed because there is not a standard/homogeneous namespace
+            # between the Helm Charts and Juju Bundles-based KNFs. If we found a way of having an homogeneous
+            # namespace, this first verification could be removed, and the next step would be done for any kind
+            # of KNF.
+            # TODO -> find a way to have an homogeneous namespace between the Helm Charts and Juju Bundles-based
+            # KNFs (Bug 2027: https://osm.etsi.org/bugzilla/show_bug.cgi?id=2027)
+            if k8sclustertype in ("juju", "juju-bundle"):
+                # First, verify if the current namespace is present in the `_admin.projects_read` (if not, it means
+                # that the user passed a namespace which he wants its KDU to be deployed in)
+                if (
+                    self.db.count(
+                        table="nsrs",
+                        q_filter={
+                            "_id": nsr_id,
+                            "_admin.projects_write": k8s_instance_info["namespace"],
+                            "_admin.projects_read": k8s_instance_info["namespace"],
+                        },
+                    )
+                    > 0
+                ):
+                    self.logger.debug(
+                        f"Updating namespace/model for Juju Bundle from {k8s_instance_info['namespace']} to {kdu_instance}"
+                    )
+                    self.update_db_2(
+                        item="nsrs",
+                        _id=nsr_id,
+                        _desc={f"{nsr_db_path}.namespace": kdu_instance},
+                    )
+                    k8s_instance_info["namespace"] = kdu_instance
+
             await self.k8scluster_map[k8sclustertype].install(
                 cluster_uuid=k8s_instance_info["k8scluster-uuid"],
                 kdu_model=k8s_instance_info["kdu-model"],
@@ -3216,9 +3252,6 @@ class NsLcm(LcmBase):
                 kdu_instance=kdu_instance,
                 vca_id=vca_id,
             )
-            self.update_db_2(
-                "nsrs", nsr_id, {nsr_db_path + ".kdu-instance": kdu_instance}
-            )
 
             # Obtain services to obtain management service ip
             services = await self.k8scluster_map[k8sclustertype].get_services(