From: yshah Date: Tue, 11 Feb 2025 12:37:04 +0000 (+0000) Subject: Delete KSU from DB while deleting default and non-default profiles X-Git-Tag: v17.0.1~5 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=4998f50fc96b23c71ff620b7f7a352804e51fa30;p=osm%2FLCM.git Delete KSU from DB while deleting default and non-default profiles Change-Id: Ia50335512cb5a39f881cea4c2f49af8acf40662c Signed-off-by: yshah Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 3a0e2d0b..58337ac0 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -50,6 +50,13 @@ class GitOpsLcm(LcmBase): "app_profiles": "k8sapp", } + profile_type_mapping = { + "infra-controllers": "infra_controller_profiles", + "infra-configs": "infra_config_profiles", + "managed-resources": "resource_profiles", + "applications": "app_profiles", + } + def __init__(self, msg, lcm_tasks, config): self.logger = logging.getLogger("lcm.gitops") self.lcm_tasks = lcm_tasks @@ -274,6 +281,13 @@ class GitOpsLcm(LcmBase): ) return content_copy + def delete_profile_ksu(self, _id, profile_type): + filter_q = {"profile": {"_id": _id, "profile_type": profile_type}} + ksu_list = self.db.get_list("ksus", filter_q) + if ksu_list: + self.db.del_list("ksus", filter_q) + return + def cluster_kubectl(self, db_cluster): cluster_kubeconfig = db_cluster["credentials"] kubeconfig_path = f"/tmp/{db_cluster['_id']}_kubeconfig.yaml" @@ -725,6 +739,7 @@ class ClusterLcm(GitOpsLcm): "the db_profile name is :{}".format(db_profile["name"]) ) if db_cluster["name"] == db_profile["name"]: + self.delete_profile_ksu(profile_id, profile_type) self.db.del_one(db_collection, {"_id": profile_id}) else: profile_ids.remove(profile_id) @@ -1520,6 +1535,8 @@ class K8sAppLcm(GitOpsLcm): if resource_status: content["state"] = "DELETED" + profile_type = self.profile_type_mapping[content["profile_type"]] + self.delete_profile_ksu(profile_id, profile_type) self.db.set_one(self.db_collection, {"_id": content["_id"]}, content) self.db.del_one(self.db_collection, {"_id": content["_id"]}) self.logger.info(f"App Delete Exit with resource status: {resource_status}") @@ -1598,6 +1615,8 @@ class K8sResourceLcm(GitOpsLcm): if resource_status: content["state"] = "DELETED" + profile_type = self.profile_type_mapping[content["profile_type"]] + self.delete_profile_ksu(profile_id, profile_type) self.db.set_one(self.db_collection, {"_id": content["_id"]}, content) self.db.del_one(self.db_collection, {"_id": content["_id"]}) self.logger.info( @@ -1678,6 +1697,8 @@ class K8sInfraControllerLcm(GitOpsLcm): if resource_status: content["state"] = "DELETED" + profile_type = self.profile_type_mapping[content["profile_type"]] + self.delete_profile_ksu(profile_id, profile_type) self.db.set_one(self.db_collection, {"_id": content["_id"]}, content) self.db.del_one(self.db_collection, {"_id": content["_id"]}) self.logger.info( @@ -1758,6 +1779,8 @@ class K8sInfraConfigLcm(GitOpsLcm): if resource_status: content["state"] = "DELETED" + profile_type = self.profile_type_mapping[content["profile_type"]] + self.delete_profile_ksu(profile_id, profile_type) self.db.set_one(self.db_collection, {"_id": content["_id"]}, content) self.db.del_one(self.db_collection, {"_id": content["_id"]}) self.logger.info(