From b0a42c20cab01e6372fcc7572d179a8b4ec16f7a Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Wed, 13 Nov 2024 16:00:10 +0100 Subject: [PATCH] Check of kustomizations and managed resources for cluster registration and cluster update Change-Id: Id137bd9161ceb4c4286d2b22a563f8083f930e2e Signed-off-by: garciadeblas --- osm_lcm/k8s.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index fb4a063f..4840329e 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -152,6 +152,12 @@ class ClusterLcm(GitOpsLcm): "create_cluster": { "check_resource_function": self.check_create_cluster, }, + "register_cluster": { + "check_resource_function": self.check_register_cluster, + }, + "update_cluster": { + "check_resource_function": self.check_update_cluster, + }, } self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config) @@ -289,6 +295,89 @@ class ClusterLcm(GitOpsLcm): checkings_list.insert(3, nodepool_check) return await self.common_check_list(checkings_list, "clusters", db_cluster) + async def check_register_cluster(self, op_id, op_params, content): + self.logger.info( + f"check_register_cluster Operation {op_id}. Params: {op_params}." + ) + # self.logger.debug(f"Content: {content}") + db_cluster = content["cluster"] + cluster_name = db_cluster["git_name"].lower() + cluster_kustomization_name = cluster_name + bootstrap = op_params.get("bootstrap", True) + checkings_list = [ + { + "item": "kustomization", + "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", + "namespace": "managed-resources", + "flag": "Ready", + "timeout": self._checkloop_kustomization_timeout, + "enable": bootstrap, + "resourceState": "IN_PROGRESS.BOOTSTRAP_OK", + }, + ] + return await self.common_check_list(checkings_list, "clusters", db_cluster) + + async def check_update_cluster(self, op_id, op_params, content): + self.logger.info( + f"check_create_cluster Operation {op_id}. Params: {op_params}." + ) + # self.logger.debug(f"Content: {content}") + db_cluster = content["cluster"] + cluster_name = db_cluster["git_name"].lower() + cluster_kustomization_name = cluster_name + db_vim_account = content["vim_account"] + cloud_type = db_vim_account["vim_type"] + nodepool_name = "" + if cloud_type == "aws": + nodepool_name = f"{cluster_name}-nodegroup" + cluster_name = f"{cluster_name}-cluster" + elif cloud_type == "gcp": + nodepool_name = f"nodepool-{cluster_name}" + if cloud_type in ("azure", "gcp", "aws"): + checkings_list = [ + { + "item": "kustomization", + "name": cluster_kustomization_name, + "namespace": "managed-resources", + "flag": "Ready", + "timeout": self._checkloop_kustomization_timeout, + "enable": True, + "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY", + }, + { + "item": f"cluster_{cloud_type}", + "name": cluster_name, + "namespace": "", + "flag": "Synced", + "timeout": self._checkloop_resource_timeout, + "enable": True, + "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER", + }, + { + "item": f"cluster_{cloud_type}", + "name": cluster_name, + "namespace": "", + "flag": "Ready", + "timeout": self._checkloop_resource_timeout, + "enable": True, + "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER", + }, + ] + else: + return False, "Not suitable VIM account to check cluster status" + if nodepool_name: + nodepool_check = { + "item": f"nodepool_{cloud_type}", + "name": nodepool_name, + "namespace": "", + "flag": "Ready", + "timeout": self._checkloop_resource_timeout, + "enable": True, + "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL", + } + checkings_list.append(nodepool_check) + return await self.common_check_list(checkings_list, "clusters", db_cluster) + def update_profile_state(self, db_cluster, workflow_status, resource_status): profiles = [ "infra_controller_profiles", -- 2.25.1