Skip to content
Snippets Groups Projects
Commit 6bad889d authored by Shahithya Y's avatar Shahithya Y
Browse files

Delete KSU from DB while deleting default and non-default profiles


Change-Id: Ia50335512cb5a39f881cea4c2f49af8acf40662c
Signed-off-by: default avataryshah <shahithya.y@tataelxsi.co.in>
parent b23d2dc5
No related branches found
No related tags found
No related merge requests found
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment