Skip to content

Commit

Permalink
Added creationTimestamp in policies_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Devaansh-Kumar committed Apr 3, 2024
1 parent 5ef9dad commit d2071d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 54 deletions.
18 changes: 9 additions & 9 deletions gwctl/pkg/printer/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/yaml"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/duration"
"k8s.io/utils/clock"
)
Expand Down Expand Up @@ -157,7 +158,7 @@ type policyCrdDescribeView struct {
Kind string `json:",omitempty"`
Labels map[string]string `json:",omitempty"`
Annotations map[string]string `json:",omitempty"`
Metadata interface{} `json:",omitempty"`
Metadata *metav1.ObjectMeta `json:",omitempty"`
Spec *apiextensionsv1.CustomResourceDefinitionSpec `json:",omitempty"`
Status *apiextensionsv1.CustomResourceDefinitionStatus `json:",omitempty"`
}
Expand All @@ -172,12 +173,11 @@ func (pp *PoliciesPrinter) PrintPolicyCRDsDescribeView(policyCrds []policymanage
for i, policyCrd := range policyCrds {
crd := policyCrd.CRD()

excludedFieldsFromMetadata := map[string]bool{
"Labels": true,
"Annotations": true,
}

modifiedMetadata := ExcludeFieldsFromStruct(crd.ObjectMeta, excludedFieldsFromMetadata)
metadata := crd.ObjectMeta.DeepCopy()
metadata.Labels = nil
metadata.Annotations = nil
metadata.Name = ""
metadata.Namespace = ""

views := []policyCrdDescribeView{
{
Expand All @@ -189,11 +189,11 @@ func (pp *PoliciesPrinter) PrintPolicyCRDsDescribeView(policyCrds []policymanage
Kind: crd.Kind,
},
{
Labels: crd.Labels,
Labels: crd.Labels,
Annotations: crd.Annotations,
},
{
Metadata: modifiedMetadata,
Metadata: metadata,
},
{
Spec: &crd.Spec,
Expand Down
8 changes: 4 additions & 4 deletions gwctl/pkg/printer/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func TestPolicyCrd_PrintDescribeView(t *testing.T) {
Labels: map[string]string{
gatewayv1alpha2.PolicyLabelKey: "inherited",
},
CreationTimestamp: metav1.NewTime(time.Date(2024, time.Month(2), 1, 13, 9, 0, 0, time.UTC)),
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Scope: apiextensionsv1.ClusterScoped,
Expand Down Expand Up @@ -405,6 +406,7 @@ func TestPolicyCrd_PrintDescribeView(t *testing.T) {
Labels: map[string]string{
gatewayv1alpha2.PolicyLabelKey: "direct",
},
CreationTimestamp: metav1.NewTime(time.Date(2023, time.Month(11), 9, 4, 56, 0, 0, time.UTC)),
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Scope: apiextensionsv1.NamespaceScoped,
Expand Down Expand Up @@ -449,8 +451,7 @@ Kind: CustomResourceDefinition
Labels:
gateway.networking.k8s.io/policy: inherited
Metadata:
creationTimestamp: null
name: healthcheckpolicies.foo.com
creationTimestamp: "2024-02-01T13:09:00Z"
resourceVersion: "999"
Spec:
group: foo.com
Expand All @@ -476,8 +477,7 @@ Kind: CustomResourceDefinition
Labels:
gateway.networking.k8s.io/policy: direct
Metadata:
creationTimestamp: null
name: timeoutpolicies.bar.com
creationTimestamp: "2023-11-09T04:56:00Z"
resourceVersion: "999"
Spec:
group: bar.com
Expand Down
41 changes: 0 additions & 41 deletions gwctl/pkg/printer/utils.go

This file was deleted.

0 comments on commit d2071d4

Please sign in to comment.