Skip to content

Make stage resource deletion idempotent - #1820

Merged
kubernetes-prow[bot] merged 3 commits into
kubernetes-sigs:mainfrom
vaibhav61:fix/idempotent-stage-deletion
Nov 24, 2026
Merged

kubernetes-prow[bot] merged 3 commits into
kubernetes-sigs:mainfrom
vaibhav61:fix/idempotent-stage-deletion

Conversation

@vaibhav61

@vaibhav61 vaibhav61 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

We encountered this while testing KEDA autoscaling with KWOK simulating the workload pods. The experiment used 20,000 Deployments, each with a ScaledObject and HPA. We changed a shared Prometheus metric to run three scale-up/scale-down cycles, moving the simulated pod population from 20,000 to 40,000 and back to 20,000, to measure how quickly the system converged.

While investigating scaling latency, bounded KWOK log captures contained 2,021 distinct pod-deletion error lines reporting NotFound: the target pod was already absent when the deletion stage tried to delete it. All scaling cycles completed successfully. These counts describe the captured logs, not a full-run total, and do not establish which component deleted each pod first or that these errors caused the scaling delay.

A queued deletion stage can execute after its target has already been deleted, for example by another controller or an earlier deletion attempt. The desired outcome is already satisfied, so this PR treats an API NotFound response as successful deletion for pods, nodes, and generic Stage resources. Other API errors remain visible, and delete options are preserved.

This prevents an already-satisfied deletion from producing a failed-stage error. It does not change retry policy or claim a throughput improvement.

Which issue(s) this PR fixes:

No linked issue.

Special notes for your reviewer:

Regression coverage exercises deletion twice against client-go object trackers and verifies that permission errors, conflicts, and timeouts remain failures. The repeated-delete cases fail on the base revision with NotFound on attempt 2. Validation:

  • The exact new tests on base commit d550320 fail in six NotFound cases (repeated deletion and explicit NotFound for each controller).
  • With this change, all 15 subtests pass with the race detector.
  • make unit-test passes (go test -race ./pkg/...; 45 packages with tests).
  • Formatting, changed-file boilerplate checks, and git diff --check pass.
  • go vet ./pkg/kwok/controllers reports a pre-existing lostcancel warning in stages_manager.go:101,128. The same command on the clean base commit produces identical output.

No live cluster changes are required to reproduce the regression.

Does this PR introduce a user-facing change?

KWOK treats deleting an already-absent pod, node, or generic Stage resource as successful.

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


@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Nov 21, 2026
@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

👷 Deploy request for k8s-kwok pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7d7892a

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: vaibhav61 / name: Vaibhav Mishra (c699831)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @vaibhav61!

It looks like this is your first PR to kubernetes-sigs/kwok 🎉. 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-sigs/kwok 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. 😃

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @vaibhav61. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

Details

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.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2026
Signed-off-by: Vaibhav Mishra <37236922+vaibhav61@users.noreply.github.com>
@vaibhav61
vaibhav61 force-pushed the fix/idempotent-stage-deletion branch from 9c772c9 to c699831 Compare November 21, 2026 04:01
@vaibhav61

Copy link
Copy Markdown
Contributor Author

@wzshiming, could you review this fix and authorize CI with /ok-to-test when appropriate? Thank you!

@kubernetes-prow kubernetes-prow Bot 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 Nov 21, 2026
@wzshiming

Copy link
Copy Markdown
Member

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 23, 2026
Signed-off-by: Vaibhav Mishra <37236922+vaibhav61@users.noreply.github.com>
@vaibhav61

Copy link
Copy Markdown
Contributor Author

@wzshiming, all tests on the latest commit are now passing, including Benchmark and the Prow end-to-end checks. Could you take a look when you have a chance? Thank you for authorizing CI!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the idempotent stage-deletion change.

No open issues 🎉

What changed in this PR

Makes KWOK stage deletion idempotent: deleting an already-absent pod, node, or generic Stage resource succeeds instead of reporting a failed stage.

Changes:

  • Treat API NotFound responses as successful deletion across all three controllers.
  • Preserve other deletion errors and existing delete options.
  • Add regression tests for repeated deletion, error propagation, and delete preconditions.
File Description
pkg/​kwok/​controllers/​stage_controller.go Accepts NotFound when deleting generic Stage resources.
pkg/​kwok/​controllers/​pod_controller.go Accepts NotFound when deleting pods.
pkg/​kwok/​controllers/​node_controller.go Accepts NotFound when deleting nodes.
pkg/​kwok/​controllers/​delete_resource_test.go Tests idempotent deletion, preserved errors, and delete options.

Review effort: Balanced

@kubernetes-prow kubernetes-prow Bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 24, 2026
@wzshiming

Copy link
Copy Markdown
Member

/approve
/lgtm
/label tide/merge-method-squash

@kubernetes-prow kubernetes-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 24, 2026
@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 24, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vaibhav61, wzshiming

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 24, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 58201b5 into kubernetes-sigs:main Nov 24, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants