Skip to content

Commit

Permalink
fix event last seen output, close #139
Browse files Browse the repository at this point in the history
  • Loading branch information
gmeghnag committed Mar 3, 2024
1 parent cce2969 commit e039bd3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/tablegenerator/tablegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"sort"
"strings"
"time"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -76,12 +77,24 @@ func InternalResourceTable(runtimeObject runtime.Object, unstruct *unstructured.
}
}
if table.ColumnDefinitions[0].Name == "Name" {
if vars.ShowKind == true {
if vars.ShowKind {
table.Rows[0].Cells[0] = resourceKind + "/" + unstruct.GetName()
} else {
table.Rows[0].Cells[0] = unstruct.GetName()
}
}
if resourceKind == "event" && table.ColumnDefinitions[0].Name == "Last Seen" {
var lastTimestamp metav1.Time
lastTimestampInterface := unstruct.Object["lastTimestamp"]
if lastTimestampInterface != nil {
lastTimestampTime, _ := time.Parse(time.RFC3339, fmt.Sprintf("%v", lastTimestampInterface))
lastTimestamp = metav1.NewTime(lastTimestampTime.UTC())
} else {
lastTimestamp = metav1.NewTime(unstruct.GetCreationTimestamp().UTC())
}
lastSeen := helpers.GetAge(vars.MustGatherRootPath, lastTimestamp)
table.Rows[0].Cells[0] = lastSeen
}

if vars.ShowNamespace {
table.ColumnDefinitions = append([]metav1.TableColumnDefinition{{Format: "string", Name: "Namespace"}}, table.ColumnDefinitions...)
Expand Down Expand Up @@ -181,9 +194,3 @@ func GenerateCustomResourceTable(unstruct unstructured.Unstructured) (*metav1.Ta

return table, nil
}

func kind(resource *unstructured.Unstructured) string {
longKind := strings.Split(resource.GetAPIVersion(), "/")[0]
splittedKind := strings.Split(longKind, ".")
return splittedKind[0]
}

0 comments on commit e039bd3

Please sign in to comment.