Merge pull request #51748 from smarterclayton/events_inline

Automatic merge from submit-queue (batch tested with PRs 50602, 51561, 51703, 51748, 49142)

Simplify describe events table

The describe table for events is not easy to read and violates other
output guidelines. Change to use spaces (we don't use tabs in formal
output for tables). Remove columns that are not normally needed or
available on events.

Example for pods:

```
...
QoS Class:       BestEffort
Node-Selectors:  role=app
Tolerations:     <none>
Events:
  Type     Reason      Age                 From                         Message
  ----     ------      ----                ----                         -------
  Normal   Pulling     1h (x51 over 5h)    kubelet, origin-ci-ig-n-gj0x pulling image "registry.svc.ci.openshift.org/experiment/commenter:latest"
  Normal   BackOff     8m (x1274 over 5h)  kubelet, origin-ci-ig-n-gj0x Back-off pulling image "registry.svc.ci.openshift.org/experiment/commenter:latest"
  Warning  FailedSync  3m (x1359 over 5h)  kubelet, origin-ci-ig-n-gj0x Error syncing pod
```

Puts the type first (separate important from not), then reason (which is
the most impactful scanning field). Collapses first seen, last seen, and
times into a single field, since most of the time you care about the
last time the event happened, not the first time.

@kubernetes/sig-cli-pr-reviews sorry for the last minute drop, but the usability of this is driving me up the wall and I can't take it anymore. Would like to slip this into 1.8 so that I can debug things without dying a little inside.

Fixes #47715

```release-note
The event table output under `kubectl describe` has been simplified to show only the most essential info.
```
This commit is contained in:
Kubernetes Submit Queue 2017-09-03 01:12:12 -07:00 committed by GitHub
commit fc87bba2dd
3 changed files with 43 additions and 26 deletions

View File

@ -335,7 +335,7 @@ func applyHistory(ds *extensionsv1beta1.DaemonSet, history *appsv1beta1.Controll
func tabbedString(f func(io.Writer) error) (string, error) {
out := new(tabwriter.Writer)
buf := &bytes.Buffer{}
out.Init(buf, 0, 8, 1, '\t', 0)
out.Init(buf, 0, 8, 2, ' ', 0)
err := f(out)
if err != nil {

View File

@ -89,6 +89,8 @@ type PrefixWriter interface {
Write(level int, format string, a ...interface{})
// WriteLine writes an entire line with no indentation level.
WriteLine(a ...interface{})
// Flush forces indendation to be reset.
Flush()
}
// prefixWriter implements PrefixWriter
@ -116,6 +118,12 @@ func (pw *prefixWriter) WriteLine(a ...interface{}) {
fmt.Fprintln(pw.out, a...)
}
func (pw *prefixWriter) Flush() {
if f, ok := pw.out.(flusher); ok {
f.Flush()
}
}
func describerMap(c clientset.Interface) map[schema.GroupKind]printers.Describer {
m := map[schema.GroupKind]printers.Describer{
api.Kind("Pod"): &PodDescriber{c},
@ -2857,19 +2865,24 @@ func DescribeEvents(el *api.EventList, w PrefixWriter) {
w.Write(LEVEL_0, "Events:\t<none>\n")
return
}
w.Flush()
sort.Sort(events.SortableEvents(el.Items))
w.Write(LEVEL_0, "Events:\n FirstSeen\tLastSeen\tCount\tFrom\tSubObjectPath\tType\tReason\tMessage\n")
w.Write(LEVEL_1, "---------\t--------\t-----\t----\t-------------\t--------\t------\t-------\n")
w.Write(LEVEL_0, "Events:\n Type\tReason\tAge\tFrom\tMessage\n")
w.Write(LEVEL_1, "----\t------\t----\t----\t-------\n")
for _, e := range el.Items {
w.Write(LEVEL_1, "%s\t%s\t%d\t%v\t%v\t%v\t%v\t%v\n",
translateTimestamp(e.FirstTimestamp),
translateTimestamp(e.LastTimestamp),
e.Count,
formatEventSource(e.Source),
e.InvolvedObject.FieldPath,
var interval string
if e.Count > 1 {
interval = fmt.Sprintf("%s (x%d over %s)", translateTimestamp(e.LastTimestamp), e.Count, translateTimestamp(e.FirstTimestamp))
} else {
interval = translateTimestamp(e.FirstTimestamp)
}
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
e.Type,
e.Reason,
e.Message)
interval,
formatEventSource(e.Source),
strings.TrimSpace(e.Message),
)
}
}
@ -3595,10 +3608,14 @@ func printTolerationsMultilineWithIndent(w PrefixWriter, initialIndent, title, i
}
}
type flusher interface {
Flush()
}
func tabbedString(f func(io.Writer) error) (string, error) {
out := new(tabwriter.Writer)
buf := &bytes.Buffer{}
out.Init(buf, 0, 8, 1, '\t', 0)
out.Init(buf, 0, 8, 2, ' ', 0)
err := f(out)
if err != nil {

View File

@ -1499,22 +1499,22 @@ URL: http://localhost
func TestDescribePodSecurityPolicy(t *testing.T) {
expected := []string{
"Name:\t*mypsp",
"Allow Privileged:\t*false",
"Default Add Capabilities:\t*<none>",
"Required Drop Capabilities:\t*<none>",
"Allowed Capabilities:\t*<none>",
"Allowed Volume Types:\t*<none>",
"Allow Host Network:\t*false",
"Allow Host Ports:\t*<none>",
"Allow Host PID:\t*false",
"Allow Host IPC:\t*false",
"Read Only Root Filesystem:\t*false",
"Name:\\s*mypsp",
"Allow Privileged:\\s*false",
"Default Add Capabilities:\\s*<none>",
"Required Drop Capabilities:\\s*<none>",
"Allowed Capabilities:\\s*<none>",
"Allowed Volume Types:\\s*<none>",
"Allow Host Network:\\s*false",
"Allow Host Ports:\\s*<none>",
"Allow Host PID:\\s*false",
"Allow Host IPC:\\s*false",
"Read Only Root Filesystem:\\s*false",
"SELinux Context Strategy: RunAsAny",
"User:\t*<none>",
"Role:\t*<none>",
"Type:\t*<none>",
"Level:\t*<none>",
"User:\\s*<none>",
"Role:\\s*<none>",
"Type:\\s*<none>",
"Level:\\s*<none>",
"Run As User Strategy: RunAsAny",
"FSGroup Strategy: RunAsAny",
"Supplemental Groups Strategy: RunAsAny",