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

add PodReplacementPolicy for Deployments: terminating pods #128546

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

atiratree
Copy link
Member

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?

A new status field `.spec.terminatingReplicas` is added to Deployments and ReplicaSets to allow tracking of terminating pods.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/code-generation area/test kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 4, 2024
@k8s-triage-robot
Copy link

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.

@atiratree
Copy link
Member Author

/test pull-kubernetes-e2e-gce

Copy link
Contributor

@soltysh soltysh left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 55eabbc1e4eb3dd523e255d1fdaa13a8b09cb7c8

@soltysh
Copy link
Contributor

soltysh commented Nov 5, 2024

/triage accepted
/priority important-longterm
/label api-review

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. api-review Categorizes an issue or PR as actively needing an API review. labels Nov 5, 2024
@k8s-ci-robot k8s-ci-robot removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 5, 2024
@atiratree atiratree force-pushed the pod-replacement-policy-terminating-pods branch from 46560dc to ca34534 Compare November 7, 2024 16:01
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

pkg/apis/apps/types.go Outdated Show resolved Hide resolved
pkg/apis/apps/types.go Outdated Show resolved Hide resolved
pkg/apis/apps/validation/validation.go Outdated Show resolved Hide resolved
pkg/apis/apps/validation/validation.go Outdated Show resolved Hide resolved
pkg/controller/deployment/sync.go Show resolved Hide resolved
staging/src/k8s.io/api/apps/v1beta1/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/apps/v1beta2/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/apps/v1beta2/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/extensions/v1beta1/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/extensions/v1beta1/types.go Outdated Show resolved Hide resolved
@liggitt liggitt self-assigned this Nov 7, 2024
@atiratree atiratree force-pushed the pod-replacement-policy-terminating-pods branch 3 times, most recently from b9df89f to 642842f Compare November 7, 2024 19:37
@atiratree
Copy link
Member Author

seems like the #123946 flake is still present
/test pull-kubernetes-integration

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2024
@atiratree atiratree force-pushed the pod-replacement-policy-terminating-pods branch from 642842f to 444ba7b Compare November 8, 2024 16:19
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2024
terminatingReplicas := int32(0)
for _, rs := range replicaSets {
if rs != nil {
terminatingReplicas += ptr.Deref(rs.Status.TerminatingReplicas, 0)
Copy link
Member

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

Suggested change
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)

Copy link
Member Author

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.

Copy link
Member Author

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 {
Copy link
Member

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)
Copy link
Member

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)) +
Copy link
Member

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

Copy link
Member

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))

Copy link
Member Author

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.

@atiratree atiratree force-pushed the pod-replacement-policy-terminating-pods branch from 444ba7b to b0e9ae4 Compare November 22, 2024 15:53
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: atiratree, soltysh
Once this PR has been reviewed and has the lgtm label, please ask for approval from liggitt. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. area/code-generation area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: In progress
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

5 participants