"create_cluster": {
"check_resource_function": self.check_create_cluster,
},
- "deregister_cluster": {
- "check_resource_function": self.check_deregister_cluster,
- },
}
self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config)
db_cluster = self.update_operation_history(db_cluster, workflow_status, None)
self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
+ # Clean items used in the workflow or in the cluster, no matter if the workflow succeeded
+ clean_status, clean_msg = await self.odu.clean_items_workflow(
+ "deregister_cluster", 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.check_resource_status(
"deregister_cluster", op_id, op_params, content
self.db.del_one("clusters", {"_id": db_cluster["_id"]})
return
- async def check_deregister_cluster(self, op_id, op_params, content):
- self.logger.info(
- f"check_deregister_cluster Operation {op_id}. Params: {op_params}."
- )
- # self.logger.debug(f"Content: {content}")
- # Clean secrets
- self.logger.info("Cleaning kubeconfig")
- cluster_name = content["cluster"]["git_name"].lower()
- items = {
- "secrets": [
- {
- "name": f"kubeconfig-{cluster_name}",
- "namespace": "managed-resources",
- },
- ]
- }
-
- try:
- await self.odu.clean_items(items)
- except Exception as e:
- return False, f"Error while cleaning items: {e}"
- return True, "OK"
-
async def get_creds(self, op_id, db_cluster):
self.logger.info("Cluster get creds Enter")
result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster)
secret_value2 = yaml.safe_dump(
db_cluster["credentials"], indent=4, default_flow_style=False, sort_keys=False
)
- await self.create_secret(
- secret_name2,
- secret_namespace2,
- secret_key2,
- secret_value2,
- )
+ try:
+ await self.create_secret(
+ secret_name2,
+ secret_namespace2,
+ secret_key2,
+ secret_value2,
+ )
+ except Exception as e:
+ self.logger.info(
+ f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
+ )
+ return False, ""
# Additional params for the workflow
cluster_kustomization_name = cluster_name
return True, "OK"
except Exception as e:
return False, f"Error while cleaning items: {e}"
+
+
+async def clean_items_cluster_deregister(self, op_id, op_params, content):
+ self.logger.info(
+ f"clean_items_cluster_deregister Enter. Operation {op_id}. Params: {op_params}"
+ )
+ # self.logger.debug(f"Content: {content}")
+ # Clean secrets
+ self.logger.info("Cleaning kubeconfig")
+ cluster_name = content["cluster"]["git_name"].lower()
+ items = {
+ "secrets": [
+ {
+ "name": f"kubeconfig-{cluster_name}",
+ "namespace": "managed-resources",
+ },
+ ]
+ }
+
+ try:
+ await self.clean_items(items)
+ return True, "OK"
+ except Exception as e:
+ return False, f"Error while cleaning items: {e}"
},
"deregister_cluster": {
"workflow_function": self.deregister_cluster,
+ "clean_function": self.clean_items_cluster_deregister,
},
"create_profile": {
"workflow_function": self.create_profile,
clean_items_cluster_create,
clean_items_cluster_update,
clean_items_cluster_register,
+ clean_items_cluster_deregister,
get_cluster_credentials,
)
from osm_lcm.odu_libs.ksu import (