db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
+ # Clean items used in the workflow, no matter if the workflow succeeded
+ clean_status, clean_msg = await self.odu.clean_items_workflow(
+ "create_ksus", op_id, op_params, content
+ )
+ self.logger.info(
+ f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
+ )
+
if workflow_status:
resource_status, resource_msg = await self.odu.check_resource_status(
"create_ksus", op_id, op_params, content
db_ksu = self.update_operation_history(db_ksu, workflow_status, None)
self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu)
+ # Clean items used in the workflow, no matter if the workflow succeeded
+ clean_status, clean_msg = await self.odu.clean_items_workflow(
+ "create_ksus", op_id, op_params, content
+ )
+ self.logger.info(
+ f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
+ )
if workflow_status:
resource_status, resource_msg = await self.odu.check_resource_status(
"update_ksus", op_id, op_params, content
return workflow_name
+async def clean_items_ksu_create(self, op_id, op_params_list, content_list):
+ self.logger.info("Clean items ksu_create Enter")
+ self.logger.info(
+ f"Operation {op_id}. Params: {op_params_list}. Content: {content_list}"
+ )
+ try:
+ if len(content_list) > 1:
+ raise Exception("There is no ODU workflow yet able to manage multiple KSUs")
+ db_ksu = content_list[0]
+ ksu_name = db_ksu["git_name"].lower()
+ ksu_params = op_params_list[0]
+ oka_list = ksu_params["oka"]
+ if len(oka_list) > 1:
+ raise Exception(
+ "There is no ODU workflow yet able to manage multiple OKAs for a KSU"
+ )
+ oka_item = oka_list[0]
+ oka_params = oka_item.get("transformation", {})
+ secret_values = oka_params.get("secret_values", "")
+ if secret_values:
+ items = {
+ "secrets": [
+ {
+ "name": f"ref-secret-{ksu_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_ksu_update(self, op_id, op_params_list, content_list):
+ self.logger.info("Clean items ksu_update Enter")
+ self.logger.info(
+ f"Operation {op_id}. Params: {op_params_list}. Content: {content_list}"
+ )
+ return await self.clean_items_ksu_create(op_id, op_params_list, content_list)
+
+
async def check_create_ksus(self, op_id, op_params, content):
self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}")
return True, "OK"
},
"create_ksus": {
"workflow_function": self.create_ksus,
+ "clean_function": self.clean_items_ksu_create,
"check_resource_function": self.check_create_ksus,
},
"update_ksus": {
"workflow_function": self.update_ksus,
+ "clean_function": self.clean_items_ksu_update,
"check_resource_function": self.check_update_ksus,
},
"delete_ksus": {
delete_ksus,
clone_ksu,
move_ksu,
+ clean_items_ksu_create,
+ clean_items_ksu_update,
check_create_ksus,
check_update_ksus,
check_delete_ksus,