Commit e3a37434 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #40073 from matthyx/master

Automatic merge from submit-queue (batch tested with PRs 40046, 40073, 40547, 40534, 40249) Issue #13501 - printEvent Source to much more cleaner Create a formatEventSource func and use it. **What this PR does / why we need it**: Adds a smarter way to print EventSource, removing "{ }" and the eventual extra ", " when Host is empty. It was also reported in OpenShift issue https://github.com/openshift/origin/issues/6586 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #13501 **Special notes for your reviewer**: I have used this new func in all user facing printouts, but there are other places where EventSource are printed to logs, like DumpEventsInNamespace in test/e2e/framework/util.go for instance. Don't know if I should correct there too... **Release note**: ```release-note Improve formatting of EventSource in kubectl get and kubectl describe ```
parents bef60b86 42eb8ff0
...@@ -2282,7 +2282,7 @@ func DescribeEvents(el *api.EventList, w *PrefixWriter) { ...@@ -2282,7 +2282,7 @@ func DescribeEvents(el *api.EventList, w *PrefixWriter) {
translateTimestamp(e.FirstTimestamp), translateTimestamp(e.FirstTimestamp),
translateTimestamp(e.LastTimestamp), translateTimestamp(e.LastTimestamp),
e.Count, e.Count,
e.Source, formatEventSource(e.Source),
e.InvolvedObject.FieldPath, e.InvolvedObject.FieldPath,
e.Type, e.Type,
e.Reason, e.Reason,
......
...@@ -1728,7 +1728,7 @@ func printEvent(event *api.Event, w io.Writer, options PrintOptions) error { ...@@ -1728,7 +1728,7 @@ func printEvent(event *api.Event, w io.Writer, options PrintOptions) error {
event.InvolvedObject.FieldPath, event.InvolvedObject.FieldPath,
event.Type, event.Type,
event.Reason, event.Reason,
event.Source, formatEventSource(event.Source),
event.Message, event.Message,
); err != nil { ); err != nil {
return err return err
...@@ -2727,3 +2727,12 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { ...@@ -2727,3 +2727,12 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
func (p *JSONPathPrinter) HandledResources() []string { func (p *JSONPathPrinter) HandledResources() []string {
return []string{} return []string{}
} }
// formatEventSource formats EventSource as a comma separated string excluding Host when empty
func formatEventSource(es api.EventSource) string {
EventSourceString := []string{es.Component}
if len(es.Host) > 0 {
EventSourceString = append(EventSourceString, es.Host)
}
return strings.Join(EventSourceString, ", ")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment