From b3dbc7f7e1360f20df4fd167310d0c31403661e3 Mon Sep 17 00:00:00 2001 From: SAGNIK PAL Date: Tue, 21 Jan 2025 15:49:33 +0530 Subject: [PATCH 1/2] Fix for getMeshSyncStatus Signed-off-by: SAGNIK PAL --- models/controllers/meshery_operator.go | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/models/controllers/meshery_operator.go b/models/controllers/meshery_operator.go index fe5e5814..555b0ed8 100644 --- a/models/controllers/meshery_operator.go +++ b/models/controllers/meshery_operator.go @@ -8,6 +8,7 @@ import ( mesherykube "github.com/layer5io/meshkit/utils/kubernetes" kubeerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/kubectl/pkg/polymorphichelpers" ) @@ -63,8 +64,36 @@ func (mo *mesheryOperator) GetStatus() MesheryControllerStatus { mo.setStatus(Unknown) return mo.status } - if done { - mo.setStatus(Deployed) + + // Check if deployment is ready and running + if done { + // Get status + status, found, err := unstructured.NestedMap(deployment.Object, "status") + if err != nil || !found { + mo.setStatus(Unknown) + return mo.status + } + + // Get readyReplicas + readyReplicas, found, err := unstructured.NestedInt64(deployment.Object, "readyReplicas") + if err != nil || !found { + mo.setStatus(Unknown) + return mo.status + } + + // Get replicas + replicas, found, err := unstructured.NestedInt64(status, "replicas") + if err != nil || !found { + mo.setStatus(Unknown) + return mo.status + } + + // check if all replicas are ready + if readyReplicas > 0 && readyReplicas == replicas { + mo.setStatus(Connected) + } else { + mo.setStatus(Deployed) + } } else { mo.setStatus(Deploying) } From 99ce5b28c6d4c2f6d322035a88b6831719ef6329 Mon Sep 17 00:00:00 2001 From: Sagnik Pal <112897062+palSagnik@users.noreply.github.com> Date: Tue, 21 Jan 2025 21:45:02 +0530 Subject: [PATCH 2/2] additional fixes for meshSyncStatus Signed-off-by: Sagnik Pal <112897062+palSagnik@users.noreply.github.com> --- models/controllers/meshery_operator.go | 30 ++------------------------ 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/models/controllers/meshery_operator.go b/models/controllers/meshery_operator.go index 555b0ed8..f8e1874d 100644 --- a/models/controllers/meshery_operator.go +++ b/models/controllers/meshery_operator.go @@ -67,35 +67,9 @@ func (mo *mesheryOperator) GetStatus() MesheryControllerStatus { // Check if deployment is ready and running if done { - // Get status - status, found, err := unstructured.NestedMap(deployment.Object, "status") - if err != nil || !found { - mo.setStatus(Unknown) - return mo.status - } - - // Get readyReplicas - readyReplicas, found, err := unstructured.NestedInt64(deployment.Object, "readyReplicas") - if err != nil || !found { - mo.setStatus(Unknown) - return mo.status - } - - // Get replicas - replicas, found, err := unstructured.NestedInt64(status, "replicas") - if err != nil || !found { - mo.setStatus(Unknown) - return mo.status - } - - // check if all replicas are ready - if readyReplicas > 0 && readyReplicas == replicas { - mo.setStatus(Connected) - } else { - mo.setStatus(Deployed) - } + mo.setStatus(Connected) } else { - mo.setStatus(Deploying) + mo.setStatus(Deployed) } return mo.status }