Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Sep 3, 2024
1 parent e482789 commit 933ebeb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 72 deletions.
26 changes: 14 additions & 12 deletions controllers/apps/v2beta1/update_emqx_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
}
}

Expand Down
78 changes: 18 additions & 60 deletions e2e/v2beta1/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
)

Expand Down Expand Up @@ -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()),
),
)

Expand Down Expand Up @@ -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()),
),
)

Expand Down Expand Up @@ -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()),
),
)

Expand Down Expand Up @@ -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()),
),
)

Expand Down Expand Up @@ -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()),
),
)

Expand Down

0 comments on commit 933ebeb

Please sign in to comment.