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

Add missing columns to gwctl get policycrds #2811

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions gwctl/pkg/printer/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ func (pp *PoliciesPrinter) PrintCRDs(policyCRDs []policymanager.PolicyCRD) {
})

tw := tabwriter.NewWriter(pp.Out, 0, 0, 2, ' ', 0)
row := []string{"NAME", "GROUP", "KIND", "POLICY TYPE", "SCOPE"}
row := []string{"NAME", "POLICY TYPE", "SCOPE", "AGE"}
tw.Write([]byte(strings.Join(row, "\t") + "\n"))

for _, policyCRD := range policyCRDs {
policyType := "Direct"
if policyCRD.IsInherited() {
policyType = "Inherited"
}

age := duration.HumanDuration(pp.Clock.Since(policyCRD.CRD().GetCreationTimestamp().Time))

row := []string{
policyCRD.CRD().Name,
policyCRD.CRD().Spec.Group,
policyCRD.CRD().Spec.Names.Kind,
policyType,
string(policyCRD.CRD().Spec.Scope),
age,
}
tw.Write([]byte(strings.Join(row, "\t") + "\n"))
}
Expand Down
16 changes: 12 additions & 4 deletions gwctl/pkg/printer/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,17 @@ Spec:
}

func TestPoliciesPrinter_PrintCRDs(t *testing.T) {
fakeClock := testingclock.NewFakeClock(time.Now())
objects := []runtime.Object{
&apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: "healthcheckpolicies.foo.com",
Labels: map[string]string{
gatewayv1alpha2.PolicyLabelKey: "inherited",
},
CreationTimestamp: metav1.Time{
Time: fakeClock.Now().Add(-24 * 24 * time.Hour),
},
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Scope: apiextensionsv1.ClusterScoped,
Expand Down Expand Up @@ -300,6 +304,9 @@ func TestPoliciesPrinter_PrintCRDs(t *testing.T) {
Labels: map[string]string{
gatewayv1alpha2.PolicyLabelKey: "direct",
},
CreationTimestamp: metav1.Time{
Time: fakeClock.Now().Add(-5 * time.Minute),
},
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Scope: apiextensionsv1.NamespaceScoped,
Expand Down Expand Up @@ -332,15 +339,16 @@ func TestPoliciesPrinter_PrintCRDs(t *testing.T) {

params := utils.MustParamsForTest(t, common.MustClientsForTest(t, objects...))
pp := &PoliciesPrinter{
Out: &bytes.Buffer{},
Out: &bytes.Buffer{},
Clock: fakeClock,
}
pp.PrintCRDs(params.PolicyManager.GetCRDs())

got := pp.Out.(*bytes.Buffer).String()
want := `
NAME GROUP KIND POLICY TYPE SCOPE
healthcheckpolicies.foo.com foo.com HealthCheckPolicy Inherited Cluster
timeoutpolicies.bar.com bar.com TimeoutPolicy Direct Namespaced
NAME POLICY TYPE SCOPE AGE
healthcheckpolicies.foo.com Inherited Cluster 24d
timeoutpolicies.bar.com Direct Namespaced 5m
`
if diff := cmp.Diff(common.YamlString(want), common.YamlString(got), common.YamlStringTransformer); diff != "" {
t.Errorf("Unexpected diff\ngot=\n%v\nwant=\n%v\ndiff (-want +got)=\n%v", got, want, diff)
Expand Down