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
```
This commit is contained in:
Kubernetes Submit Queue 2017-01-26 16:10:36 -08:00 committed by GitHub
commit e3a3743410
2 changed files with 11 additions and 2 deletions

View File

@ -2282,7 +2282,7 @@ func DescribeEvents(el *api.EventList, w *PrefixWriter) {
translateTimestamp(e.FirstTimestamp),
translateTimestamp(e.LastTimestamp),
e.Count,
e.Source,
formatEventSource(e.Source),
e.InvolvedObject.FieldPath,
e.Type,
e.Reason,

View File

@ -1728,7 +1728,7 @@ func printEvent(event *api.Event, w io.Writer, options PrintOptions) error {
event.InvolvedObject.FieldPath,
event.Type,
event.Reason,
event.Source,
formatEventSource(event.Source),
event.Message,
); err != nil {
return err
@ -2727,3 +2727,12 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
func (p *JSONPathPrinter) HandledResources() []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, ", ")
}