-
Notifications
You must be signed in to change notification settings - Fork 491
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
Implemented gwctl describe policycrds
#2872
Implemented gwctl describe policycrds
#2872
Conversation
Hi @Devaansh-Kumar. 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. |
/assign |
gwctl/pkg/policymanager/manager.go
Outdated
@@ -196,6 +201,36 @@ func (p PolicyCRD) IsClusterScoped() bool { | |||
return p.crd.Spec.Scope == apiextensionsv1.ClusterScoped | |||
} | |||
|
|||
func (p PolicyCRD) Spec() map[string]interface{} { |
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.
These helper functions seem to be purely concerned with printing at the moment. Lets keep them in the printer package.
gwctl/pkg/printer/policies.go
Outdated
@@ -148,3 +150,65 @@ func (pp *PoliciesPrinter) PrintDescribeView(policies []policymanager.Policy) { | |||
} | |||
} | |||
} | |||
|
|||
type policyCrdDescribeView struct { | |||
// PolicyCrd *apiextensionsv1.CustomResourceDefinition `json:",omitempty"` |
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.
Does this comment need to be cleaned up?
gwctl/pkg/printer/policies_test.go
Outdated
@@ -354,3 +354,155 @@ timeoutpolicies.bar.com Direct Namespaced 5m | |||
t.Errorf("Unexpected diff\ngot=\n%v\nwant=\n%v\ndiff (-want +got)=\n%v", got, want, diff) | |||
} | |||
} | |||
|
|||
func TestPolicyCrd_PrintDescribeView(t *testing.T) { | |||
// fakeClock := testingclock.NewFakeClock(time.Now()) |
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 clean this up if we don't need a fakeClock? Else, can we evaluate if we need a fakeClock and use it?
gwctl/pkg/printer/policies_test.go
Outdated
params := utils.MustParamsForTest(t, common.MustClientsForTest(t, objects...)) | ||
pp := &PoliciesPrinter{ | ||
Out: &bytes.Buffer{}, | ||
// Clock: fakeClock, |
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.
Same comment as above.
gwctl/pkg/printer/policies_test.go
Outdated
Kind: CustomResourceDefinition | ||
Metadata: | ||
creationTimestamp: null | ||
labels: |
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.
For things like label
, annotations
etc which we're including outside the metadata
, maybe we should not print them twice?
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.
Agreed, I will remove the label
and annotations
outside as its more difficult to remove from within metadata
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.
Lets try using concrete types and see if that helps ease this as well.
policyCrdList = params.PolicyManager.GetCRDs() | ||
} else { | ||
var found bool | ||
policyCrd, found := params.PolicyManager.GetCRD(args[1]) |
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.
For users, args[1] would usually mean the actual "name" of the CRD. It's worth noting here that the "name" of the CRD is not the policyCrdID
which is being used as the "key" for the policyCRDs map within manager.go
.
This means that if someone does gwctl describe policycrds mycrd.foo.bar
, it might not work.
I think we need to modify the GetCRD
function to accept a crdName
and then manually search for the CRD in the map and return the right one.
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.
Yes I agree with this. I will make the changes
gwctl/pkg/printer/policies.go
Outdated
APIVersion string `json:",omitempty"` | ||
Kind string `json:",omitempty"` | ||
Metadata map[string]interface{} `json:",omitempty"` | ||
Spec map[string]interface{} `json:",omitempty"` |
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.
Will using the concrete type here instead of map[string]interface{}
make things simple? Any reason why we purposely want to keep this generic?
Same comment for Metadata and Status
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.
Yes, initially I used concrete types itself, but the output was not being parsed properly by yaml
package, so I had to convert it to map[string]interface{}
.
Should I leave it as it is or do you suggest any other alternative?
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 you elaborate on what problem you run into if you use something like this:
Metadata *metav1.ObjectMeta `json:",omitempty"`
Spec *apiextensionsv1.CustomResourceDefinitionSpec `json:",omitempty"`
Status *apiextensionsv1.CustomResourceDefinitionStatus `json:",omitempty"`
I think this should make things very easy. Am I missing something?
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.
My mistake, I was not dereferencing the type, due to which it wasnt parsing properly. I works fine now
87a5362
to
a52b454
Compare
@gauravkghildiyal I have resolved the above issues, just reconfirm this comment once: #2872 (comment) |
gwctl/pkg/printer/policies.go
Outdated
APIVersion string `json:",omitempty"` | ||
Kind string `json:",omitempty"` | ||
Metadata map[string]interface{} `json:",omitempty"` | ||
Spec map[string]interface{} `json:",omitempty"` |
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 you elaborate on what problem you run into if you use something like this:
Metadata *metav1.ObjectMeta `json:",omitempty"`
Spec *apiextensionsv1.CustomResourceDefinitionSpec `json:",omitempty"`
Status *apiextensionsv1.CustomResourceDefinitionStatus `json:",omitempty"`
I think this should make things very easy. Am I missing something?
gwctl/pkg/printer/policies_test.go
Outdated
Kind: CustomResourceDefinition | ||
Metadata: | ||
creationTimestamp: null | ||
labels: |
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.
Lets try using concrete types and see if that helps ease this as well.
gwctl/pkg/printer/policies.go
Outdated
Status map[string]interface{} `json:",omitempty"` | ||
} | ||
|
||
func (pp *PoliciesPrinter) PolicyCrd_PrintDescribeView(policyCrds []policymanager.PolicyCRD) { |
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.
This isn't a blocker, but it would be nice if we could adjust the overall evolving names of other functions as well:
PrintPoliciesGetView
PrintPoliciesDescribeView
PrintPolicyCRDsGetView
PrintPolicyCRDsDescribeView
If we do include this change, lets correspondingly change the Test function names as well :)
a52b454
to
1f2fb32
Compare
@gauravkghildiyal I have resolved the above issues, please review |
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 @Devaansh-Kumar, almost there!
Can we try to address https://github.com/kubernetes-sigs/gateway-api/pull/2872/files#r1534775341 please?
1f2fb32
to
070bdb1
Compare
@Devaansh-Kumar I see you pushed some new changes...is https://github.com/kubernetes-sigs/gateway-api/pull/2872/files#r1534775341 still a work in progress? /ok-to-test |
@gauravkghildiyal I have already left a comment on that thread before, I think I have already solved it but maybe you are asking for something else that I dont understand. You had told to not print out |
Can we try to get those outside Metadata please, as per the original plan. I'm hoping it won't be too challenging now (correct me if I'm wrong) |
Ok, now I understood what you wanted. You want me to parse the entire |
070bdb1
to
87cd786
Compare
@gauravkghildiyal I have tried out your suggested change here by creating a new function |
gwctl/pkg/printer/policies_test.go
Outdated
Labels: | ||
gateway.networking.k8s.io/policy: inherited | ||
Metadata: | ||
creationTimestamp: null |
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.
Consider using fakeClock
to validate the output for creationTimestamp
.
Ref. #2822
fakeClock := testingclock.NewFakeClock(time.Now())
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.
+1
How about something like this: type policyCrdDescribeView struct {
Name string `json:",omitempty"`
Namespace string `json:",omitempty"`
APIVersion string `json:",omitempty"`
Kind string `json:",omitempty"`
Labels map[string]string `json:",omitempty"`
Annotations map[string]string `json:",omitempty"`
Metadata *metav1.ObjectMeta `json:",omitempty"`
Spec *apiextensionsv1.CustomResourceDefinitionSpec `json:",omitempty"`
Status *apiextensionsv1.CustomResourceDefinitionStatus `json:",omitempty"`
}
.
.
.
metadata := crd.ObjectMeta.DeepCopy()
// Remove fields which are printed independently from the metadata.
metadata.Name = ""
metadata.Namespace = ""
metadata.Labels = nil
metadata.Annotations = nil
views := []policyCrdDescribeView{
{
Name: crd.Name,
Namespace: crd.Namespace,
},
{
APIVersion: crd.APIVersion,
Kind: crd.Kind,
},
{
Labels: crd.Labels,
Annotations: crd.Annotations,
},
{
Metadata: metadata,
},
{
Spec: &crd.Spec,
},
{
Status: &crd.Status,
},
} I guess you won't need the
|
/label tide/merge-method-squash |
…r policies and policycrds
87cd786
to
d2071d4
Compare
@gauravkghildiyal I have made the necessary changes, please review |
Thanks for getting this through @Devaansh-Kumar /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Devaansh-Kumar, gauravkghildiyal 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 |
What type of PR is this?
Add one of the following kinds:
/area gwctl
/kind feature
/cc @gauravkghildiyal
What this PR does / why we need it:
Implement
gwctl describe policycrds
commandWhich issue(s) this PR fixes:
Fixes #2870
Does this PR introduce a user-facing change?: