Skip to content

Commit a352662

Browse files
committed
Truncate long reasons
1 parent 11f9f47 commit a352662

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pkg/cli/admin/upgrade/status/controlplane.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func (d *controlPlaneStatusDisplayData) Write(f io.Writer, detailed bool, now ti
503503
if i == 0 {
504504
_, _ = table.Write([]byte(o.Name + "\t"))
505505
_, _ = table.Write([]byte(shortDuration(now.Sub(o.Condition.LastTransitionTime.Time)) + "\t"))
506-
_, _ = table.Write([]byte(reason + "\t"))
506+
_, _ = table.Write([]byte(ellipsis(reason, 20) + "\t"))
507507
_, _ = table.Write([]byte(line + "\n"))
508508
} else {
509509
_, _ = table.Write([]byte("\t\t\t" + line + "\n"))
@@ -517,6 +517,17 @@ func (d *controlPlaneStatusDisplayData) Write(f io.Writer, detailed bool, now ti
517517
return nil
518518
}
519519

520+
func ellipsis(s string, maxLen int) string {
521+
runes := []rune(s)
522+
if len(runes) <= maxLen {
523+
return s
524+
}
525+
if maxLen < 3 {
526+
maxLen = 3
527+
}
528+
return string(runes[0:maxLen-3]) + "..."
529+
}
530+
520531
const controlPlaneStatusTemplateRaw = `= Control Plane =
521532
Assessment: {{ .Assessment }}
522533
Target Version: {{ .TargetVersion }}

pkg/cli/admin/upgrade/status/examples/4.16.0-single-node.detailed-output

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Duration: 2m54s (Est. Time Remaining: 1h9m)
77
Operator Health: 32 Healthy, 1 Available but degraded
88

99
Updating Cluster Operators
10-
NAME SINCE REASON MESSAGE
11-
kube-apiserver 2m NodeInstaller::PetrDoesNotLikeLongLines::WhichTakeTooMuchSpace NodeInstallerProgressing: 1 node is at revision 8; 0 nodes have achieved new revision 10
12-
Test line breaks
13-
New line
10+
NAME SINCE REASON MESSAGE
11+
kube-apiserver 2m NodeInstaller::Pe... NodeInstallerProgressing: 1 node is at revision 8; 0 nodes have achieved new revision 10
12+
Test line breaks
13+
New line
1414

1515
Control Plane Nodes
1616
NAME ASSESSMENT PHASE VERSION EST MESSAGE

0 commit comments

Comments
 (0)