Skip to content

Commit efa7f51

Browse files
authored
Add missing columns to gwctl get policycrds (#2811)
Signed-off-by: Jongwoo Han <[email protected]>
1 parent 81cf90a commit efa7f51

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

gwctl/pkg/printer/policies.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,22 @@ func (pp *PoliciesPrinter) PrintCRDs(policyCRDs []policymanager.PolicyCRD) {
7777
})
7878

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

8383
for _, policyCRD := range policyCRDs {
8484
policyType := "Direct"
8585
if policyCRD.IsInherited() {
8686
policyType = "Inherited"
8787
}
88+
89+
age := duration.HumanDuration(pp.Clock.Since(policyCRD.CRD().GetCreationTimestamp().Time))
90+
8891
row := []string{
8992
policyCRD.CRD().Name,
90-
policyCRD.CRD().Spec.Group,
91-
policyCRD.CRD().Spec.Names.Kind,
9293
policyType,
9394
string(policyCRD.CRD().Spec.Scope),
95+
age,
9496
}
9597
tw.Write([]byte(strings.Join(row, "\t") + "\n"))
9698
}

gwctl/pkg/printer/policies_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,17 @@ Spec:
251251
}
252252

253253
func TestPoliciesPrinter_PrintCRDs(t *testing.T) {
254+
fakeClock := testingclock.NewFakeClock(time.Now())
254255
objects := []runtime.Object{
255256
&apiextensionsv1.CustomResourceDefinition{
256257
ObjectMeta: metav1.ObjectMeta{
257258
Name: "healthcheckpolicies.foo.com",
258259
Labels: map[string]string{
259260
gatewayv1alpha2.PolicyLabelKey: "inherited",
260261
},
262+
CreationTimestamp: metav1.Time{
263+
Time: fakeClock.Now().Add(-24 * 24 * time.Hour),
264+
},
261265
},
262266
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
263267
Scope: apiextensionsv1.ClusterScoped,
@@ -300,6 +304,9 @@ func TestPoliciesPrinter_PrintCRDs(t *testing.T) {
300304
Labels: map[string]string{
301305
gatewayv1alpha2.PolicyLabelKey: "direct",
302306
},
307+
CreationTimestamp: metav1.Time{
308+
Time: fakeClock.Now().Add(-5 * time.Minute),
309+
},
303310
},
304311
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
305312
Scope: apiextensionsv1.NamespaceScoped,
@@ -332,15 +339,16 @@ func TestPoliciesPrinter_PrintCRDs(t *testing.T) {
332339

333340
params := utils.MustParamsForTest(t, common.MustClientsForTest(t, objects...))
334341
pp := &PoliciesPrinter{
335-
Out: &bytes.Buffer{},
342+
Out: &bytes.Buffer{},
343+
Clock: fakeClock,
336344
}
337345
pp.PrintCRDs(params.PolicyManager.GetCRDs())
338346

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

0 commit comments

Comments
 (0)