gateway-api icon indicating copy to clipboard operation
gateway-api copied to clipboard

feat: kubectl-compliant get specific resource

Open yashvardhan-kukreja opened this issue 9 months ago • 5 comments

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

yashvardhan-kukreja avatar May 01 '24 11:05 yashvardhan-kukreja

@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 avatar May 01 '24 11:05 k8s-ci-robot

[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 avatar May 01 '24 11:05 k8s-ci-robot

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.

k8s-ci-robot avatar May 01 '24 11:05 k8s-ci-robot

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.

gauravkghildiyal avatar May 01 '24 18:05 gauravkghildiyal

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.

k8s-ci-robot avatar May 02 '24 05:05 k8s-ci-robot

Yash, I'll assume the previous comment makes sense and close this out for now.

/close

gauravkghildiyal avatar Jun 06 '24 06:06 gauravkghildiyal

@gauravkghildiyal: Closed this PR.

In response to this:

Yash, I'll assume the previous comment makes sense and close this out for now.

/close

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 avatar Jun 06 '24 06:06 k8s-ci-robot