Skip to content

Commit

Permalink
fix(v2alpha2): fix replicant status replica error
Browse files Browse the repository at this point in the history
  • Loading branch information
Rory-Z committed Jun 27, 2023
1 parent b3f30a2 commit 741c487
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions controllers/apps/v2alpha2/add_emqx_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ func (a *addCore) getNewStatefulSet(ctx context.Context, instance *appsv2alpha2.
}

func (a *addCore) syncStatefulSet(ctx context.Context, instance *appsv2alpha2.EMQX) error {
if isExistReplicant(instance) {
rsList := getReplicaSetList(ctx, a.Client,
client.InNamespace(instance.Namespace),
client.MatchingLabels(instance.Spec.ReplicantTemplate.Labels),
)
if len(rsList) != 1 {
// wait for replicaSet finished the scale down
return nil
}
}

stsList := getStateFulSetList(ctx, a.Client,
client.InNamespace(instance.Namespace),
client.MatchingLabels(instance.Spec.CoreTemplate.Labels),
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/v2alpha2/add_emqx_repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (a *addRepl) syncReplicaSet(ctx context.Context, instance *appsv2alpha2.EMQ
old := rsList[0].DeepCopy()
eList := getEventList(ctx, a.Clientset, old)

if canBeScaledDown(instance, appsv2alpha2.CodeNodesReady, eList) {
if canBeScaledDown(instance, appsv2alpha2.Ready, eList) {
old.Spec.Replicas = pointer.Int32(old.Status.Replicas - 1)
if err := a.Client.Update(ctx, old); err != nil {
return emperror.Wrap(err, "failed to scale down old replicaSet")
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/v2alpha2/update_emqx_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (u *updateStatus) reconcile(ctx context.Context, instance *appsv2alpha2.EMQ
if isExistReplicant(instance) {
if instance.Status.ReplicantNodesStatus == nil {
instance.Status.ReplicantNodesStatus = &appsv2alpha2.EMQXNodesStatus{}
instance.Status.ReplicantNodesStatus.Replicas = *instance.Spec.ReplicantTemplate.Spec.Replicas
}

rsList := &appsv1.ReplicaSetList{}
Expand All @@ -53,6 +52,8 @@ func (u *updateStatus) reconcile(ctx context.Context, instance *appsv2alpha2.EMQ
if len(rsList.Items) > 0 {
existedRs = rsList.Items[0].DeepCopy()
}

instance.Status.ReplicantNodesStatus.Replicas = *instance.Spec.ReplicantTemplate.Spec.Replicas
}

if r != nil {
Expand Down

0 comments on commit 741c487

Please sign in to comment.