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

Ignore not found in kubectl wait --for=delete #90969

Merged

Conversation

zhouya0
Copy link
Contributor

@zhouya0 zhouya0 commented May 11, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:
If the condition of kubectl wait if delete, then we should ignore 404 not found errors.

Before:

[root@master ~]# kubectl wait jobs job1 --for=delete
Error from server (NotFound): jobs.batch "job1" not found
[root@master ~]# echo $?
1

With this PR:

[root@master ~]# ./kubectl wait jobs job1 --for=delete
[root@master ~]# echo $?
0

Which issue(s) this PR fixes:

Fixes ##87747

Special notes for your reviewer:
/cc @soltysh

Does this PR introduce a user-facing change?:

Add kubectl wait  --ignore-not-found flag

@k8s-ci-robot k8s-ci-robot requested a review from soltysh May 11, 2020 08:20
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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. 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 May 11, 2020
@zhouya0
Copy link
Contributor Author

zhouya0 commented May 11, 2020

/assign @seans3

@zhouya0 zhouya0 force-pushed the kubectl_wait_add_ignore_not_found branch from b23647c to 6c39b62 Compare May 11, 2020 10:38
@zhouya0
Copy link
Contributor Author

zhouya0 commented May 11, 2020

/retest

2 similar comments
@zhouya0
Copy link
Contributor Author

zhouya0 commented May 11, 2020

/retest

@zhouya0
Copy link
Contributor Author

zhouya0 commented May 14, 2020

/retest

@zhouya0
Copy link
Contributor Author

zhouya0 commented Jun 10, 2020

/cc @brianpursley Can you help me to review this? Thanks!

@brianpursley
Copy link
Member

Are we sure we want to add a new flag for this, instead of just changing the behavior of waiting for delete?

It seems like it is already trying to handle not found here, but I wonder if it needs more. I don't know off-hand if List() returns a 404 if the list is empty, so this might not actually be doing what was intended.

What about in func IsDeleted, just adding another if apierrors.IsNotFound(err) condition like this? Would this work?

objWatch, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), watchOptions)
if apierrors.IsNotFound(err) {   # <-- Added this
	return info.Object, true, nil
}
if err != nil {
	return gottenObj, false, err
}

I'm not entirely opposed to having a command-line option, but I'm trying to imagine when I would not want to set this when I'm waiting for a deletion, or a case where I would want to set this when I'm waiting for a condition.

@brianpursley
Copy link
Member

/cc @soltysh
/cc @seans3

Thoughts on adding an --ignore-not-found flag vs changing the behavior of waiting for a delete to always ignore not found errors? (See my previous comment)

@k8s-ci-robot k8s-ci-robot requested a review from seans3 June 10, 2020 20:10
@zhouya0
Copy link
Contributor Author

zhouya0 commented Jun 11, 2020

@brianpursley I tried your suggestion and apparently it doesn't work because the Notfound error happens before. In visitor := o.ResourceFinder.Do() in RunWait and it will call

func (b *Builder) visitorResult() *Result {

It's will firstly send the request to get the info and that's where error happens :)

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.

I'm also leaning towards what Brian said, since we already ignore not found, I'd make it explicit there as well.

staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go Outdated Show resolved Hide resolved
@soltysh soltysh self-assigned this Jun 17, 2020
@zhouya0 zhouya0 force-pushed the kubectl_wait_add_ignore_not_found branch 2 times, most recently from 7b5ec1c to 5e050c7 Compare July 23, 2020 02:08
@zhouya0
Copy link
Contributor Author

zhouya0 commented Jul 23, 2020

/retest

@apelisse apelisse changed the title Add kubectl wait --ignore-not-found flag Ignore not found in kubectl wait --for=delete Jul 23, 2020
@zhouya0
Copy link
Contributor Author

zhouya0 commented Jul 23, 2020

/retest

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.

Oh, and please squash your changes.

staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go Outdated Show resolved Hide resolved
@zhouya0 zhouya0 force-pushed the kubectl_wait_add_ignore_not_found branch from 5e050c7 to 5ed1f17 Compare July 27, 2020 03:03
@zhouya0 zhouya0 force-pushed the kubectl_wait_add_ignore_not_found branch from 5ed1f17 to 3d2d95e Compare August 28, 2020 03:59
@zhouya0 zhouya0 requested a review from soltysh August 28, 2020 05:40
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
/milestone v1.20
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Sep 16, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Sep 16, 2020
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 16, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: soltysh, zhouya0

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 Sep 16, 2020
@soltysh soltysh added kind/bug Categorizes issue or PR as related to a bug. and removed kind/feature Categorizes issue or PR as related to a new feature. labels Sep 16, 2020
@soltysh
Copy link
Contributor

soltysh commented Sep 16, 2020

Changing kind per linked issue.

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/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants