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): when pod have DeletionTimestamp, don't scale down #895

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
18 changes: 14 additions & 4 deletions controllers/apps/v2beta1/sync_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
return subResult{}
}

if !instance.Status.IsConditionTrue(appsv2beta1.Available) {
return subResult{}
}

updateSts, currentSts, _ := getStateFulSetList(ctx, s.Client, instance)
updateRs, currentRs, _ := getReplicaSetList(ctx, s.Client, instance)

Expand Down Expand Up @@ -55,7 +59,7 @@
if err != nil {
return subResult{err: emperror.Wrap(err, "failed to check if pod can be scale down")}
}
if shouldDeletePod != nil {
if shouldDeletePod != nil && shouldDeletePod.DeletionTimestamp == nil {
if shouldDeletePod.Annotations == nil {
shouldDeletePod.Annotations = make(map[string]string)
}
Expand All @@ -71,7 +75,7 @@
return subResult{err: emperror.Wrap(err, "failed to get should delete pod")}
}
}
if _, ok := pod.Annotations["controller.kubernetes.io/pod-deletion-cost"]; ok && pod.DeletionTimestamp == nil {
if _, ok := pod.Annotations["controller.kubernetes.io/pod-deletion-cost"]; ok {
currentRs.Spec.Replicas = pointer.Int32(instance.Status.ReplicantNodesStatus.CurrentReplicas - 1)
if err := s.Client.Update(ctx, currentRs); err != nil {
return subResult{err: emperror.Wrap(err, "failed to scale down old replicaSet")}
Expand Down Expand Up @@ -140,9 +144,11 @@
sort.Sort(PodsByNameOlder(oldRsPods))
shouldDeletePod = oldRsPods[0].DeepCopy()
for _, pod := range oldRsPods {
if pod.DeletionTimestamp != nil {
return pod.DeepCopy(), nil
}
if _, ok := pod.Annotations["controller.kubernetes.io/pod-deletion-cost"]; ok {
shouldDeletePod = pod.DeepCopy()
break
return pod.DeepCopy(), nil
}
}

Expand Down Expand Up @@ -204,6 +210,10 @@
Name: fmt.Sprintf("%s-%d", oldSts.Name, *oldSts.Spec.Replicas-1),
}, shouldDeletePod)

if shouldDeletePod.DeletionTimestamp != nil {
return false, nil
}

Check warning on line 215 in controllers/apps/v2beta1/sync_pods.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v2beta1/sync_pods.go#L214-L215

Added lines #L214 - L215 were not covered by tests

shouldDeletePodInfo, err = getEMQXNodeInfoByAPI(r, fmt.Sprintf("emqx@%s.%s.%s.svc.cluster.local", shouldDeletePod.Name, oldSts.Spec.ServiceName, oldSts.Namespace))
if err != nil {
return false, emperror.Wrap(err, "failed to get node info by API")
Expand Down