Skip to content

Commit

Permalink
kubectl: fix the Scheduled eventTime is <unknown> when use kubectl de…
Browse files Browse the repository at this point in the history
…scribe pod xxx
  • Loading branch information
gosoon authored and ialidzhikov committed Sep 20, 2020
1 parent 8d8a97c commit 0d06c86
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions staging/src/k8s.io/kubectl/pkg/describe/versioned/describe.go
Expand Up @@ -3552,6 +3552,9 @@ func DescribeEvents(el *corev1.EventList, w PrefixWriter) {
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, translateTimestampSince(e.FirstTimestamp))
} else {
interval = translateTimestampSince(e.FirstTimestamp)
if e.FirstTimestamp.IsZero() {
interval = translateMicroTimestampSince(e.EventTime)
}
}
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
e.Type,
Expand Down Expand Up @@ -4619,6 +4622,16 @@ func shorten(s string, maxLength int) string {
return s
}

// translateMicroTimestampSince returns the elapsed time since timestamp in
// human-readable approximation.
func translateMicroTimestampSince(timestamp metav1.MicroTime) string {
if timestamp.IsZero() {
return "<unknown>"
}

return duration.HumanDuration(time.Since(timestamp.Time))
}

// translateTimestampSince returns the elapsed time since timestamp in
// human-readable approximation.
func translateTimestampSince(timestamp metav1.Time) string {
Expand Down

0 comments on commit 0d06c86

Please sign in to comment.