Skip to content

Commit 5157383

Browse files
authored
Merge pull request kubernetes#90227 from gosoon/bugfix
kubectl: fix the Scheduled eventTime is <unknown> when printing event
2 parents 5655350 + 798f677 commit 5157383

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

staging/src/k8s.io/kubectl/pkg/describe/describe.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,9 @@ func DescribeEvents(el *corev1.EventList, w PrefixWriter) {
36423642
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, translateTimestampSince(e.FirstTimestamp))
36433643
} else {
36443644
interval = translateTimestampSince(e.FirstTimestamp)
3645+
if e.FirstTimestamp.IsZero() {
3646+
interval = translateMicroTimestampSince(e.EventTime)
3647+
}
36453648
}
36463649
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
36473650
e.Type,
@@ -4745,6 +4748,16 @@ func shorten(s string, maxLength int) string {
47454748
return s
47464749
}
47474750

4751+
// translateMicroTimestampSince returns the elapsed time since timestamp in
4752+
// human-readable approximation.
4753+
func translateMicroTimestampSince(timestamp metav1.MicroTime) string {
4754+
if timestamp.IsZero() {
4755+
return "<unknown>"
4756+
}
4757+
4758+
return duration.HumanDuration(time.Since(timestamp.Time))
4759+
}
4760+
47484761
// translateTimestampSince returns the elapsed time since timestamp in
47494762
// human-readable approximation.
47504763
func translateTimestampSince(timestamp metav1.Time) string {

0 commit comments

Comments
 (0)