mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
StatefulSetHasDesiredReplicas condition should check ObservedGeneration and update statefulset reaper use StatefulSetHasDesiredReplicas
This commit is contained in:
@@ -79,15 +79,23 @@ func ReplicaSetHasDesiredReplicas(rsClient extensionsclient.ReplicaSetsGetter, r
|
||||
}
|
||||
}
|
||||
|
||||
// StatefulSetHasDesiredReplicas returns a conditon that checks the number of statefulset replicas
|
||||
// StatefulSetHasDesiredReplicas returns a condition that checks the number of StatefulSet replicas
|
||||
func StatefulSetHasDesiredReplicas(ssClient appsclient.StatefulSetsGetter, ss *apps.StatefulSet) wait.ConditionFunc {
|
||||
// TODO: Differentiate between 0 statefulset pods and a really quick scale down using generation.
|
||||
// If we're given a StatefulSet where the status lags the spec, it either means that the
|
||||
// StatefulSet is stale, or that the StatefulSet manager hasn't noticed the update yet.
|
||||
// Polling status.Replicas is not safe in the latter case.
|
||||
desiredGeneration := ss.Generation
|
||||
return func() (bool, error) {
|
||||
ss, err := ssClient.StatefulSets(ss.Namespace).Get(ss.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return ss.Status.Replicas == ss.Spec.Replicas, nil
|
||||
// There's a chance a concurrent update modifies the Spec.Replicas causing this check to
|
||||
// pass, or, after this check has passed, a modification causes the StatefulSet manager to
|
||||
// create more pods. This will not be an issue once we've implemented graceful delete for
|
||||
// StatefulSet, but till then concurrent stop operations on the same StatefulSet might have
|
||||
// unintended side effects.
|
||||
return ss.Status.ObservedGeneration != nil && *ss.Status.ObservedGeneration >= desiredGeneration && ss.Status.Replicas == ss.Spec.Replicas, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user