Skip to content

fix(pdb): Ignore terminating pods when checking for controllers to prevent race condition #132431

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

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

Conversation

atilsensalduz
Copy link

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PR fixes a race condition in the PDB controller when determining the expected scale of pods.

Problem:
Previously, if a pod was terminating (had a DeletionTimestamp) and its controller was already deleted (example scenario is during rolling restart if revisionHistoryLimit: 0), the PDB controller would return an error because it could not find a controller for the pod. This created a race condition between finding scale count in already deleted controller and, potentially resulting in unnecessary errors or incorrect PDB status.

Solution:

  • The PDB controller logic is updated to skip pods with a DeletionTimestamp when verifying controller presence for expected scale calculation.
  • A unit test is added to ensure that terminating pods do not cause errors during expected scale calculation.

Impact:
This change prevents the PDB controller from reporting errors or misbehaving in scenarios where pods are terminating and their controllers have already been deleted, thus making the disruption logic more robust.

Which issue(s) this PR is related to:
Closes #130723

Does this PR introduce a user-facing change?
No.

…llers to find expected scale

- Updates the PodDisruptionBudget controller logic to skip pods with a DeletionTimestamp when verifying controller presence to find expected scale.
- Adds a unit test to ensure that pods marked for deletion do not cause errors during expected scale calculation.
- Fixes a race condition where a terminating pod's controller may already be deleted, preventing unnecessary errors.

Signed-off-by: atilsensalduz <[email protected]>
…llers to find expected scale

- Updates the PodDisruptionBudget controller logic to skip pods with a DeletionTimestamp when verifying controller presence to find expected scale.
- Adds a unit test to ensure that pods marked for deletion do not cause errors during expected scale calculation.
- Fixes a race condition where a terminating pod's controller may already be deleted, preventing unnecessary errors.

Signed-off-by: atilsensalduz <[email protected]>
…llers to find expected scale

- Updates the PodDisruptionBudget controller logic to skip pods with a DeletionTimestamp when verifying controller presence to find expected scale.
- Adds a unit test to ensure that pods marked for deletion do not cause errors during expected scale calculation.
- Fixes a race condition where a terminating pod's controller may already be deleted, preventing unnecessary errors.

Signed-off-by: atilsensalduz <[email protected]>
@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 20, 2025
Copy link

linux-foundation-easycla bot commented Jun 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 20, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

Welcome @atilsensalduz!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 20, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @atilsensalduz. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: atilsensalduz
Once this PR has been reviewed and has the lgtm label, please assign smarterclayton for approval. For more information see the 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

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 20, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Apps Jun 20, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 20, 2025
…llers to find expected scale

- Updates the PodDisruptionBudget controller logic to skip pods with a DeletionTimestamp when verifying controller presence to find expected scale.
- Adds a unit test to ensure that pods marked for deletion do not cause errors during expected scale calculation.
- Fixes a race condition where a terminating pod's controller may already be deleted, preventing unnecessary errors.

Signed-off-by: atilsensalduz <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 22, 2025
…llers to find expected scale

- Updates the PodDisruptionBudget controller logic to skip pods with a DeletionTimestamp when verifying controller presence to find expected scale.
- Adds a unit test to ensure that pods marked for deletion do not cause errors during expected scale calculation.
- Fixes a race condition where a terminating pod's controller may already be deleted, preventing unnecessary errors.

Signed-off-by: atilsensalduz <[email protected]>
@@ -896,7 +896,7 @@ func (dc *DisruptionController) getExpectedScale(ctx context.Context, pdb *polic
break
}
}
if !foundController {
if !foundController && pod.DeletionTimestamp == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without knowing much about the context, but does this change require modifying the err info? 🤔

err = fmt.Errorf("found no controllers for pod %q", pod.Name)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current error message is still accurate, since it only triggers for pods that are not being deleted, but I’m happy to make it more explicit if you prefer.

@atilsensalduz
Copy link
Author

Hi @mortent , @smarterclayton just a friendly ping on this when you have a moment, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

Pod Disruption Budget Treats Terminating Pods as Unmanaged During Rolling Restarts
3 participants