From 71edf075de3ea0e26aa40f06f1670862aaebcf33 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Tue, 4 Aug 2020 18:10:34 +0200 Subject: [PATCH] kubectl describe pod: use ReportingController as an event source With https://github.com/kubernetes/kubernetes/pull/91645 merged (promotion of v1beta1 events to v1), it's no longer permitted to set Source field. Based on https://stupefied-goodall-e282f7.netlify.app/contributors/design-proposals/instrumentation/events-redesign/#backward-compatibility Source.Component is supposed to be replaced by ReportingController. Source.Host is supposed to be replaced by DeprecatedHost, though DeprecatedHost was never implemented. Thus, ignoring the second field. --- .../src/k8s.io/kubectl/pkg/describe/describe.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index 24e70e2ae75..5034864bdfb 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -3873,11 +3873,15 @@ func DescribeEvents(el *corev1.EventList, w PrefixWriter) { interval = translateMicroTimestampSince(e.EventTime) } } + source := e.Source.Component + if source == "" { + source = e.ReportingController + } w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n", e.Type, e.Reason, interval, - formatEventSource(e.Source), + source, strings.TrimSpace(e.Message), ) } @@ -5001,15 +5005,6 @@ func translateTimestampSince(timestamp metav1.Time) string { return duration.HumanDuration(time.Since(timestamp.Time)) } -// formatEventSource formats EventSource as a comma separated string excluding Host when empty -func formatEventSource(es corev1.EventSource) string { - EventSourceString := []string{es.Component} - if len(es.Host) > 0 { - EventSourceString = append(EventSourceString, es.Host) - } - return strings.Join(EventSourceString, ", ") -} - // Pass ports=nil for all ports. func formatEndpoints(endpoints *corev1.Endpoints, ports sets.String) string { if len(endpoints.Subsets) == 0 {