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

When running kubectl drain in dry-run, list warnings and pods that would be deleted. #82660

Merged
merged 1 commit into from
Dec 6, 2019

Conversation

sallyom
Copy link
Contributor

@sallyom sallyom commented Sep 12, 2019

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?:

kubectl drain node --dry-run will list pods that would be evicted or deleted

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. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 12, 2019
@k8s-ci-robot
Copy link
Contributor

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 /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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 12, 2019
@sallyom
Copy link
Contributor Author

sallyom commented Sep 12, 2019

/assign @soltysh

@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 12, 2019
@sallyom
Copy link
Contributor Author

sallyom commented Sep 13, 2019

/ok-to-test

:)

@k8s-ci-robot k8s-ci-robot 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 Sep 13, 2019
@sallyom sallyom force-pushed the list-pods-dry-run-drain branch 2 times, most recently from 8935c18 to 2de8782 Compare September 13, 2019 15:43
@sallyom
Copy link
Contributor Author

sallyom commented Sep 13, 2019

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)

@soltysh
Copy link
Contributor

soltysh commented Oct 14, 2019

/priority important-longtemr

@k8s-ci-robot
Copy link
Contributor

@soltysh: The label(s) priority/important-longtemr cannot be applied. These labels are supported: api-review, community/discussion, community/maintenance, community/question, cuj/build-train-deploy, cuj/multi-user, platform/aws, platform/azure, platform/gcp, platform/minikube, platform/other

In response to this:

/priority important-longtemr

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.

@soltysh
Copy link
Contributor

soltysh commented Oct 14, 2019

/priority important-longterm

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 14, 2019
@sallyom
Copy link
Contributor Author

sallyom commented Oct 15, 2019

/retest

@sallyom sallyom force-pushed the list-pods-dry-run-drain branch 3 times, most recently from e3207af to 84154d0 Compare October 22, 2019 23:58
@sallyom
Copy link
Contributor Author

sallyom commented Oct 23, 2019

/retest

@sallyom
Copy link
Contributor Author

sallyom commented Oct 23, 2019

/test pull-kubernetes-node-e2e-containerd

1 similar comment
@sallyom
Copy link
Contributor Author

sallyom commented Oct 24, 2019

/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)
Copy link
Contributor

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)
so I'd expect something similar for printing here maybe with (dry run) added at the end.

Copy link
Contributor

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.

Copy link
Contributor

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 😉

Copy link
Contributor Author

@sallyom sallyom Dec 2, 2019

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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)
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup got it.

@sallyom
Copy link
Contributor Author

sallyom commented Dec 2, 2019

/test pull-kubernetes-e2e-gce-device-plugin-gpu

@sallyom
Copy link
Contributor Author

sallyom commented Dec 3, 2019

/test pull-kubernetes-integration

@sallyom
Copy link
Contributor Author

sallyom commented Dec 3, 2019

/test pull-kubernetes-e2e-gce-100-performance

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.

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

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 {

Copy link
Contributor Author

@sallyom sallyom Dec 5, 2019

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh right, ok. dropped

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

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

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 5, 2019
@soltysh
Copy link
Contributor

soltysh commented Dec 5, 2019

/retest

@k8s-ci-robot k8s-ci-robot merged commit 646afd5 into kubernetes:master Dec 6, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Dec 6, 2019
@k8s-ci-robot
Copy link
Contributor

@sallyom: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce 909300b link /test pull-kubernetes-e2e-gce

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.

wking pushed a commit to wking/kubernetes that referenced this pull request Jul 21, 2020
When running `kubectl drain` in dry-run, list warnings and pods that would be deleted.

Kubernetes-commit: 646afd5
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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. 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/cli Categorizes an issue or PR as relevant to SIG CLI. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants