kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.86k stars 921 forks source link

Could we add a shorthand for --field-selector in kubectl? #1649

Open tnqn opened 1 month ago

tnqn commented 1 month ago

What happened?

I’m wondering if the --field-selector option is used frequently enough to justify a shorthand like -F. In our extension API server, we have a field that users need to specify to limit objects within a particular scope, but --field-selector feels a bit lengthy to type compared to the -l shorthand for label selectors. Would it make sense to add a shorthand for --field-selector?

Creating the issue to gather some feedback before introducing such a shorthand as suggested by @soltysh.

The original thread in sig-cli slack channel: https://kubernetes.slack.com/archives/C2GL57FJ4/p1725613426106679

cc @soltysh @apelisse

/sig cli

What did you expect to happen?

A shorthand can be used to filter objects by field selector, such as kubectl get FOO -F .spec.region=BAR.

How can we reproduce it (as minimally and precisely as possible)?

NONE

Anything else we need to know?

No response

Kubernetes version

```console $ kubectl version # paste output here ```

Cloud provider

OS version

```console # On Linux: $ cat /etc/os-release # paste output here $ uname -a # paste output here # On Windows: C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture # paste output here ```

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

k8s-ci-robot commented 1 month ago

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

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-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
ardaguclu commented 1 month ago

It looks reasonable. However, I'm wondering whether this was intentional decision due to some reasons. /transfer kubectl

mpuckett159 commented 1 month ago

/triage accepted Need to verify that there will not be collision between -f and -F. This will need to get tested across windows/macOS/various linux distros.

apelisse commented 1 month ago

This is totally parsed by the program, as opposed to the file path that is usually parsed by the kernel/operating system.

tnqn commented 1 month ago

Thank you all for your feedback.

It looks reasonable. However, I'm wondering whether this was intentional decision due to some reasons.

@ardaguclu, I checked https://github.com/kubernetes/kubernetes/pull/50140 which added the flag and didn't find any discussion about the shorthand, I guess it wasn't intentional.

Need to verify that there will not be collision between -f and -F. This will need to get tested across windows/macOS/various linux distros.

@mpuckett159, as @apelisse explains, this is parsed by the program so the flag names are case-sensitive, otherwise the command kubectl get -l <selector> -L <label> would fail.

I created https://github.com/kubernetes/kubernetes/pull/127345 to implement it, could you please take a look?

soltysh commented 1 month ago

/kind feature

mpuckett159 commented 1 month ago

Apologies I misunderstood and we need to wait for more evidence for this before accepting. This issue should be fore gathering more feedback. Sorry for the churn/misunderstanding.