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

Support wide output format for get commands (-o wide) #3129

Merged

Conversation

deszhou
Copy link
Member

@deszhou deszhou commented Jun 4, 2024

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #2889

Does this PR introduce a user-facing change?:

1.Support wide output format for get commands (-o wide)
2.Replace `Print` in BackendsPrinter with `PrintTable`
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: BackendTLSPolicy
metadata:
  name: enable-backend-tls
  namespace: default
spec:
  targetRef:
    group: ''
    kind: Service
    name: tls-backend
    sectionName: "443"
  tls:
    caCertRefs:
    - name: example-ca
      group: ''
      kind: ConfigMap
    hostname: www.example.com
EOF
  • backend
➜  ✗ gwctl get backend       
NAMESPACE  NAME         TYPE     AGE
default    backend      Service  106d
default    kubernetes   Service  106d
default    tls-backend  Service  44h

➜  ✗ gwctl get backend -owide
NAMESPACE  NAME         TYPE     AGE   REFERRED BY ROUTES  POLICIES
default    backend      Service  106d  None                0
default    kubernetes   Service  106d  None                0
default    tls-backend  Service  44h   default/backend     1
  • gatewayclass
➜  ✗ gwctl get gatewayclass       
NAME           CONTROLLER                                     ACCEPTED  AGE
eg             gateway.envoyproxy.io/gatewayclass-controller  True      104d
envoy-gateway  gateway.envoyproxy.io/gatewayclass-controller  True      95d

➜  ✗ gwctl get gatewayclass -owide
NAME           CONTROLLER                                     ACCEPTED  AGE   GATEWAYS
eg             gateway.envoyproxy.io/gatewayclass-controller  True      104d  1
envoy-gateway  gateway.envoyproxy.io/gatewayclass-controller  True      95d   0
  • gateway
➜  ✗ gwctl get gateway      
NAMESPACE  NAME  CLASS  ADDRESSES       PORTS  PROGRAMMED  AGE
default    eg    eg     172.18.255.201  80     True        106d

➜  ✗ gwctl get gateway -owide
NAMESPACE  NAME  CLASS  ADDRESSES       PORTS  PROGRAMMED  AGE   POLICIES  HTTPROUTES
default    eg    eg     172.18.255.201  80     True        106d  0         1
  • httproute
➜  ✗ gwctl get httproute
NAMESPACE  NAME     HOSTNAMES        PARENT REFS  AGE
default    backend  www.example.com  1            104d
➜  ✗ gwctl get httproute -owide
NAMESPACE  NAME     HOSTNAMES        PARENT REFS  AGE   POLICIES
default    backend  www.example.com  1            104d  0

  • namespace
➜  ✗ gwctl get ns
NAME                  STATUS  AGE
default               Active  104d
envoy-gateway-system  Active  104d
kube-node-lease       Active  104d
kube-public           Active  104d
kube-system           Active  104d
local-path-storage    Active  104d
metallb-system        Active  95d
monitoring            Active  94d
➜  ✗ gwctl get ns -owide
NAME                  STATUS  AGE   POLICIES
default               Active  104d  0
envoy-gateway-system  Active  104d  0
kube-node-lease       Active  104d  0
kube-public           Active  104d  0
kube-system           Active  104d  0
local-path-storage    Active  104d  0
metallb-system        Active  95d   0
monitoring            Active  94d   0

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/gwctl labels Jun 4, 2024
@k8s-ci-robot
Copy link
Contributor

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

@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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 4, 2024
Copy link
Member

@mlavacca mlavacca 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 to me, I left a minor comment 👍

/ok-to-test

gwctl/pkg/utils/types.go Outdated Show resolved Hide resolved
@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 4, 2024
Copy link
Member

@jongwooo jongwooo left a comment

Choose a reason for hiding this comment

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

The OutputFormatWIDE type is not currently handled by the switch statement below. Please add a case statement for OutputFormatWIDE type:

switch format {
case utils.OutputFormatJSON, utils.OutputFormatYAML:
pp.printClientObjects(clientObjects, format)
case utils.OutputFormatTable:
pp.printPoliciesTable(sortedPolicies)
default:
fmt.Fprintf(os.Stderr, "unknown output format '%s' found\n", format)
os.Exit(1)
}

switch format {
case utils.OutputFormatJSON, utils.OutputFormatYAML:
pp.printClientObjects(clientObjects, format)
case utils.OutputFormatTable:
pp.printCRDsTable(sortedPolicyCRDs)
default:
fmt.Fprintf(os.Stderr, "unknown output format '%s' found\n", format)
os.Exit(1)
}

Copy link
Member

@mlavacca mlavacca left a comment

Choose a reason for hiding this comment

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

Thanks, @yeedove

/lgtm

I'll let the approval to @gauravkghildiyal

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 5, 2024
Copy link
Member

@gauravkghildiyal gauravkghildiyal left a comment

Choose a reason for hiding this comment

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

Thanks @yeedove! This looks great, just have one minor request which should be quite straightforward.

if wide {
columnNames = []string{"NAMESPACE", "NAME", "TYPE", "REFERRED BY ROUTES", "AGE", "POLICIES"}
} else {
columnNames = []string{"NAMESPACE", "NAME", "TYPE", "REFERRED BY ROUTES", "AGE"}
Copy link
Member

Choose a reason for hiding this comment

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

I know this is a bit different from what's documented but I've come to realize that we should avoid any parameter from being displayed which needs additional calculations.

Calculating things like "REFERRED BY ROUTES" and "POLICIES" will take additional time (which becomes significant when there's lot's of resources). Hence it's preferrable to only include them in the -o wide format and not as a default.

tl;dr: Can you please move REFERRED BY ROUTES to wide format as well?

(In case you are wondering, we'll separately work on not calculating the additional values by default int the resourceModel -- as of now, that distinction doesn't exist`

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, done!

@gauravkghildiyal
Copy link
Member

Can you please also edit the release note and avoid the BackendsPrinter (to only focus on how the user experience is different)

@youngnick youngnick removed their request for review June 6, 2024 05:42
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 6, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 6, 2024
@gauravkghildiyal
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, yeedove

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2024
@gauravkghildiyal
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit 9787352 into kubernetes-sigs:main Jun 6, 2024
8 checks passed
BobyMCbobs pushed a commit to BobyMCbobs/kubernetes-sigs-gateway-api that referenced this pull request Jul 10, 2024
…s#3129)

* Support wide output format for get commands (-o wide)

* Add a case statement for OutputFormatWide type

* Move REFERRED BY ROUTES to wide format

* Move REFERRED BY ROUTES to wide format
BobyMCbobs pushed a commit to BobyMCbobs/kubernetes-sigs-gateway-api that referenced this pull request Jul 22, 2024
…s#3129)

* Support wide output format for get commands (-o wide)

* Add a case statement for OutputFormatWide type

* Move REFERRED BY ROUTES to wide format

* Move REFERRED BY ROUTES to wide format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/gwctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support wide output format for get commands (-o wide)
5 participants