From 933ebebff00daa5992615e23703d3d6970e245f8 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:39:36 +0800 Subject: [PATCH] WIP Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- .../apps/v2beta1/update_emqx_status.go | 26 ++++--- e2e/v2beta1/e2e_test.go | 78 +++++-------------- 2 files changed, 32 insertions(+), 72 deletions(-) diff --git a/controllers/apps/v2beta1/update_emqx_status.go b/controllers/apps/v2beta1/update_emqx_status.go index ff0360e7..2fc52c61 100644 --- a/controllers/apps/v2beta1/update_emqx_status.go +++ b/controllers/apps/v2beta1/update_emqx_status.go @@ -114,18 +114,20 @@ func (u *updateStatus) reconcile(ctx context.Context, logger logr.Logger, instan } instance.Status.ReplicantNodes = replNodes - instance.Status.ReplicantNodesStatus.ReadyReplicas = 0 - instance.Status.ReplicantNodesStatus.CurrentReplicas = 0 - instance.Status.ReplicantNodesStatus.UpdateReplicas = 0 - for _, node := range replNodes { - if node.NodeStatus == "running" { - instance.Status.ReplicantNodesStatus.ReadyReplicas++ - } - if currentRs != nil && node.ControllerUID == currentRs.UID { - instance.Status.ReplicantNodesStatus.CurrentReplicas++ - } - if updateRs != nil && node.ControllerUID == updateRs.UID { - instance.Status.ReplicantNodesStatus.UpdateReplicas++ + if instance.Status.ReplicantNodesStatus != nil { + instance.Status.ReplicantNodesStatus.ReadyReplicas = 0 + instance.Status.ReplicantNodesStatus.CurrentReplicas = 0 + instance.Status.ReplicantNodesStatus.UpdateReplicas = 0 + for _, node := range replNodes { + if node.NodeStatus == "running" { + instance.Status.ReplicantNodesStatus.ReadyReplicas++ + } + if currentRs != nil && node.ControllerUID == currentRs.UID { + instance.Status.ReplicantNodesStatus.CurrentReplicas++ + } + if updateRs != nil && node.ControllerUID == updateRs.UID { + instance.Status.ReplicantNodesStatus.UpdateReplicas++ + } } } diff --git a/e2e/v2beta1/e2e_test.go b/e2e/v2beta1/e2e_test.go index d5de4d90..9cbd2df5 100644 --- a/e2e/v2beta1/e2e_test.go +++ b/e2e/v2beta1/e2e_test.go @@ -80,16 +80,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { WithTransform(func(instance *appsv2beta1.EMQX) []appsv2beta1.EMQXNode { return instance.Status.ReplicantNodes }, BeNil()), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Equal("")), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Equal("")), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), ) @@ -138,16 +131,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { WithTransform(func(instance *appsv2beta1.EMQX) []appsv2beta1.EMQXNode { return instance.Status.ReplicantNodes }, BeNil()), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Equal("")), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Equal("")), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), ) @@ -196,16 +182,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { WithTransform(func(instance *appsv2beta1.EMQX) []appsv2beta1.EMQXNode { return instance.Status.ReplicantNodes }, BeNil()), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Equal("")), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Equal("")), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), ) @@ -248,16 +227,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateRevision", Not(Equal(storage.Status.CoreNodesStatus.CurrentRevision))), HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Equal("")), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Equal("")), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), ) @@ -483,16 +455,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { WithTransform(func(instance *appsv2beta1.EMQX) []appsv2beta1.EMQXNode { return instance.Status.ReplicantNodes }, HaveLen(int(*instance.Spec.ReplicantTemplate.Spec.Replicas))), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Equal(storage.Status.ReplicantNodesStatus.CurrentRevision)), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Equal(storage.Status.ReplicantNodesStatus.CurrentRevision)), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), ) @@ -588,16 +553,9 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateRevision", Not(Equal(storage.Status.CoreNodesStatus.CurrentRevision))), HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), - WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return *instance.Status.ReplicantNodesStatus - }, And( - HaveField("Replicas", Equal(int32(0))), - HaveField("ReadyReplicas", Equal(int32(0))), - HaveField("CurrentRevision", Not(Equal(storage.Status.ReplicantNodesStatus.CurrentRevision))), - HaveField("CurrentReplicas", Equal(int32(0))), - HaveField("UpdateRevision", Not(Equal(storage.Status.ReplicantNodesStatus.CurrentRevision))), - HaveField("UpdateReplicas", Equal(int32(0))), - )), + WithTransform(func(instance *appsv2beta1.EMQX) *appsv2beta1.EMQXNodesStatus { + return instance.Status.ReplicantNodesStatus + }, BeNil()), ), )