Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2046 from lenriquez/issue-1462
Browse files Browse the repository at this point in the history
Removed resource age column since the information is repeated
  • Loading branch information
mklanjsek authored Feb 22, 2021
2 parents 7fb96d9 + 62913a8 commit db9eec3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/1462-lenriquez
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed resource age column from Custom Resources
12 changes: 11 additions & 1 deletion internal/printer/customresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ func (crl *CustomResourceLister) List(crdObject *unstructured.Unstructured, reso
}

for _, column := range v.PrinterColumns {
// Base on this issue https://github.com/vmware-tanzu/octant/issues/1462
// Resource Age is not necessary since it has the same info as Age
if column.Name == "Age" {
continue
}

name := column.Name
if octantStrings.Contains(column.Name, []string{"Name", "Labels", "Age"}) {
if octantStrings.Contains(column.Name, []string{"Name", "Labels"}) {
name = fmt.Sprintf("Resource %s", column.Name)
}
table.AddColumn(name)
Expand Down Expand Up @@ -104,6 +110,10 @@ func (crl *CustomResourceLister) List(crdObject *unstructured.Unstructured, reso
row["Age"] = component.NewTimestamp(cr.GetCreationTimestamp().Time)

for _, column := range version.PrinterColumns {
if column.Name == "Age" {
continue
}

s, err := printCustomColumn(cr.Object, column)
if err != nil {
return nil, fmt.Errorf("print custom column %q in CRD %q: %w",
Expand Down
16 changes: 8 additions & 8 deletions internal/printer/customresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ func TestCustomResourceLister_List(t *testing.T) {
wantErr: false,
want: component.NewTableWithRows(
"crontabs.stable.example.com/v1", "We could not find any crontabs.stable.example.com/v1!",
component.NewTableCols("Name", "Labels", "Spec", "Replicas", "Errors", "Resource Age", "Age"),
component.NewTableCols("Name", "Labels", "Spec", "Replicas", "Errors", "Resource Name", "Age"),
[]component.TableRow{
{
"Name": component.NewLink("", "my-crontab", "/my-crontab"),
"Age": component.NewTimestamp(now),
"Labels": component.NewLabels(labels),
"Replicas": component.NewText("1"),
"Spec": component.NewText("* * * * */5"),
"Errors": component.NewText("1"),
"Resource Age": component.NewText(now.UTC().Format(time.RFC3339)),
"Name": component.NewLink("", "my-crontab", "/my-crontab"),
"Age": component.NewTimestamp(now),
"Labels": component.NewLabels(labels),
"Replicas": component.NewText("1"),
"Spec": component.NewText("* * * * */5"),
"Errors": component.NewText("1"),
"Resource Name": component.NewText("my-crontab"),
},
}),
},
Expand Down
4 changes: 4 additions & 0 deletions internal/printer/testdata/crd-additional-columns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ spec:
type: string
description: A custom timestamp
JSONPath: .metadata.creationTimestamp
- name: Name
type: string
description: A custom name
JSONPath: .metadata.name

0 comments on commit db9eec3

Please sign in to comment.