kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.89k stars 924 forks source link

Kubectl allows unknown flag `-n` when querying resources not linked to namespaces #1526

Closed JMQuill closed 11 months ago

JMQuill commented 1 year ago

What happened: When running a command using the namespace flag such as kubectl get pv -n {namespace} all PVs are returned from the cluster

What you expected to happen: An error such as Unknown flag -n for resource type PersistentVolume

How to reproduce it (as minimally and precisely as possible):

  1. Run kubectl get pv -n {namespace}
  2. Inspect output and see that all PVs from cluster are returned

Anything else we need to know?:

Environment:

k8s-ci-robot commented 1 year ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
tamilselvan1102 commented 1 year ago

PVs are not scoped to any namespace. For ref check here

tamilselvan1102 commented 1 year ago

To see more about k8s resources are/aren't in a namespace, use following comments

resources in namespace     kubectl api-resources --namespaced=true

Resources not in namespace     kubectl api-resources --namespaced=false

JMQuill commented 1 year ago

@tamilselvan1102 I understand they aren't namespaced, which is why i think an unknown flag error should be thrown when interacting with them using -n

ardaguclu commented 1 year ago

kubectl get command can return multiple resources with a mixture of namespaced and non-namespaced ones. That's why, not returning unknown flag for -n is the expected behavior even when the resource is non-namespaced resource to let kubectl get pv,pvc -n test return something.

I understand the inconvenience in here but I doubt that we can change this behavior.

ardaguclu commented 11 months ago

I think, we can close this one because it is duplicate as well as designed by that way;

/close

k8s-ci-robot commented 11 months ago

@ardaguclu: Closing this issue.

In response to [this](https://github.com/kubernetes/kubectl/issues/1526#issuecomment-1867695019): >I think, we can close this one because it is duplicate as well as designed by that way; > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.