Skip to content

Commit

Permalink
workloadctl: account for terminating pods
Browse files Browse the repository at this point in the history
Don't set Progressing=False if some pods from the previous generation
are still running.
  • Loading branch information
stlaz committed May 6, 2024
1 parent 52527b8 commit 141390e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/operator/apiserver/controller/workload/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
desiredReplicas = *(workload.Spec.Replicas)
}

matchingPods, err := c.kubeClient.CoreV1().Pods(c.targetNamespace).List(ctx, metav1.ListOptions{LabelSelector: workload.Spec.Selector.String()})
if err != nil {
return err
}
// Terminating pods don't account for any of the other status fields but
// still can exist in a state when they are accepting connections and would
// contribute to unexpected behavior if we report Progressing=False.
// The case of too many pods might occur for example if `TerminationGracePeriodSeconds`
// is set.
tooManyMatchingPods := int32(len(matchingPods.Items)) > desiredReplicas

// If the workload is up to date, then we are no longer progressing
workloadAtHighestGeneration := workload.ObjectMeta.Generation == workload.Status.ObservedGeneration
workloadIsBeingUpdated := workload.Status.UpdatedReplicas < desiredReplicas
Expand All @@ -274,6 +285,10 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
deploymentProgressingCondition.Status = operatorv1.ConditionTrue
deploymentProgressingCondition.Reason = "PodsUpdating"
deploymentProgressingCondition.Message = fmt.Sprintf("deployment/%s.%s: %d/%d pods have been updated to the latest generation", workload.Name, c.targetNamespace, workload.Status.UpdatedReplicas, desiredReplicas)
} else if tooManyMatchingPods {
deploymentProgressingCondition.Status = operatorv1.ConditionTrue
deploymentProgressingCondition.Reason = "PreviousGenPodsPresent"
deploymentProgressingCondition.Message = fmt.Sprintf("deployment/%s.%s: %d pods from the previous generation are still present", workload.Name, c.targetNamespace, len(matchingPods.Items)-int(desiredReplicas))
} else {
deploymentProgressingCondition.Status = operatorv1.ConditionFalse
deploymentProgressingCondition.Reason = "AsExpected"
Expand Down

0 comments on commit 141390e

Please sign in to comment.