Fix checks for KSU update operations 98/14898/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 27 Jan 2025 17:31:06 +0000 (18:31 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 27 Jan 2025 17:31:06 +0000 (18:31 +0100)
Change-Id: I4dd187183b6c5c13cfae9eab7069456a9c0733b1
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/k8s.py

index 5d3cca4..dda07fb 100644 (file)
@@ -1175,29 +1175,66 @@ class ClusterLcm(GitOpsLcm):
             f"check_update_cluster Operation {op_id}. Params: {op_params}."
         )
         self.logger.debug(f"Content: {content}")
-        return await self.check_dummy_operation(op_id, op_params, content)
-        # db_cluster = content["cluster"]
-        # cluster_id = db_cluster["_id"]
-        # cluster_kubectl = self.cluster_kubectl(db_cluster)
-        # cluster_name = db_cluster["git_name"].lower()
-        # cluster_kustomization_name = cluster_name
-        # checkings_list = [
-        #     {
-        #         "item": "kustomization",
-        #         "name": cluster_kustomization_name,
-        #         "namespace": "managed-resources",
-        #         "condition": {
-        #             "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
-        #             "value": "True",
-        #         },
-        #         "timeout": self._checkloop_kustomization_timeout,
-        #         "enable": True,
-        #         "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
-        #     },
-        # ]
-        # return await self.common_check_list(
-        #     op_id, checkings_list, "clusters", db_cluster, cluster_kubectl
-        # )
+        # return await self.check_dummy_operation(op_id, op_params, 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"]
+        if cloud_type == "aws":
+            cluster_name = f"{cluster_name}-cluster"
+        if cloud_type in ("azure", "gcp", "aws"):
+            checkings_list = [
+                {
+                    "item": "kustomization",
+                    "name": cluster_kustomization_name,
+                    "namespace": "managed-resources",
+                    "condition": {
+                        "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+                        "value": "True",
+                    },
+                    "timeout": self._checkloop_kustomization_timeout,
+                    "enable": True,
+                    "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
+                },
+            ]
+        else:
+            return False, "Not suitable VIM account to check cluster status"
+        # Scale operation
+        if "node_count" in op_params:
+            checkings_list.append(
+                {
+                    "item": f"cluster_{cloud_type}",
+                    "name": cluster_name,
+                    "namespace": "",
+                    "condition": {
+                        "jsonpath_filter": "status.atProvider.defaultNodePool[0].nodeCount",
+                        "value": f"{op_params['node_count']}",
+                    },
+                    "timeout": self._checkloop_resource_timeout * 2,
+                    "enable": True,
+                    "resourceState": "IN_PROGRESS.RESOURCE_READY.NODE_COUNT.CLUSTER",
+                }
+            )
+        # Upgrade operation
+        if "k8s_version" in op_params:
+            checkings_list.append(
+                {
+                    "item": f"cluster_{cloud_type}",
+                    "name": cluster_name,
+                    "namespace": "",
+                    "condition": {
+                        "jsonpath_filter": "status.atProvider.defaultNodePool[0].orchestratorVersion",
+                        "value": op_params["k8s_version"],
+                    },
+                    "timeout": self._checkloop_resource_timeout * 2,
+                    "enable": True,
+                    "resourceState": "IN_PROGRESS.RESOURCE_READY.K8S_VERSION.CLUSTER",
+                }
+            )
+        return await self.common_check_list(
+            op_id, checkings_list, "clusters", db_cluster
+        )
 
 
 class CloudCredentialsLcm(GitOpsLcm):