From 7ef12b31d521247318d15cd4c3a446a8b1f1ca67 Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Tue, 14 Jul 2026 11:48:32 +0200 Subject: [PATCH 1/3] chore(e2e): reduce log noise from kubectl output Terratest echoes every stdout line of the kubectl commands it runs. Two spots dominated the e2e log volume: - listK8sResourceKinds dumped ~100+ api-resource names per call, twice per cluster snapshot. - getBrokerConfigMapLogDirs dumped the full broker-config ConfigMap for all 3 brokers on every multi-disk-removal poll iteration. Both now use the existing runKubectlSilent bypass. The multi-disk poller additionally logs only the parsed log.dirs, which is all it inspects. Also removes the dead setupReducedLogging(): its TEST_LOG_LEVEL / KUBECTL_* env vars have no effect on terratest v1.0.1's logger, which is why the line-dumping persisted. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/e2e/k8s.go | 24 +++--------------------- tests/e2e/koperator_suite_test.go | 3 --- tests/e2e/test_multidisk_removal.go | 8 +++++++- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/tests/e2e/k8s.go b/tests/e2e/k8s.go index b166c3fbc..d77eeebaf 100644 --- a/tests/e2e/k8s.go +++ b/tests/e2e/k8s.go @@ -516,13 +516,9 @@ func listK8sResourceKinds(kubectlOptions k8s.KubectlOptions, apiGroupSelector st args = append(args, extraArgs...) - output, err := k8s.RunKubectlAndGetOutputContextE( - ginkgo.GinkgoT(), - context.Background(), - &kubectlOptions, - args..., - ) - + // Execute kubectl directly without terratest's logging: api-resources returns + // one line per resource kind (100+ lines), which otherwise floods the test output. + output, err := runKubectlSilent(kubectlOptions, args...) if err != nil { return nil, err } @@ -746,20 +742,6 @@ func isKubectlNotFoundError(err error) bool { return err != nil && strings.Contains(err.Error(), kubectlNotFoundErrorMsg) } -// setupReducedLogging configures reduced logging for terratest operations -func setupReducedLogging() { - // Set environment variables to reduce terratest logging verbosity - if os.Getenv("E2E_VERBOSE_LOGGING") != verboseLoggingEnabled { - // Reduce terratest internal logging - os.Setenv("TEST_LOG_LEVEL", "-5") - // Reduce kubectl verbosity - os.Setenv("KUBECTL_VERBOSITY", "0") - // Additional environment variables to reduce terratest kubectl command logging - os.Setenv("TERRATEST_LOG_LEVEL", "INFO") - os.Setenv("KUBECTL_LOG_LEVEL", "0") - } -} - // waitForKafkaClusterWithPodStatusCheck waits for KafkaCluster to be ready and checks pod status every 10 seconds func waitForKafkaClusterWithPodStatusCheck(kubectlOptions k8s.KubectlOptions, clusterName string, timeout time.Duration) error { // Only log if verbose logging is enabled diff --git a/tests/e2e/koperator_suite_test.go b/tests/e2e/koperator_suite_test.go index 3e2c35c3a..dc270d42e 100644 --- a/tests/e2e/koperator_suite_test.go +++ b/tests/e2e/koperator_suite_test.go @@ -32,9 +32,6 @@ func TestKoperator(t *testing.T) { } var _ = ginkgo.BeforeSuite(func() { - // Setup reduced logging for terratest operations - setupReducedLogging() - ginkgo.By("Acquiring K8s cluster") var kubeconfigPath string var kubecontextName string diff --git a/tests/e2e/test_multidisk_removal.go b/tests/e2e/test_multidisk_removal.go index 110d58d8a..fa34a07a9 100644 --- a/tests/e2e/test_multidisk_removal.go +++ b/tests/e2e/test_multidisk_removal.go @@ -132,7 +132,11 @@ func getBrokerConfigMapLogDirs(kubectlOptions k8s.KubectlOptions, configMapName "-n", namespace, "-o", fmt.Sprintf("jsonpath={.data.%s}", kafkautils.ConfigPropertyName), } - output, err := k8s.RunKubectlAndGetOutputE(ginkgo.GinkgoT(), &kubectlOptions, args...) + // Fetch broker-config directly without terratest's logging: the ConfigMap holds the + // entire broker configuration (a multi-line properties blob) and this runs on every + // poll iteration for each broker, so logging the full value would flood the output. + // We only need log.dirs, which we parse out of the properties content below. + output, err := runKubectlSilent(kubectlOptions, args...) if err != nil { return nil, fmt.Errorf("getting configmap %s: %w", configMapName, err) } @@ -153,6 +157,8 @@ func getBrokerConfigMapLogDirs(kubectlOptions k8s.KubectlOptions, configMapName paths = append(paths, q) } } + // Log only the extracted log.dirs (not the whole broker config). + ginkgo.By(fmt.Sprintf("configmap %s log.dirs: %v", configMapName, paths)) return paths, nil } } From a86f17d164e8dacd68222ceaf0386912f2075de6 Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Tue, 14 Jul 2026 12:06:38 +0200 Subject: [PATCH 2/3] fix(e2e): trim trailing newline in listK8sResourceKinds output runKubectlSilent uses cmd.Output(), which preserves kubectl's trailing newline (terratest's runner stripped it). listK8sResourceKinds split on "\n" without trimming, producing an empty-string kind element that got joined into the `kubectl get` args during cluster snapshotting: error: the server doesn't have a resource type "" TrimRight the trailing newline before splitting, matching getK8sResources and getK8sResourcesQuiet. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/e2e/k8s.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/e2e/k8s.go b/tests/e2e/k8s.go index d77eeebaf..ae25a287d 100644 --- a/tests/e2e/k8s.go +++ b/tests/e2e/k8s.go @@ -529,6 +529,12 @@ func listK8sResourceKinds(kubectlOptions k8s.KubectlOptions, apiGroupSelector st return nil, nil } + // Trim the trailing newline before splitting: runKubectlSilent preserves + // kubectl's trailing "\n" (unlike terratest's runner), which would otherwise + // yield an empty-string element and break callers that join the kinds for + // `kubectl get` (error: the server doesn't have a resource type ""). + output = strings.TrimRight(output, "\n") + return kubectlRemoveWarnings(strings.Split(output, "\n")), nil } From 9f943c65179975d7922396bb75d6d66745f4db0a Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Tue, 14 Jul 2026 12:08:37 +0200 Subject: [PATCH 3/3] fix(e2e): harden listK8sCRDs output parsing listK8sCRDs split kubectl output on "\n" without trimming the trailing newline and without dropping warning lines - the same latent bug fixed in listK8sResourceKinds. It currently uses terratest's runner (which strips the trailing newline) so it isn't broken today, but it would break the moment it's switched to runKubectlSilent. TrimRight the trailing newline, guard empty output, and run kubectlRemoveWarnings - consistent with getK8sResources and getK8sResourcesQuiet. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/e2e/k8s.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/e2e/k8s.go b/tests/e2e/k8s.go index ae25a287d..c020f2690 100644 --- a/tests/e2e/k8s.go +++ b/tests/e2e/k8s.go @@ -424,7 +424,15 @@ func listK8sCRDs(kubectlOptions k8s.KubectlOptions, crdNames ...string) ([]strin return nil, errors.WrapIfWithDetails(err, "listing K8s CRDs failed failed", "crdNames", crdNames) } - return strings.Split(output, "\n"), nil + // Trim the trailing newline before splitting so a trailing empty-string + // element never leaks into the result (see listK8sResourceKinds), and drop + // any warning lines - consistent with the other list helpers. + output = strings.TrimRight(output, "\n") + if output == "" { + return nil, nil + } + + return kubectlRemoveWarnings(strings.Split(output, "\n")), nil } // deleteK8sResourceOpts deletes K8s resources based on the kind and name or kind and selector.