fix using stale pod when evict failed and retry - #133461
Conversation
|
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Mon Aug 11 10:25:10 UTC 2025. |
|
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The DetailsInstructions 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. |
|
Welcome @justlorain! |
|
Hi @justlorain. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
/cc @ardaguclu |
|
/ok-to-test |
Sure, I'll add the relevant tests. |
|
Thanks for the PR. Looking more closely at the code in drain.go, I have a few thoughts... Not about your changes, but about the entire Mainly, I'm unclear why The code clearly isn't working as intended right now, since But I think we can achieve the desired behavior of refreshing the pod by simply moving the If the code makes it through the error handling without returning or breaking, then (I think) we should always attempt to re-get the pod. So the first time through the loop, we use the original pod (set What do you think? Does this make sense or am I missing something? I feel like this logic would be more straightforward since it relies on regular code flow instead of having to manage and check a boolean. |
Thanks for your review! I think your approach is completely reasonable and intuitive for me. I've tried to implement a new commit based on it - could you please check if it aligns with your thinking? |
|
I think the changes look good. A few more things:
|
Hi, I've added the relevant unit tests and resolved the CI issues. Could you please review it again? |
|
Excellent work. The changes you made look good and thank you for writing the unit tests. The only thing I noticed is that the unit test takes 15s to run. Can you make some changes to improve the test speed? One approach might be to change the hard-coded For example: And then something like this in the two places (here and here) where it is used. For example: And finally, in the unit test, you can then reduce the delay to 1ms and also adjust the globalTimeout variable to make the test run faster: What do you think? |
I'm thinking if would be better to introduce the retry delay as a field of the kubernetes/staging/src/k8s.io/kubectl/pkg/drain/drain.go Lines 50 to 51 in 697d952 Helper is also described as a struct used to uniformly control drainer behavior, and it meets the need for configuration in unit tests.
Another consideration I have is whether it's necessary to make the retry delay setting a new option for the drain command. In that case, having it as a field of What do you think? |
That seems like it should work too. In that case though, it would be up to the caller to set the retry duration. Not a problem for kubectl, but if any other tool uses this drain helper, it will need to know to set that retry duration to 5 seconds or else the behavior would be different. I do think the existing retry behavior is broken right now anyway though, so it's probably not an issue.
Yeah, I agree and don't think we need to expose retry delay as a command option at this point. If it is something that someone really needs for some reason, they can open an issue for it and we can decide whether to add it then. I think you're right... let's keep this PR focused on fixing the bug. |
Attempted to introduce |
brianpursley
left a comment
There was a problem hiding this comment.
Looks good, thanks!
/lgtm
/label tide/merge-method-squash
|
LGTM label has been added. DetailsGit tree hash: 8397e0a4cdae6936f6551ced025d9c99b9ee55a1 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brianpursley, justlorain The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* fix using stale pod when evict failed and retry * simplify pod refresh process * use activePod at getPodFn * fix lint check * add ut * introduce EvictErrorRetryDelay
* fix using stale pod when evict failed and retry * simplify pod refresh process * use activePod at getPodFn * fix lint check * add ut * introduce EvictErrorRetryDelay
* fix using stale pod when evict failed and retry * simplify pod refresh process * use activePod at getPodFn * fix lint check * add ut * introduce EvictErrorRetryDelay
What type of PR is this?
/kind bug
What this PR does / why we need it:
The kubectl drain command still uses stale Pods when it fails and retries after evicting Pods.
It should re-fetch the latest Pods when failing and retrying after evicting Pods.
Which issue(s) this PR is related to:
Fixes kubernetes/kubectl#1767
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: