Skip to content

Commit

Permalink
fix(v2beta1): fix status machine error
Browse files Browse the repository at this point in the history
  • Loading branch information
Rory-Z committed Jul 29, 2023
1 parent e643f0e commit 35adf29
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 342 deletions.
17 changes: 12 additions & 5 deletions controllers/apps/v2beta1/status_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ limitations under the License.
package v2beta1

import (
"context"

appsv2beta1 "github.com/emqx/emqx-operator/apis/apps/v2beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type status interface {
nextStatus()
}

type emqxStatusMachine struct {
emqx *appsv2beta1.EMQX
emqx *appsv2beta1.EMQX
client client.Client

// EMQX cluster status
initialized status
Expand All @@ -40,9 +44,10 @@ type emqxStatusMachine struct {
currentStatus status
}

func newEMQXStatusMachine(emqx *appsv2beta1.EMQX) *emqxStatusMachine {
func newEMQXStatusMachine(k8sClient client.Client, emqx *appsv2beta1.EMQX) *emqxStatusMachine {
emqxStatusMachine := &emqxStatusMachine{
emqx: emqx,
client: k8sClient,
emqx: emqx,
}

initializedStatus := &initializedStatus{emqxStatusMachine: emqxStatusMachine}
Expand Down Expand Up @@ -133,7 +138,8 @@ type coreNodesProgressingStatus struct {
func (s *coreNodesProgressingStatus) nextStatus() {
emqx := s.emqxStatusMachine.GetEMQX()

if emqx.Status.CoreNodesStatus.UpdateReplicas == emqx.Status.CoreNodesStatus.Replicas {
updateSts, _, _ := getStateFulSetList(context.Background(), s.emqxStatusMachine.client, emqx)
if updateSts.Status.ReadyReplicas == emqx.Status.CoreNodesStatus.Replicas {
emqx.Status.SetCondition(metav1.Condition{
Type: appsv2beta1.CoreNodesReady,
Status: metav1.ConditionTrue,
Expand Down Expand Up @@ -184,7 +190,8 @@ func (s *replicantNodesProgressingStatus) nextStatus() {
return
}

if emqx.Status.ReplicantNodesStatus.UpdateReplicas == emqx.Status.ReplicantNodesStatus.Replicas {
updateRs, _, _ := getReplicaSetList(context.Background(), s.emqxStatusMachine.client, emqx)
if updateRs.Status.ReadyReplicas == emqx.Status.ReplicantNodesStatus.Replicas {
emqx.Status.SetCondition(metav1.Condition{
Type: appsv2beta1.ReplicantNodesReady,
Status: metav1.ConditionTrue,
Expand Down
335 changes: 0 additions & 335 deletions controllers/apps/v2beta1/status_machine_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion controllers/apps/v2beta1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var emqx *appsv2beta1.EMQX = &appsv2beta1.EMQX{
Name: "emqx",
Labels: map[string]string{
appsv2beta1.ManagerByLabelKey: "emqx-operator",
appsv2beta1.InstanceNameLabelKey: instance.Name,
appsv2beta1.InstanceNameLabelKey: "emqx",
},
},
Spec: appsv2beta1.EMQXSpec{
Expand Down
Loading

0 comments on commit 35adf29

Please sign in to comment.