Skip to content

Improve ignore-not-found behavior #132542

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gemmahou
Copy link

@gemmahou gemmahou commented Jun 25, 2025

What type of PR is this?

  1. Improve help message of ignore-not-found flag

before:

--ignore-not-found=false:
	If the requested object does not exist the command will return exit code 0.

after:

--ignore-not-found=false:
    If set to true, suppresses NotFound error for object(s) that do not exist and returns exit code 0. Using this flag with commands that query for collections of resources has no effect on the exit code.
  1. Check ignore-not-found flag in watch operation as well; when it's set to true, ignore errors
  2. Improve test coverage

/kind bug

What this PR does / why we need it:

Which issue(s) this PR is related to:

kubernetes/kubectl#1596

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Yes

     Clarify help message of --ignore-not-found flag. Support --ignore-not-found in `watch` operation.

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


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 25, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @gemmahou. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added 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. labels Jun 25, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI Jun 25, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 25, 2025
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 25, 2025
@gemmahou
Copy link
Author

/assign @seans3

@seans3
Copy link
Contributor

seans3 commented Jun 26, 2025

/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 Jun 26, 2025
@seans3
Copy link
Contributor

seans3 commented Jun 26, 2025

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 26, 2025
Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

This looks good, and thanks for the tests. But if I understood the conversation in this issue correctly, I believe there should also be a warning if the --ignore-not-found flag is set when not getting a specific resource. In other words, it doesn't make sense to set the flag unless also retrieving a specific resource. Please let me know what you think.

@github-project-automation github-project-automation bot moved this from Needs Triage to In Progress in SIG CLI Jun 26, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gemmahou
Once this PR has been reviewed and has the lgtm label, please ask for approval from seans3. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@seans3
Copy link
Contributor

seans3 commented Jun 26, 2025

Example of ignoring lint issue for checking return error code:

conn.WriteMessage(gwebsocket.BinaryMessage, []byte{}) //nolint:errcheck

@gemmahou
Copy link
Author

gemmahou commented Jun 26, 2025

This looks good, and thanks for the tests. But if I understood the conversation in this issue correctly, I believe there should also be a warning if the --ignore-not-found flag is set when not getting a specific resource. In other words, it doesn't make sense to set the flag unless also retrieving a specific resource. Please let me know what you think.

I've updated the help message for this flag, but it will only show up when when running kubectl get -h. It makes sense to display a warning if the flag is used incorrectly.

@gemmahou
Copy link
Author

gemmahou commented Jun 26, 2025

@seans3 I uploaded db2b0f7 to add an additional warning message.

I attempted to validate kubectl cmds by analyzing args and flags for warning triggers. However, this proved overly complex due to the varied nature of kubectl cmds, for example, kubectl get service/frontend and kubectl get service,pods have same args counts, but only the former queries a specific resource. Furthermore, if the GET request successfully finds resource(s), even --ignore-not-found is set, the warning message may not be necessary.

The primary confusion seems to lie with the exit code when there's no output(not found) and no HTTP error. So I've added additional warning messages that appears in this specific scenario. I believe this will help clarify user confusion. Let me know WDYT and I will add additional test cases.

@gemmahou gemmahou force-pushed the ignorenotfound branch 2 times, most recently from b6f95a8 to b4c8dd9 Compare June 26, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants