-
Notifications
You must be signed in to change notification settings - Fork 39.4k
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
When running kubectl drain
in dry-run, list warnings and pods that would be deleted.
#82660
When running kubectl drain
in dry-run, list warnings and pods that would be deleted.
#82660
Conversation
Hi @sallyom. 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. 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/test-infra repository. |
/assign @soltysh |
/ok-to-test :) |
8935c18
to
2de8782
Compare
sample output: $ kubectl drain ip-10-0-138-243.blah --dry-run
node/ip-10-0-138-243.blah cordoned (dry run)
evicting pod ns1/pod1
evicting pod ns2/pod2
evicting pod ns3/pod3
evicting pod ns1/pod2
node/ip-10-0-138-243.blah drained (dry run) |
2de8782
to
0d06f3a
Compare
/priority important-longtemr |
@soltysh: The label(s) In response to this:
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/test-infra repository. |
/priority important-longterm |
0d06f3a
to
141917d
Compare
141917d
to
99aa82b
Compare
/retest |
e3207af
to
84154d0
Compare
/retest |
/test pull-kubernetes-node-e2e-containerd |
1 similar comment
/test pull-kubernetes-node-e2e-containerd |
if len(list.Pods()) > 0 && o.drainer.DryRun { | ||
fmt.Fprintf(o.Out, "namespace/pod (dry run)\n") | ||
for _, pod := range list.Pods() { | ||
fmt.Fprintf(o.Out, "%s/%s\n", pod.Namespace, pod.Name) |
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.
From what I see DeleteOrEvicPods
is doing this:
fmt.Fprintf(d.Out, "evicting pod %q\n", pod.Name) |
(dry run)
added at the end.
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.
Although we should probably update that to print both namespace and name altogether, in which case what you have here would be in sync.
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.
Honestly, in both cases, we should probably fix that helper method to be reusable by passing ResourcePrinter
but let's leave that as a separate PR 😉
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 added namespace to kubectl/pkg/drain/drain.go added "evicting pod ... (dry-run)" to dry-run list.
$ kubectl drain ip-10-0-144-193.us-east-2.compute.internal --dry-run --pod-selector="app=hello-node"
node/ip-10-0-144-193.us-east-2.compute.internal cordoned (dry run)
evicting pod test/hello-node-7676b5fb8d-6w57 (dry run)
node/ip-10-0-144-193.us-east-2.compute.internal drained (dry run)
non-dry-run:
$ kubectl drain ip-10-0-144-193.us-east-2.compute.internal --pod-selector="app=hello-node"
node/ip-10-0-144-193.us-east-2.compute.internal cordoned
evicting pod test/hello-node-7676b5fb8d-6w57
pod/hello-node-7676b5fb8d-6w57r evicted
node/ip-10-0-144-193.us-east-2.compute.internal evicted
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.
also, I changed '%q' to '%s' for printing, so instead of
evicting pod "test"/"hello-node-7676b5fb8d-6w57r"
pod/hello-node-7676b5fb8d-6w57r evicted
it prints
evicting pod test/hello-node-7676b5fb8d-6w57r
pod/hello-node-7676b5fb8d-6w57r evicted
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.
but will change to %q if that's preferred
@@ -321,12 +319,21 @@ func (o *DrainCmdOptions) RunDrain() error { | |||
|
|||
func (o *DrainCmdOptions) deleteOrEvictPodsSimple(nodeInfo *resource.Info) error { | |||
list, errs := o.drainer.GetPodsForDeletion(nodeInfo.Name) | |||
if len(list.Pods()) > 0 && o.drainer.DryRun { | |||
fmt.Fprintf(o.Out, "namespace/pod (dry run)\n") |
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.
Remove this line entirely, you'll not gonna get it in regular drain execution path, so it can't be here either.
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.
got it, removed
for _, pod := range list.Pods() { | ||
fmt.Fprintf(o.Out, "%s/%s\n", pod.Namespace, pod.Name) | ||
} | ||
} |
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 entire if should be after the below error check, in the normal when you encounter an error we'll return that error, same applies for dry-run.
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.
ah right, doh, thanks, updated
if errs != nil { | ||
return utilerrors.NewAggregate(errs) | ||
} | ||
if warnings := list.Warnings(); warnings != "" { | ||
fmt.Fprintf(o.ErrOut, "WARNING: %s\n", warnings) | ||
} | ||
if o.drainer.DryRun { | ||
return nil |
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.
Here should the print happen.
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.
yup got it.
84154d0
to
993d4a1
Compare
/test pull-kubernetes-e2e-gce-device-plugin-gpu |
/test pull-kubernetes-integration |
/test pull-kubernetes-e2e-gce-100-performance |
993d4a1
to
c98a0d9
Compare
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.
Two small nits and this is ready to go, thanks for keeping up with me 🙃
} | ||
if err == nil || o.drainer.DryRun { | ||
err = o.deleteOrEvictPodsSimple(info) | ||
if err == nil { |
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.
By now you should be aware that people call me short-if 👮♂️ 😉 the above 3 lines can be easily squashed into a single:
if err := o.deleteOrEvictPodsSimple(info); err == nil {
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.
of course : ) thanks - squashed
@@ -327,6 +325,14 @@ func (o *DrainCmdOptions) deleteOrEvictPodsSimple(nodeInfo *resource.Info) error | |||
if warnings := list.Warnings(); warnings != "" { | |||
fmt.Fprintf(o.ErrOut, "WARNING: %s\n", warnings) | |||
} | |||
if o.drainer.DryRun { | |||
if len(list.Pods()) > 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.
No need for this check, for-range will handle that for you
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.
oh right, ok. dropped
…would be deleted.
c98a0d9
to
909300b
Compare
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sallyom, soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
@sallyom: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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/test-infra repository. I understand the commands that are listed here. |
When running `kubectl drain` in dry-run, list warnings and pods that would be deleted. Kubernetes-commit: 646afd5
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR will result in listing pods that would be deleted if running
kubectl drain <node>
along with any warnings or errors that would occur if not in dry-run.Which issue(s) this PR fixes:
Fixes #
kubernetes/kubectl#719
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: