-
Notifications
You must be signed in to change notification settings - Fork 39.7k
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
add PodReplacementPolicy for Deployments: terminating pods #128546
base: master
Are you sure you want to change the base?
add PodReplacementPolicy for Deployments: terminating pods #128546
Conversation
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
804f453
to
f4a8480
Compare
f4a8480
to
46560dc
Compare
/test pull-kubernetes-e2e-gce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
from sig-apps pov
LGTM label has been added. Git tree hash: 55eabbc1e4eb3dd523e255d1fdaa13a8b09cb7c8
|
/triage accepted |
46560dc
to
ca34534
Compare
New changes are detected. LGTM label has been removed. |
staging/src/k8s.io/api/testdata/v1.31.0/apps.v1.Deployment.after_roundtrip.pb
Outdated
Show resolved
Hide resolved
b9df89f
to
642842f
Compare
seems like the #123946 flake is still present |
642842f
to
444ba7b
Compare
terminatingReplicas := int32(0) | ||
for _, rs := range replicaSets { | ||
if rs != nil { | ||
terminatingReplicas += ptr.Deref(rs.Status.TerminatingReplicas, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaulting a nil here to 0 unconditionally is not correct.
If this replicaset has been synced by the replicaset controller at all (status.observedGeneration != 0), and TerminatingReplicas is nil, we cannot reason about the sum of terminatingReplicas across the replicasets and have to return nil from GetTerminatingReplicaCountForReplicaSets
terminatingReplicas += ptr.Deref(rs.Status.TerminatingReplicas, 0) | |
if rs.Status.ObservedGeneration != 0 && rs.Status.TerminatingReplicas == nil { | |
// we cannot sum TerminatingReplicas from replicasets that have been synced by the replicaset controller but do not have TerminatingReplicas set | |
return nil | |
} | |
// sum TerminatingReplicas reported by the replicaset controller (or 0 for replicasets not yet synced by the controller) | |
terminatingReplicas += ptr.Deref(rs.Status.TerminatingReplicas, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable at first glance. I will try to update the code handling for this in both PRs and test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated both PRs to handle the pointer fields. It seems to work fine when we check the ObservedGeneration as we will get non nil fields during normal operations.
If we are unable to asses the number of terminating pods, the deployment will stop progressing until we are able to make that decision again. As mentioned in #128546 (comment), this should almost never happen.
@@ -714,6 +714,17 @@ func GetAvailableReplicaCountForReplicaSets(replicaSets []*apps.ReplicaSet) int3 | |||
return totalAvailableReplicas | |||
} | |||
|
|||
// GetTerminatingReplicaCountForReplicaSets returns the number of terminating pods for all replica sets. | |||
func GetTerminatingReplicaCountForReplicaSets(replicaSets []*apps.ReplicaSet) int32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to return *int32 to distinguish between scenarios where we can sum across replicasets and scenarios where we cannot. We can special-case handling of replicasets never synced by the controller at all and treat terminatingReplicas as 0 in that case, see the comment below.
if err != nil { | ||
return err | ||
} | ||
|
||
if utilfeature.DefaultFeatureGate.Enabled(features.DeploymentPodReplacementPolicy) { | ||
terminatingPods = controller.FilterTerminatingPods(allPods) | ||
terminatingPods, err = rsc.claimPods(ctx, rs, selector, terminatingPods) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just counting terminating pods already managed by the replicaset is a much smaller change to reason about than starting to claim terminating pods as well... (it's not adding any new API calls, it's just tweaking the data we're already reporting upward into ReplicaSet and Deployment)
fmt.Sprintf("fullyLabeledReplicas %d->%d, ", rs.Status.FullyLabeledReplicas, newStatus.FullyLabeledReplicas) + | ||
fmt.Sprintf("readyReplicas %d->%d, ", rs.Status.ReadyReplicas, newStatus.ReadyReplicas) + | ||
fmt.Sprintf("availableReplicas %d->%d, ", rs.Status.AvailableReplicas, newStatus.AvailableReplicas) + | ||
fmt.Sprintf("terminatingReplicas %d->%d, ", ptr.Deref(rs.Status.TerminatingReplicas, 0), ptr.Deref(newStatus.TerminatingReplicas, 0)) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't mask the difference between nil and 0 here... we should be able to see nil→0
or 5→nil
in the log if that's what's happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would also be easier to see the diff to conditionally construct the terminatingReplicas bit into a string and just append the string
terminatingReplicasInfo := ""
if utilfeature.DefaultFeatureGate.Enabled(features.DeploymentPodReplacementPolicy) {
terminatingReplicasInfo = ...
}
logger.V(4).Info(fmt.Sprintf("Updating status for %v: %s/%s, ", rs.Kind, rs.Namespace, rs.Name) +
fmt.Sprintf("replicas %d->%d (need %d), ", rs.Status.Replicas, newStatus.Replicas, *(rs.Spec.Replicas)) + fmt.Sprintf("replicas %d->%d (need %d), ", rs.Status.Replicas, newStatus.Replicas, *(rs.Spec.Replicas)) +
fmt.Sprintf("fullyLabeledReplicas %d->%d, ", rs.Status.FullyLabeledReplicas, newStatus.FullyLabeledReplicas) + fmt.Sprintf("fullyLabeledReplicas %d->%d, ", rs.Status.FullyLabeledReplicas, newStatus.FullyLabeledReplicas) +
fmt.Sprintf("readyReplicas %d->%d, ", rs.Status.ReadyReplicas, newStatus.ReadyReplicas) + fmt.Sprintf("readyReplicas %d->%d, ", rs.Status.ReadyReplicas, newStatus.ReadyReplicas) +
fmt.Sprintf("availableReplicas %d->%d, ", rs.Status.AvailableReplicas, newStatus.AvailableReplicas) + fmt.Sprintf("availableReplicas %d->%d, ", rs.Status.AvailableReplicas, newStatus.AvailableReplicas) +
terminatingReplicasInfo +
fmt.Sprintf("sequence No: %v->%v", rs.Status.ObservedGeneration, newStatus.ObservedGeneration)) fmt.Sprintf("sequence No: %v->%v", rs.Status.ObservedGeneration, newStatus.ObservedGeneration))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, reporting also a nil transitions now.
- update internal ReplicaSet and Deployment type documentation to match with versioned API - made Replicaset and Deployment type documentation more consistent
444ba7b
to
b0e9ae4
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: atiratree, soltysh The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
A new status field
.spec.terminatingReplicas
is added to Deployments and ReplicaSets to allow tracking of terminating pods.This is a part 1 - please see special notes.
Which issue(s) this PR fixes:
tracking issue: kubernetes/enhancements#3973
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: