-
Notifications
You must be signed in to change notification settings - Fork 480
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 JSON and YAML output format in get commands (-o json
)
#2940
Support JSON and YAML output format in get commands (-o json
)
#2940
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
Pending:
|
e32c79b
to
e18bf13
Compare
Hi @robscott @gauravkghildiyal , can you ptal at this PR? PS: majority of the changes are just tests 😬 |
/assign |
Hi folks, I seem to be facing this error under
Seems like an unexpected issue with the import Can anyone of you help me with this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, @yashsingh74! In addition to the comments I left in the review, I have one broader comment:
I see a lot of code duplication in this PR: the logic to group and sort GatewayClass
es, Gateway
s, HTTPRoute
s is almost the same (and I think it should be 100% the same, I left a couple of comments about it). Do we really need to have resource-specific printers or can we have only one printer that deals with client.Object
? We could have a common logic that sorts the objects based on Namespace
and Name
and print it out.
In addition, the difference between json
and yaml
functions is very tiny; we could just add a parameter to the print function signature to tell whether the output needs to be json or yaml, instead of having output-specific functions.
fd9cdfe
to
00fb01e
Compare
Hi @mlavacca , I just did a major refactor introducing a some factories and interfaces, and got rid of a majority of the code duplication. Please take a look. Thank you |
c84847e
to
f907808
Compare
/test pull-gateway-api-test |
@gauravkghildiyal I was under the impression that we might wanna keep things compliant with how kubectl works i.e. returning a list for non-one-elements sized items, else returning the items itself. But if you're explicitly calling this out, we can just straightaway returning a list only instead |
@gauravkghildiyal addressed your comments |
1acd08f
to
5ce4781
Compare
I think kubectl as well behaves in that same manner I'm describing. Anyways, I really don't want to add more logic to this PR and keep it on hold. Let's tackle it separately. ❯ kubectl create ns my-ns
namespace/my-ns created
❯ kubectl create secret generic my-secret -n my-ns
secret/my-secret created
❯ kubectl get secret -n my-ns
NAME TYPE DATA AGE
my-secret Opaque 0 8s
❯ kubectl get secret -n my-ns -o yaml
apiVersion: v1
items:
- apiVersion: v1
kind: Secret
metadata:
creationTimestamp: "2024-04-30T18:06:22Z"
name: my-secret
namespace: my-ns
resourceVersion: "4005867"
uid: 2ff8f11c-baed-45d9-8de1-2d0fb9add3d7
type: Opaque
kind: List
metadata:
resourceVersion: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think this should be the last, sorry for not calling this out earlier)
@@ -250,3 +252,175 @@ Status: {} | |||
}) | |||
} | |||
} | |||
|
|||
// TestGatewayClassesPrinter_PrintJson tests the -o json output of the `get` subcommand | |||
func TestGatewayClassesPrinter_PrintJson(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please squash the separate tests for PrintJSON and PrintYAML into one, since they should mostly be the same with the same setup, with the only difference in the assertion/comparision of output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sorry for leaving them like this, they were a consequence of the previous design of separate JSON and YAML printers.
No worries at all, feel absolutely free to call out any concerns you'd like to mention. I would be happy to resolve them. Anyway, highly appreciate your reviews. |
5ce4781
to
c9a0b10
Compare
c9a0b10
to
7138fc5
Compare
@gauravkghildiyal squashed the tests too |
Thank you for the patience! /lgtm |
/approve |
[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 |
/lgtm |
Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
9e83440
to
846f24d
Compare
@gauravkghildiyal just squashed the commits and rebased them on top of HEAD. Can you lgtm again? |
/lgtm |
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #2931 #2932
Does this PR introduce a user-facing change?: