From 36dbf37cf19db7c2083e8b0683afd603d10f5a4c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 4 Dec 2025 13:34:22 +0100 Subject: [PATCH] DRA upgrade/downgrade: better Gomega failure for system log output Truncating the kube-controller-manager log output at the end when waiting for "Caches are synced" fails isn't useful because it doesn't show how far the controller got (might be stuck). This can be solved by implementing GomegaStringer with truncation in the middle. --- test/utils/localupcluster/localupcluster.go | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/test/utils/localupcluster/localupcluster.go b/test/utils/localupcluster/localupcluster.go index 4cc0e142f4b..32c16e77976 100644 --- a/test/utils/localupcluster/localupcluster.go +++ b/test/utils/localupcluster/localupcluster.go @@ -44,6 +44,7 @@ import ( "time" "github.com/onsi/gomega" + "github.com/onsi/gomega/format" "github.com/onsi/gomega/gstruct" corev1 "k8s.io/api/core/v1" @@ -299,12 +300,39 @@ func (c *Cluster) LoadConfig(tCtx ktesting.TContext) *restclient.Config { } // GetSystemLogs returns the output of the given component, the empty string and false if not started. -func (c *Cluster) GetSystemLogs(tCtx ktesting.TContext, component KubeComponentName) (string, bool) { +func (c *Cluster) GetSystemLogs(tCtx ktesting.TContext, component KubeComponentName) (GString, bool) { cmd, ok := c.running[component] if !ok { return "", false } - return cmd.Output(tCtx), true + return GString(cmd.Output(tCtx)), true +} + +// GString is useful for log output because in contrast to the default behavior for +// strings it truncates in the middle. +type GString string + +var ( + _ format.GomegaStringer = GString("") + _ fmt.Stringer = GString("") +) + +func (gs GString) GomegaString() string { + s := string(gs) + if len(s) < format.MaxLength { + return s + } + elipsis := "\n...\n" + keepLen := format.MaxLength - len(elipsis) + if keepLen < 0 { + // Cannot truncate in the middle, result would be too long. Leave it to Gomega. + return s + } + return s[:keepLen/2] + elipsis + s[len(gs)-keepLen/2:] +} + +func (gs GString) String() string { + return string(gs) } type ModifyOptions struct {