Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2beta1): fix status machine error #890

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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