Skip to content

Commit 80a8691

Browse files
committed
fix: avoid ensuring replicant consistency while still scaling
This commit also makes sure that terminating pods are not affected by ensure consistency routines.
1 parent 11f84eb commit 80a8691

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

internal/controller/sync_replicant_sets.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,34 @@ func (s *syncReplicantSets) reconcile(r *reconcileRound, instance *crd.EMQX) sub
4545
}
4646

4747
// Steady state: handle scale-up and scale-down.
48+
specReplicas := ptr.Deref(updateRs.Spec.Replicas, 0)
4849
desiredReplicas := instance.Spec.NumReplicantReplicas()
49-
currentReplicas := ptr.Deref(updateRs.Spec.Replicas, 0)
50+
currentReplicas := updateRs.Status.Replicas
5051

51-
if currentReplicas < desiredReplicas {
52+
if specReplicas < desiredReplicas {
5253
r.log.V(1).Info("scaling up replicantSet",
5354
"replicaSet", klog.KObj(updateRs),
54-
"from", currentReplicas,
55+
"from", specReplicas,
5556
"to", desiredReplicas,
5657
)
5758
return s.scaleUp(r, updateRs, desiredReplicas)
5859
}
5960

60-
if currentReplicas > desiredReplicas {
61+
if specReplicas > desiredReplicas {
6162
r.log.V(1).Info("scaling down replicantSet",
6263
"replicaSet", klog.KObj(updateRs),
63-
"from", currentReplicas,
64+
"from", specReplicas,
6465
"to", desiredReplicas,
6566
)
66-
return s.scaleDown(r, instance, updateRs, currentReplicas, desiredReplicas)
67+
return s.scaleDown(r, instance, updateRs, specReplicas, desiredReplicas)
6768
}
6869

6970
// Steady state: clean up stale artifacts.
70-
err := s.ensureConsistency(r, instance, updateRs)
71-
if err != nil {
72-
return reconcileError(emperror.Wrap(err, "failed to restore replicant consistency"))
71+
if currentReplicas == specReplicas {
72+
err := s.ensureConsistency(r, instance, updateRs)
73+
if err != nil {
74+
return reconcileError(emperror.Wrap(err, "failed to restore replicant consistency"))
75+
}
7376
}
7477

7578
return subResult{}
@@ -142,7 +145,7 @@ func (s *syncReplicantSets) ensureConsistency(
142145
instance *crd.EMQX,
143146
updateRs *appsv1.ReplicaSet,
144147
) error {
145-
for _, pod := range r.state.podsManagedBy(updateRs) {
148+
for _, pod := range r.state.listPods(podsManagedBy{updateRs}, podsAlive{}) {
146149
// 1. Check if pod has stale scale-down annotations.
147150
dirty := s.removeStaleReplicantAnnotations(pod)
148151
if !dirty {

0 commit comments

Comments
 (0)