Skip to content
Snippets Groups Projects
Commit b23d2dc5 authored by garciadeblas's avatar garciadeblas
Browse files

Clean-up of resources created in OKA workflows


Change-Id: I1a0ce2de88bd3e77036724a34c9423385c340b6d
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 167dde3e
No related branches found
No related tags found
No related merge requests found
Pipeline #18521 passed with warnings with stage
in 5 minutes and 32 seconds
......@@ -1799,6 +1799,14 @@ class OkaLcm(GitOpsLcm):
"create_oka", op_id, op_params, db_content
)
self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
"create_oka", op_id, op_params, db_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
)
self.logger.info(f"OKA Create Exit with resource status: {resource_status}")
return
......@@ -1822,6 +1830,13 @@ class OkaLcm(GitOpsLcm):
"update_oka", op_id, op_params, db_content
)
self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
"update_oka", op_id, op_params, db_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
)
self.logger.info(f"OKA Update Exit with resource status: {resource_status}")
return
......@@ -1849,6 +1864,13 @@ class OkaLcm(GitOpsLcm):
db_content["state"] == "DELETED"
self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content)
self.db.del_one(self.db_collection, {"_id": db_content["_id"]})
# Clean items used in the workflow, no matter if the workflow succeeded
clean_status, clean_msg = await self.odu.clean_items_workflow(
"delete_oka", op_id, op_params, db_content
)
self.logger.info(
f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
)
self.logger.info(f"OKA Delete Exit with resource status: {resource_status}")
return
......
......@@ -427,3 +427,11 @@ async def clean_items_ksu_update(self, op_id, op_params_list, content_list):
)
# self.logger.debug(f"Content: {content_list}")
return await self.clean_items_ksu_create(op_id, op_params_list, content_list)
async def clean_items_ksu_delete(self, op_id, op_params_list, content_list):
self.logger.info(
f"clean_items_ksu_delete Enter. Operation {op_id}. Params: {op_params_list}"
)
# self.logger.debug(f"Content: {content_list}")
return True, "OK"
......@@ -179,3 +179,46 @@ async def delete_oka(self, op_id, op_params, content):
api_version="v1alpha1",
)
return True, workflow_name
async def clean_items_oka_create(self, op_id, op_params_list, content_list):
self.logger.info(
f"clean_items_oka_create Enter. Operation {op_id}. Params: {op_params_list}"
)
# self.logger.debug(f"Content: {content_list}")
volume_name = f"temp-pvc-oka-{op_id}"
try:
items = {
"pods": [
{
"name": f"copy-pod-{volume_name}",
"namespace": "osm-workflows",
}
],
"pvcs": [
{
"name": volume_name,
"namespace": "osm-workflows",
}
],
}
await self.clean_items(items)
return True, "OK"
except Exception as e:
return False, f"Error while cleaning items: {e}"
async def clean_items_oka_update(self, op_id, op_params_list, content_list):
self.logger.info(
f"clean_items_oka_update Enter. Operation {op_id}. Params: {op_params_list}"
)
# self.logger.debug(f"Content: {content_list}")
return await self.clean_items_oka_create(op_id, op_params_list, content_list)
async def clean_items_oka_delete(self, op_id, op_params_list, content_list):
self.logger.info(
f"clean_items_oka_delete Enter. Operation {op_id}. Params: {op_params_list}"
)
# self.logger.debug(f"Content: {content_list}")
return True, "OK"
......@@ -76,12 +76,15 @@ class OduWorkflow(LcmBase):
},
"create_oka": {
"workflow_function": self.create_oka,
"clean_function": self.clean_items_oka_create,
},
"update_oka": {
"workflow_function": self.update_oka,
"clean_function": self.clean_items_oka_update,
},
"delete_oka": {
"workflow_function": self.delete_oka,
"clean_function": self.clean_items_oka_delete,
},
"create_ksus": {
"workflow_function": self.create_ksus,
......@@ -150,11 +153,15 @@ class OduWorkflow(LcmBase):
move_ksu,
clean_items_ksu_create,
clean_items_ksu_update,
clean_items_ksu_delete,
)
from osm_lcm.odu_libs.oka import (
create_oka,
update_oka,
delete_oka,
clean_items_oka_create,
clean_items_oka_update,
clean_items_oka_delete,
)
from osm_lcm.odu_libs.profiles import (
create_profile,
......@@ -211,6 +218,19 @@ class OduWorkflow(LcmBase):
return content["workflow_name"]
async def clean_items(self, items):
# Delete pods
for pod in items.get("pods", []):
name = pod["name"]
namespace = pod["namespace"]
self.logger.info(f"Deleting pod {name} in namespace {namespace}")
self.logger.debug(f"Testing kubectl: {self._kubectl}")
self.logger.debug(
f"Testing kubectl configuration: {self._kubectl.configuration}"
)
self.logger.debug(
f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
)
await self._kubectl.delete_pod(name, namespace)
# Delete secrets
for secret in items.get("secrets", []):
name = secret["name"]
......
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