From ca7c2146d51eaf6094248b1f55f9d053ed2340fb Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:19:15 +0800 Subject: [PATCH] WIP Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- apis/apps/v2beta1/status.go | 8 ++--- apis/apps/v2beta1/zz_generated.deepcopy.go | 12 +++++-- .../apps/v2beta1/add_emqx_core_test.go | 2 +- .../apps/v2beta1/add_emqx_repl_suite_test.go | 2 +- .../apps/v2beta1/add_emqx_repl_test.go | 2 +- .../apps/v2beta1/sync_pods_suite_test.go | 6 ++-- e2e/v2beta1/e2e_test.go | 36 +++++++++---------- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/apis/apps/v2beta1/status.go b/apis/apps/v2beta1/status.go index cf8528dc..25af00ac 100644 --- a/apis/apps/v2beta1/status.go +++ b/apis/apps/v2beta1/status.go @@ -28,11 +28,11 @@ type EMQXStatus struct { // Represents the latest available observations of a EMQX Custom Resource current state. Conditions []metav1.Condition `json:"conditions,omitempty"` - CoreNodes []EMQXNode `json:"coreNodes,omitempty"` - CoreNodesStatus EMQXNodesStatus `json:"coreNodesStatus,omitempty"` + CoreNodes []EMQXNode `json:"coreNodes,omitempty"` + CoreNodesStatus *EMQXNodesStatus `json:"coreNodesStatus,omitempty"` - ReplicantNodes []EMQXNode `json:"replicantNodes,omitempty"` - ReplicantNodesStatus EMQXNodesStatus `json:"replicantNodesStatus,omitempty"` + ReplicantNodes []EMQXNode `json:"replicantNodes,omitempty"` + ReplicantNodesStatus *EMQXNodesStatus `json:"replicantNodesStatus,omitempty"` NodeEvacuationsStatus []NodeEvacuationStatus `json:"nodEvacuationsStatus,omitempty"` } diff --git a/apis/apps/v2beta1/zz_generated.deepcopy.go b/apis/apps/v2beta1/zz_generated.deepcopy.go index 77fed49a..2bfee1a0 100644 --- a/apis/apps/v2beta1/zz_generated.deepcopy.go +++ b/apis/apps/v2beta1/zz_generated.deepcopy.go @@ -412,13 +412,21 @@ func (in *EMQXStatus) DeepCopyInto(out *EMQXStatus) { *out = make([]EMQXNode, len(*in)) copy(*out, *in) } - in.CoreNodesStatus.DeepCopyInto(&out.CoreNodesStatus) + if in.CoreNodesStatus != nil { + in, out := &in.CoreNodesStatus, &out.CoreNodesStatus + *out = new(EMQXNodesStatus) + (*in).DeepCopyInto(*out) + } if in.ReplicantNodes != nil { in, out := &in.ReplicantNodes, &out.ReplicantNodes *out = make([]EMQXNode, len(*in)) copy(*out, *in) } - in.ReplicantNodesStatus.DeepCopyInto(&out.ReplicantNodesStatus) + if in.ReplicantNodesStatus != nil { + in, out := &in.ReplicantNodesStatus, &out.ReplicantNodesStatus + *out = new(EMQXNodesStatus) + (*in).DeepCopyInto(*out) + } if in.NodeEvacuationsStatus != nil { in, out := &in.NodeEvacuationsStatus, &out.NodeEvacuationsStatus *out = make([]NodeEvacuationStatus, len(*in)) diff --git a/controllers/apps/v2beta1/add_emqx_core_test.go b/controllers/apps/v2beta1/add_emqx_core_test.go index 82d42913..46b9c904 100644 --- a/controllers/apps/v2beta1/add_emqx_core_test.go +++ b/controllers/apps/v2beta1/add_emqx_core_test.go @@ -37,7 +37,7 @@ func TestGetNewStatefulSet(t *testing.T) { }, } instance.Spec.CoreTemplate.Spec.Replicas = ptr.To(int32(3)) - instance.Status.CoreNodesStatus = appsv2beta1.EMQXNodesStatus{ + instance.Status.CoreNodesStatus = &appsv2beta1.EMQXNodesStatus{ CollisionCount: ptr.To(int32(0)), } diff --git a/controllers/apps/v2beta1/add_emqx_repl_suite_test.go b/controllers/apps/v2beta1/add_emqx_repl_suite_test.go index 63eb3b08..05b3d27d 100644 --- a/controllers/apps/v2beta1/add_emqx_repl_suite_test.go +++ b/controllers/apps/v2beta1/add_emqx_repl_suite_test.go @@ -39,7 +39,7 @@ var _ = Describe("Check add repl controller", Ordered, Label("repl"), func() { }, } instance.Status = appsv2beta1.EMQXStatus{ - ReplicantNodesStatus: appsv2beta1.EMQXNodesStatus{ + ReplicantNodesStatus: &appsv2beta1.EMQXNodesStatus{ Replicas: 3, }, Conditions: []metav1.Condition{ diff --git a/controllers/apps/v2beta1/add_emqx_repl_test.go b/controllers/apps/v2beta1/add_emqx_repl_test.go index 2752f674..1e3ce886 100644 --- a/controllers/apps/v2beta1/add_emqx_repl_test.go +++ b/controllers/apps/v2beta1/add_emqx_repl_test.go @@ -40,7 +40,7 @@ func TestGetNewReplicaSet(t *testing.T) { Replicas: ptr.To(int32(3)), }, } - instance.Status.ReplicantNodesStatus = appsv2beta1.EMQXNodesStatus{ + instance.Status.ReplicantNodesStatus = &appsv2beta1.EMQXNodesStatus{ CollisionCount: ptr.To(int32(0)), } diff --git a/controllers/apps/v2beta1/sync_pods_suite_test.go b/controllers/apps/v2beta1/sync_pods_suite_test.go index 32864d33..0843661a 100644 --- a/controllers/apps/v2beta1/sync_pods_suite_test.go +++ b/controllers/apps/v2beta1/sync_pods_suite_test.go @@ -64,7 +64,7 @@ var _ = Describe("Check sync pods controller", Ordered, Label("node"), func() { LastTransitionTime: metav1.Time{Time: time.Now().AddDate(0, 0, -1)}, }, }, - CoreNodesStatus: appsv2beta1.EMQXNodesStatus{ + CoreNodesStatus: &appsv2beta1.EMQXNodesStatus{ UpdateRevision: "update", UpdateReplicas: 1, CurrentRevision: "current", @@ -72,7 +72,7 @@ var _ = Describe("Check sync pods controller", Ordered, Label("node"), func() { ReadyReplicas: 2, Replicas: 1, }, - ReplicantNodesStatus: appsv2beta1.EMQXNodesStatus{ + ReplicantNodesStatus: &appsv2beta1.EMQXNodesStatus{ UpdateRevision: "update", UpdateReplicas: 1, CurrentRevision: "current", @@ -334,7 +334,7 @@ var _ = Describe("check can be scale down", func() { Replicas: ptr.To(int32(3)), }, } - instance.Status.ReplicantNodesStatus = appsv2beta1.EMQXNodesStatus{ + instance.Status.ReplicantNodesStatus = &appsv2beta1.EMQXNodesStatus{ UpdateRevision: "update", CurrentRevision: "current", } diff --git a/e2e/v2beta1/e2e_test.go b/e2e/v2beta1/e2e_test.go index 661b0b61..d5de4d90 100644 --- a/e2e/v2beta1/e2e_test.go +++ b/e2e/v2beta1/e2e_test.go @@ -68,7 +68,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.CoreNodes }, HaveLen(int(*instance.Spec.CoreTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -81,7 +81,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.ReplicantNodes }, BeNil()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))), @@ -126,7 +126,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.CoreNodes }, HaveLen(int(*instance.Spec.CoreTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -139,7 +139,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.ReplicantNodes }, BeNil()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))), @@ -184,7 +184,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.CoreNodes }, HaveLen(int(*instance.Spec.CoreTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -197,7 +197,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.ReplicantNodes }, BeNil()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))), @@ -239,7 +239,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.IsConditionTrue(appsv2beta1.Ready) }, BeTrue()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -249,7 +249,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))), @@ -358,7 +358,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.IsConditionTrue(appsv2beta1.Ready) }, BeTrue()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -368,7 +368,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), @@ -413,7 +413,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.CoreNodes }, HaveLen(int(*instance.Spec.CoreTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -426,7 +426,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.ReplicantNodes }, HaveLen(int(*instance.Spec.ReplicantTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), @@ -471,7 +471,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.CoreNodes }, HaveLen(int(*instance.Spec.CoreTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -484,7 +484,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.ReplicantNodes }, HaveLen(int(*instance.Spec.ReplicantTemplate.Spec.Replicas))), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))), @@ -526,7 +526,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.IsConditionTrue(appsv2beta1.Ready) }, BeTrue()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -536,7 +536,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.ReplicantTemplate.Spec.Replicas))), @@ -579,7 +579,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { return instance.Status.IsConditionTrue(appsv2beta1.Ready) }, BeTrue()), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.CoreNodesStatus + return *instance.Status.CoreNodesStatus }, And( HaveField("Replicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), HaveField("ReadyReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), @@ -589,7 +589,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { HaveField("UpdateReplicas", Equal(int32(*instance.Spec.CoreTemplate.Spec.Replicas))), )), WithTransform(func(instance *appsv2beta1.EMQX) appsv2beta1.EMQXNodesStatus { - return instance.Status.ReplicantNodesStatus + return *instance.Status.ReplicantNodesStatus }, And( HaveField("Replicas", Equal(int32(0))), HaveField("ReadyReplicas", Equal(int32(0))),