Skip to content

Commit cda7b5c

Browse files
authored
tests: introduce kubectlRun to avoid conflating stdin and stdout in tests (#15151)
* tests: introduce `kubectlRun` to avoid conflating stdin and stdout in tests Introduce a new test helper `TestHelper.KubectlRun` (and mark `TestHelper.Kubectl` as deprecated), that keeps stdout and stderr separate when invoking `kubectl`. This avoids failures on Kubernetes 1.35+, where deprecation warnings for Endpoints are emitted alongside command output and can break deserialization in `TestDestinationAPIStreamTracksRolloutEndpoints`.
1 parent 8622c90 commit cda7b5c

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

test/integration/deep/endpoints/destination_api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ func waitForServiceEndpoints(t *testing.T, namespace, service string, timeout ti
573573
// Poll Endpoints until at least one address is present. This avoids races
574574
// where the service exists but endpoint publication is still in flight.
575575
err := testutil.RetryFor(timeout, func() error {
576-
out, err := TestHelper.Kubectl("", "-n", namespace, "get", "endpoints", service, "-o", "json")
576+
// in k8s 1.35+ this call returns a warning about Endpoints being deprecated, that we ignore here
577+
out, _, err := TestHelper.KubectlRun("", "-n", namespace, "get", "endpoints", service, "-o", "json")
577578
if err != nil {
578579
return err
579580
}

testutil/kubernetes_helper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func (h *KubernetesHelper) KubectlApplyWithArgs(stdin string, cmdArgs ...string)
162162
}
163163

164164
// Kubectl executes an arbitrary Kubectl command
165+
// Deprecated: use KubectlRun instead
165166
func (h *KubernetesHelper) Kubectl(stdin string, arg ...string) (string, error) {
166167
withContext := append([]string{"--context=" + h.k8sContext}, arg...)
167168
cmd := exec.Command("kubectl", withContext...)
@@ -170,6 +171,12 @@ func (h *KubernetesHelper) Kubectl(stdin string, arg ...string) (string, error)
170171
return string(out), err
171172
}
172173

174+
// KubectlRun executes an arbitrary kubectl command and returns stdout and stderr separately
175+
func (h *KubernetesHelper) KubectlRun(stdin string, arg ...string) (string, string, error) {
176+
withContext := append([]string{"--context=" + h.k8sContext}, arg...)
177+
return combinedOutput(stdin, "kubectl", withContext...)
178+
}
179+
173180
// KubectlApplyWithContext applies a given configuration with the given flags
174181
func (h *KubernetesHelper) KubectlApplyWithContext(stdin string, context string, arg ...string) (string, error) {
175182
args := append([]string{"apply"}, arg...)

0 commit comments

Comments
 (0)