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

feat: kubectl-compliant get specific resource #3042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yashvardhan-kukreja
Copy link
Contributor

@yashvardhan-kukreja yashvardhan-kukreja commented May 1, 2024

What type of PR is this?

/kind feature

(+bug too because despite intending to gwctl couldn't do this)

What this PR does / why we need it:

Introduces the ability to do

gwctl get <RESOURCE_TYPE> <NAME>

and

gwctl get <RESOURCE_TYPE>/<NAME>

Which issue(s) this PR fixes:

Fixes #3041

Does this PR introduce a user-facing change?:

Yes, user can now get specific resources from gwctl in a kubectl-compliant manner.

After this PR

❯ ./bin/gwctl get gatewayclass default-match-example         
NAME                   CONTROLLER                  ACCEPTED  AGE
default-match-example  acme.io/gateway-controller  Unknown   4d20h

~/Projects/GoProjects/gateway-api/gwctl issue-3041/get-specific-resource*                                                                                                                           16:52:54
❯ ./bin/gwctl get gatewayclass/default-match-example
NAME                   CONTROLLER                  ACCEPTED  AGE
default-match-example  acme.io/gateway-controller  Unknown   4d20h

Before this PR

❯ ./bin/gwctl get gatewayclass/default-match-example
Unrecognized RESOURCE_TYPE

~/Projects/GoProjects/gateway-api/gwctl main* ⇡                                                                                                                                                     16:53:45
❯ ./bin/gwctl get gatewayclass default-match-example
Error: accepts 1 arg(s), received 2
Usage:
  gwctl get {namespaces|gateways|gatewayclasses|policies|policycrds|httproutes} [flags]

Flags:
  -A, --all-namespaces     If present, list requested resources from all namespaces.
  -h, --help               help for get
  -n, --namespace string    (default "default")
  -l, --selector string    Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints.

Global Flags:
      --add_dir_header                   If true, adds the file directory to the header of the log messages
      --alsologtostderr                  log to standard error as well as files (no effect when -logtostderr=true)
      --kubeconfig string                path to kubeconfig file (default is the KUBECONFIG environment variable and if it isn't set, falls back to $HOME/.kube/config)
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory (no effect when -logtostderr=true)
      --log_file string                  If non-empty, use this log file (no effect when -logtostderr=true)
      --log_file_max_size uint           Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
      --logtostderr                      log to standard error instead of files (default true)
      --one_output                       If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
      --skip_headers                     If true, avoid header prefixes in the log messages
      --skip_log_headers                 If true, avoid headers when opening log files (no effect when -logtostderr=true)
      --stderrthreshold severity         logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true) (default 2)
  -v, --v Level                          number for the log level verbosity
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

failed to execute command: accepts 1 arg(s), received 2

Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
@k8s-ci-robot
Copy link
Contributor

@yashvardhan-kukreja: The label(s) kind/(+bug, kind/too, kind/because, kind/despite, kind/[intending, kind/to](https://github.com/kubernetes-sigs/gateway-api/blob/main/gwctl/cmd/get.go#l170-l172), kind/gwctl, kind/[couldn't, kind/do, kind/this](https://github.com/kubernetes-sigs/gateway-api/blob/main/gwctl/cmd/get.go#l41)) cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this?

What this PR does / why we need it:

/kind feature (+bug too because despite intending to gwctl couldn't do this)

Which issue(s) this PR fixes:

Fixes #3041

Does this PR introduce a user-facing change?:

Yes, user can now get specific resources from gwctl in a kubectl-compliant manner.

After this PR

❯ ./bin/gwctl get gatewayclass default-match-example         
NAME                   CONTROLLER                  ACCEPTED  AGE
default-match-example  acme.io/gateway-controller  Unknown   4d20h

~/Projects/GoProjects/gateway-api/gwctl issue-3041/get-specific-resource*                                                                                                                           16:52:54
❯ ./bin/gwctl get gatewayclass/default-match-example
NAME                   CONTROLLER                  ACCEPTED  AGE
default-match-example  acme.io/gateway-controller  Unknown   4d20h

Before this PR

❯ ./bin/gwctl get gatewayclass/default-match-example
Unrecognized RESOURCE_TYPE

~/Projects/GoProjects/gateway-api/gwctl main* ⇡                                                                                                                                                     16:53:45
❯ ./bin/gwctl get gatewayclass default-match-example
Error: accepts 1 arg(s), received 2
Usage:
 gwctl get {namespaces|gateways|gatewayclasses|policies|policycrds|httproutes} [flags]

Flags:
 -A, --all-namespaces     If present, list requested resources from all namespaces.
 -h, --help               help for get
 -n, --namespace string    (default "default")
 -l, --selector string    Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints.

Global Flags:
     --add_dir_header                   If true, adds the file directory to the header of the log messages
     --alsologtostderr                  log to standard error as well as files (no effect when -logtostderr=true)
     --kubeconfig string                path to kubeconfig file (default is the KUBECONFIG environment variable and if it isn't set, falls back to $HOME/.kube/config)
     --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
     --log_dir string                   If non-empty, write log files in this directory (no effect when -logtostderr=true)
     --log_file string                  If non-empty, use this log file (no effect when -logtostderr=true)
     --log_file_max_size uint           Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
     --logtostderr                      log to standard error instead of files (default true)
     --one_output                       If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
     --skip_headers                     If true, avoid header prefixes in the log messages
     --skip_log_headers                 If true, avoid headers when opening log files (no effect when -logtostderr=true)
     --stderrthreshold severity         logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true) (default 2)
 -v, --v Level                          number for the log level verbosity
     --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

failed to execute command: accepts 1 arg(s), received 2

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 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 1, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yashvardhan-kukreja
Once this PR has been reviewed and has the lgtm label, please assign gauravkghildiyal for approval. For more information see the Kubernetes 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

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 1, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @yashvardhan-kukreja. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@gauravkghildiyal
Copy link
Member

Thanks @yashvardhan-kukreja

Let's keep the cobra.RangeArgs(1, 2) but not expand the usage to <RESOURCE_TYPE>/<NAME>

  • kubectl get <KIND/Name> is more for enabling the case when you are fetching resources of multiple kinds together i.e. something like kubectl get service/my-service pods/my-pods secret/my-secret, which is what we may not want to complicate things with for the time being
  • There's also the aspect that we're really reserving the <KIND/Name> pattern to be used with gwctl get backends customservicekind/custom-service-name or gwctl get policies <policykind>/<policyname>. Things are different for kubectl becuase the resource_type always matches a kind, but for gwctl, the resource_types like backends and policies are more like containers for a class of resource_types.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gwctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

[gwctl] (bug too) kubectl-compliant get subcommand with per-resource access
3 participants