Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions tests/e2e/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -516,13 +524,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
}
Expand All @@ -533,6 +537,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
}

Expand Down Expand Up @@ -746,20 +756,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
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/koperator_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/test_multidisk_removal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
}
Expand Down