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

Improve utilities for gwctl describe and add more info to gateway descriptions #2999

Merged

Conversation

gauravkghildiyal
Copy link
Member

@gauravkghildiyal gauravkghildiyal commented Apr 20, 2024

What this PR does / why we need it:

  • Add helpers to print gwctl describe views and Tables
  • Add more information when describing Gateways (like attached routes)
  • Discover events associated with Gateways and output them when describing Gateways.
Example:
❯ gwctl describe gateways
Name: demo-gateway-1
Namespace: default
Labels: null
Annotations:
  kubectl.kubernetes.io/last-applied-configuration: |
    {"apiVersion":"gateway.networking.k8s.io/v1beta1","kind":"Gateway","metadata":{"annotations":{},"name":"demo-gateway-1","namespace":"default"},"spec":{"gatewayClassName":"foo-com-external-gateway-class","listeners":[{"name":"http","port":80,"protocol":"HTTP"}]}}
APIVersion: gateway.networking.k8s.io/v1
Kind: Gateway
Metadata:
  creationTimestamp: "2024-04-03T04:27:12Z"
  generation: 1
  managedFields:
  - apiVersion: gateway.networking.k8s.io/v1beta1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
      f:spec:
        .: {}
        f:gatewayClassName: {}
        f:listeners:
          .: {}
          k:{"name":"http"}:
            .: {}
            f:allowedRoutes:
              .: {}
              f:namespaces:
                .: {}
                f:from: {}
            f:name: {}
            f:port: {}
            f:protocol: {}
    manager: kubectl-client-side-apply
    operation: Update
    time: "2024-04-03T04:27:12Z"
  resourceVersion: "2531077"
  uid: 034c4490-6b0d-41f0-8d90-3948dbae4b6c
Spec:
  gatewayClassName: foo-com-external-gateway-class
  listeners:
  - allowedRoutes:
      namespaces:
        from: Same
    name: http
    port: 80
    protocol: HTTP
Status:
  conditions:
  - lastTransitionTime: "1970-01-01T00:00:00Z"
    message: Waiting for controller
    reason: Pending
    status: Unknown
    type: Accepted
  - lastTransitionTime: "1970-01-01T00:00:00Z"
    message: Waiting for controller
    reason: Pending
    status: Unknown
    type: Programmed
AttachedRoutes:
  Kind       Name
  ----       ----
  HTTPRoute  default/demo-httproute-1
  HTTPRoute  default/demo-httproute-2
  HTTPRoute  default/demo-httproute-3
  HTTPRoute  ns2/demo-httproute-4
DirectlyAttachedPolicies:
  Type                       Name
  ----                       ----
  HealthCheckPolicy.foo.com  default/demo-health-check-1
  RetryOnPolicy.foo.com      default/demo-retry-policy-1
EffectivePolicies:
  HealthCheckPolicy.foo.com:
    sampleParentField:
      sampleField: hello
  RetryOnPolicy.foo.com:
    sampleParentField:
      sampleField: namaste
  TimeoutPolicy.bar.com:
    timeout1: parent
    timeout2: child
    timeout3: parent
    timeout4: child
Events:
  Type     Reason  Age  From                   Message
  ----     ------  ---  ----                   -------
  Warning  SYNC    12h  my-gateway-controller  Some message here

Notes for reviewer:
Reviewing individual commits in order might be easier

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/gwctl labels Apr 20, 2024
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 20, 2024
@gauravkghildiyal
Copy link
Member Author

/cc @mlavacca

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 20, 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 Apr 23, 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.

Apart from a very minor nit in a comment, it looks good to me. I unfortunately do not feel 100% confident in reviewing this code as I lack some context. I'd love to hear some other opinions as well here :)

gwctl/pkg/printer/common.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks for all the work on this @gauravkghildiyal!

eventList := &corev1.EventList{}
options := &client.ListOptions{
FieldSelector: fields.AndSelectors(
fields.OneTermEqualSelector("involvedObject.kind", "Gateway"),
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't you also need group here? Otherwise you might end up with some unexpected data related to other Gateway resources like Istio Gateways.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch!

Indeed we would need something of that sorts...the right choice seems to be the UID (which is what kubectl uses as well). Reason being, there's no neat way to use the API to only query the APIGroup (and not the APIVersion) which would have caused problems with gatewayv1 vs gatewayv1beta1. Anyways, UID doesn't cause any such issues.

Thanks a lot for the great find

for _, gatewayNode := range resourceModel.Gateways {
eventList := &corev1.EventList{}
options := &client.ListOptions{
FieldSelector: fields.AndSelectors(
Copy link
Member

Choose a reason for hiding this comment

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

This seems like it would get painful, would it be better to require that Gateway controllers set specific labels on Events they're publishing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Anything specific in your mind about the pain points? I guess some should get addressed as described in the other comment https://github.com/kubernetes-sigs/gateway-api/pull/2999/files#r1585597856 and we may not need it for the time being.

Comment on lines 97 to 101
// extractorFunc are used to build an index for Event objects. This is
// required to properly mock things like the following when listing Events
// associated with a resource:
//
// fields.OneTermEqualSelector("involvedObject.kind", "Gateway")
Copy link
Member

Choose a reason for hiding this comment

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

If I'm understanding correctly, this is more for just test mocks or something right? It looks like you're using this to list events. Maybe adjust the description to note that this is the best way to be able to list events that involve a specific resource?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are absolutely right. Yes the comment could use some improvement, thanks for the suggestion. Hope it's somewhat more meaningful now.

@robscott
Copy link
Member

robscott commented May 1, 2024

Thanks @gauravkghildiyal!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 1, 2024
@k8s-ci-robot k8s-ci-robot merged commit f7ab534 into kubernetes-sigs:main May 1, 2024
8 checks passed
@gauravkghildiyal gauravkghildiyal deleted the gateway-describer branch May 1, 2024 07:25
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. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants