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

[gwctl] Expand the output of gwctl describe gatewayclass #2930

Conversation

yashvardhan-kukreja
Copy link
Contributor

@yashvardhan-kukreja yashvardhan-kukreja commented Apr 3, 2024

What type of PR is this?

/kind gep

What this PR does / why we need it:

This PR introduces an expansion in the output of gwctl describe gatewayclass/gatewayclasses <name> as per the expectation of this GEP.

Checkout the example in the last section.

Note on the "null" values of Labels/Annotations**

If you notice in the above output, the "empty" value of Labels is being parsed as "null" despite the GEP expecting it to be "" (analogous to how kubectl describe works with empty values).

The reason this happens in our situation but not with kubectl describe is that we're using the YAML unmarshaler directly over Labels which is of the type *map[string]string and it inherently deals with the zero-values of pointers (to a map in this case) by stringifying it to "null" instead of "".

On the other hand, kubectl describe doesn't seem to rely upon the YAML Unmarshaller at all [1]. It describe resources flexibly yet in the hard way giving itself the opportunity to realise the zero-ness of custom types like pointers, maps, etc. and spit out <NONE> for them instead.

What's the solution then?

  • As a user, I don't care much between "null" and "", so let's just continue with the existing implementation of "null".
  • We change the type from *map[string]string to map[string]string (without omitempty): This would print out {} instead of null - Not sure how would one be more favorable than the other though
  • We change the logic of GatewayClassesPrinter) PrintDescribeView[2] to not use YAML unmarshaller[3] at all. Instead it can use the Describer interface under kubectl. A very high-level skim across kubectl insinuates that we can use the GenericResourceDescriber[4] to help describing none-native (corev1, appsv1, etc.) types. This would help produce an output identical to kubectl describe gatewayclass <NAME> and this would've its own slight differences with the GEP, so not sure it would be worth the effort.

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?:

The output of `gwctl describe gatewayclass <NAME>` is enhanced further.

For example:
GatewayClass manifest applied

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: gatewayclass-observed-generation-bump
spec:
  controllerName: "example.net/gateway-controller"
  description: "old"

Previous output of gwctl describe gatewayclass gatewayclass-observed-generation-bump (Before this PR)

Name: gatewayclass-observed-generation-bump
ControllerName: example.net/gateway-controller
Description: old

New output of gwctl describe gatewayclass gatewayclass-observed-generation-bump (After this PR)

Name: gatewayclass-observed-generation-bump
Labels: null
Annotations:
  kubectl.kubernetes.io/last-applied-configuration: |
    {"apiVersion":"gateway.networking.k8s.io/v1","kind":"GatewayClass","metadata":{"annotations":{},"name":"gatewayclass-observed-generation-bump"},"spec":{"controllerName":"example.net/gateway-controller","description":"old"}}
APIVersion: gateway.networking.k8s.io/v1alpha2
Kind: GatewayClass
Metadata:
  creationTimestamp: "2024-04-03T12:23:58Z"
  generation: 1
  resourceVersion: "2428"
  uid: 2581bf37-7a76-4084-82b3-e26b5438f9e8
ControllerName: example.net/gateway-controller
Description: old
Status:
  conditions:
  - lastTransitionTime: "1970-01-01T00:00:00Z"
    message: Waiting for controller
    reason: Waiting
    status: Unknown
    type: Accepted

References:
[0] Cause of vendor-ed changes
[1] Not a single mention of yaml package in the imports of kubectl's describe backend
[2] PrintDescribeView method
[3] Usage of YAML Unmarshal
[4] GenericResourceDescriber

@k8s-ci-robot k8s-ci-robot added kind/gep PRs related to Gateway Enhancement Proposal(GEP) do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 3, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @yashvardhan-kukreja!

It looks like this is your first PR to kubernetes-sigs/gateway-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 3, 2024
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/gwctl labels Apr 3, 2024
@youngnick youngnick requested review from robscott and removed request for youngnick April 4, 2024 00:02
@robscott
Copy link
Member

robscott commented Apr 4, 2024

Thanks for the work on this @yashvardhan-kukreja!

@dprotaso I think you've got the most context on the applyconfigurations you just added, does this change to vendor look correct to you?

@gauravkghildiyal
Copy link
Member

Thanks for the work on this @yashvardhan-kukreja!

@dprotaso I think you've got the most context on the applyconfigurations you just added, does this change to vendor look correct to you?

We had previously decided to not commit vendor changes to gwctl sub folder (similar to how the parent folder does not have vendor). I think we can still continue with that?

If we do decide to make vendor changes, it would be nice to do them in an independent PR for the first time.

CC: @yashvardhan-kukreja

@gauravkghildiyal
Copy link
Member

/assign
/remove-label kind/gep
/retitle [gwctl] Expand the output of gwctl describe gatewayclass

@k8s-ci-robot
Copy link
Contributor

@gauravkghildiyal: The label(s) /remove-label kind/gep cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/assign
/remove-label kind/gep
/retitle [gwctl] Expand the output of gwctl describe gatewayclass

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 changed the title GEP: Expand the output of gwctl describe gatewayclass [gwctl] Expand the output of gwctl describe gatewayclass Apr 4, 2024
@gauravkghildiyal
Copy link
Member

/remove-kind gep

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. and removed kind/gep PRs related to Gateway Enhancement Proposal(GEP) labels Apr 4, 2024
@yashvardhan-kukreja
Copy link
Contributor Author

yashvardhan-kukreja commented Apr 4, 2024

If we do decide to make vendor changes, it would be nice to do them in an independent PR for the first time.

CC: @yashvardhan-kukreja

So, the vendor-ed changes are only required to call these LOC so as to help resolving the right apiVersion and Kind.

I presume, for the time being, we can hardcode them as GatewayClass (for Kind) and gateway.networking.k8s.io/v1alpha2 (for ApiVersion)

This would help us get rid of this import hence, allowing us to get rid of vendor-ed changes as well.

wdyt

@dprotaso
Copy link
Contributor

dprotaso commented Apr 4, 2024

Yeah there's no reason to vendor the go deps in gwctl - you can remove that whole directory

@yashvardhan-kukreja yashvardhan-kukreja force-pushed the issue-2796/gwctl-describe-gatewayclass branch from 48f6f5a to 01a2aa0 Compare April 4, 2024 05:13
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 4, 2024
@yashvardhan-kukreja
Copy link
Contributor Author

Hi everyone, I got rid of vendor/ and added it to .gitignore as well

@yashvardhan-kukreja
Copy link
Contributor Author

Hi @dprotaso @gauravkghildiyal , mind taking a look at this one?

Thanks!

@yashvardhan-kukreja
Copy link
Contributor Author

Hi @mlavacca,
would you mind adding the ok-to-test label to this PR?

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.

/ok-to-test

.gitignore Outdated
@@ -45,6 +45,7 @@ Session.vim
/_tmp/
*.un~
.vagrant
vendor
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
vendor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this intentionally to ensure that the contributors don't end up committing the vendor/ (it seemed like only a build-time req. anyway).

Should I still remove it from gitignore?

Copy link
Member

Choose a reason for hiding this comment

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

This need not block the PR, but we can likely skip this update in this PR, and if required send an independent one. Reason being, I actually don't recall why vendor was never added to .gitignore (although we infact don't commit vendor) -- this may just turn into another long discussion which may block this PR even longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha makes sense!

gwctl/pkg/printer/gatewayclasses.go Outdated Show resolved Hide resolved
gwctl/pkg/printer/gatewayclasses.go Outdated Show resolved Hide resolved
gwctl/pkg/printer/gatewayclasses.go Outdated Show resolved Hide resolved
gwctl/pkg/utils/types.go Outdated Show resolved Hide resolved
@yashvardhan-kukreja yashvardhan-kukreja force-pushed the issue-2796/gwctl-describe-gatewayclass branch from fc9524a to 65da0b6 Compare April 10, 2024 10:04
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
@yashvardhan-kukreja yashvardhan-kukreja force-pushed the issue-2796/gwctl-describe-gatewayclass branch from 65da0b6 to bcffb8b Compare April 11, 2024 12:47
@yashvardhan-kukreja
Copy link
Contributor Author

apologies for the ping @mlavacca : just in case you missed the above commits and messages.

Thank you

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 @yashvardhan-kukreja! (and sorry for the delay)

Mostly looks good, though one thing: The tabular structure of DirectlyAttachedPolicies field as mentioned in https://gateway-api.sigs.k8s.io/geps/gep-2722/ is actually intentional.

DirectlyAttachedPolicies:
  TYPE                   NAME
  ----                   ----
  TimeoutPolicy.bar.com  demo-timeout-policy-on-gatewayclass

Ideally it would be nice to have it in the same PR, but if you want to send a separate PR for that, lets keep the issue open after this PR merges (and not use "Fixed" in the PR description)


// views ordered with respect to https://deploy-preview-2723--kubernetes-sigs-gateway-api.netlify.app/geps/gep-2722/#:~:text=gwctl%20describe%20gatewayclass%20foo%2Dcom%2Dexternal%2Dgateway%2Dclass
Copy link
Member

Choose a reason for hiding this comment

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

nit: You can either remove this comment, or change the link to a permanent one at https://gateway-api.sigs.k8s.io/geps/gep-2722/

Kind: kind,
},
{
Metadata: &metav1.ObjectMeta{
Copy link
Member

Choose a reason for hiding this comment

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

Lets follow a consistent approach as:

metadata := crd.ObjectMeta.DeepCopy()
metadata.Labels = nil
metadata.Annotations = nil
metadata.Name = ""
metadata.Namespace = ""

where we remove duplicated fields from metadata and print the rest? (This would allow for possible future expansion of the fields within Metadata to be included by default)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sounds neat

.gitignore Outdated
@@ -45,6 +45,7 @@ Session.vim
/_tmp/
*.un~
.vagrant
vendor
Copy link
Member

Choose a reason for hiding this comment

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

This need not block the PR, but we can likely skip this update in this PR, and if required send an independent one. Reason being, I actually don't recall why vendor was never added to .gitignore (although we infact don't commit vendor) -- this may just turn into another long discussion which may block this PR even longer.

@@ -286,6 +287,11 @@ func fetchGatewayClasses(ctx context.Context, k8sClients *common.K8sClients, fil
return []gatewayv1.GatewayClass{}, err
}

// because api-server doesn't return TypeMeta in `gatewayClass`
gcApplyConfig := apisv1beta1.GatewayClass(gatewayClass.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Ah nice catch! This may just be a bit more involved.

The thing is, because we construct the gatewayClass object with the v1 versioned struct (i.e. &gatewayv1.GatewayClass{}, client-go will fetch the GatewayClass for the v1 version. This means the correct APIVersion would correspond to the v1 package (and not apisv1beta1 = v1beta1):

gcApplyConfig := apisv1.GatewayClass(gatewayClass.Name)

Having said that, if we think about it a bit more, use of ApplyConfig isn't giving any real advantage here. How about something like this:

		gatewayClass.APIVersion = gatewayv1.GroupVersion.String()
		gatewayClass.Kind = reflect.TypeOf(gatewayClass).Elem().Name()

(Infact, using gatewayClass.Kind = "GatewayClass" would also just have been good enough)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh good point, will take care of this.

@gauravkghildiyal
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 17, 2024
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
@yashvardhan-kukreja
Copy link
Contributor Author

Hi @gauravkghildiyal
Took care of all the comments you made. Feel free to resolve them if you're happy with the newer commit.

@yashvardhan-kukreja
Copy link
Contributor Author

Mostly looks good, though one thing: The tabular structure of DirectlyAttachedPolicies field as mentioned in https://gateway-api.sigs.k8s.io/geps/gep-2722/ is actually intentional.

Makes sense though I noticed that the same concern is with other DescribeViews such as the ones corresponding to Gateway and HTTPRoute

So, I'd suggest a separate PR addressing all of these ones. What do you think?

@@ -286,6 +285,10 @@ func fetchGatewayClasses(ctx context.Context, k8sClients *common.K8sClients, fil
return []gatewayv1.GatewayClass{}, err
}

// because api-server doesn't return TypeMeta in `gatewayClass`
Copy link
Member

Choose a reason for hiding this comment

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

nit: kube-apiserver does infact return the TypeMeta (it always does)...this mishap happens when that object is decoded. We can likely add kubernetes/kubernetes#80609 as reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh yeah of course it does, my bad (else kubectl-like clients would never show type meta lol), I meant client-go I guess haha.

Anyway, let me change this comment to a ref to the above issue instead.

Thanks for pointing it out!

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.

Mostly looks good, though one thing: The tabular structure of DirectlyAttachedPolicies field as mentioned in https://gateway-api.sigs.k8s.io/geps/gep-2722/ is actually intentional.

Makes sense though I noticed that the same concern is with other DescribeViews such as the ones corresponding to Gateway and HTTPRoute

So, I'd suggest a separate PR addressing all of these ones. What do you think?

Yep right! Sorry this is lack of clarity from my side that "Expand the output of XXX" is also expecting this change.

Sure lets tackle that in a separate PR for gatewayclass


Also, while you are editing the PR description to remove the "Fixed" keyword, FYI, we do infact want that particular format for the release note:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, please enter a release note below:
-->
```release-note

```

This should resolve the do-not-merge/release-note-label-needed label

@gauravkghildiyal
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, yashvardhan-kukreja

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 17, 2024
@yashvardhan-kukreja
Copy link
Contributor Author

Whoops, ptal now.
Thanks :)

Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
@gauravkghildiyal
Copy link
Member

@yashvardhan-kukreja sorry one last thing. Can you please keep the thing with the "release notes quote" a self contained statement -- even a one liner helps (in this case, it could simply just be the PR title itself, or equivalent) Thanks

@yashvardhan-kukreja
Copy link
Contributor Author

Looks good @gauravkghildiyal ?

@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 Apr 18, 2024
@k8s-ci-robot k8s-ci-robot merged commit 90e22fe into kubernetes-sigs:main Apr 18, 2024
8 checks passed
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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants