Merge pull request #90227 from gosoon/bugfix
kubectl: fix the Scheduled eventTime is <unknown> when printing event
This commit is contained in:
		@@ -3642,6 +3642,9 @@ func DescribeEvents(el *corev1.EventList, w PrefixWriter) {
 | 
				
			|||||||
			interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, translateTimestampSince(e.FirstTimestamp))
 | 
								interval = fmt.Sprintf("%s (x%d over %s)", translateTimestampSince(e.LastTimestamp), e.Count, translateTimestampSince(e.FirstTimestamp))
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			interval = translateTimestampSince(e.FirstTimestamp)
 | 
								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",
 | 
							w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
 | 
				
			||||||
			e.Type,
 | 
								e.Type,
 | 
				
			||||||
@@ -4745,6 +4748,16 @@ func shorten(s string, maxLength int) string {
 | 
				
			|||||||
	return s
 | 
						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
 | 
					// translateTimestampSince returns the elapsed time since timestamp in
 | 
				
			||||||
// human-readable approximation.
 | 
					// human-readable approximation.
 | 
				
			||||||
func translateTimestampSince(timestamp metav1.Time) string {
 | 
					func translateTimestampSince(timestamp metav1.Time) string {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user