Skip to content

Commit 432fb65

Browse files
utam0kroboquat
authored andcommitted
test: Convert port-forward stderr to be easier to deal with
1 parent 9194470 commit 432fb65

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

test/pkg/integration/common/port_forward.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12+
"io"
1213
"net"
1314
"os/exec"
1415
"strings"
1516
"time"
1617
)
1718

19+
const (
20+
errorDialingBackend = "error: error upgrading connection: error dialing backend: EOF"
21+
)
22+
1823
// ForwardPortOfPod establishes a TCP port forwarding to a Kubernetes pod
1924
func ForwardPortOfPod(ctx context.Context, kubeconfig string, namespace, name, port string) (readychan chan struct{}, errchan chan error) {
2025
return forwardPort(ctx, kubeconfig, namespace, "pod", name, port)
@@ -48,17 +53,31 @@ func forwardPort(ctx context.Context, kubeconfig string, namespace, resourceType
4853
command.Stderr = &serr
4954
err := command.Start()
5055
if err != nil {
51-
errchan <- fmt.Errorf("unexpected error string port-forward: %w", errors.New(serr.String()))
52-
if command.Process != nil {
53-
_ = command.Process.Kill()
56+
if strings.TrimSuffix(serr.String(), "\n") == errorDialingBackend {
57+
errchan <- io.EOF
58+
if command.Process != nil {
59+
_ = command.Process.Kill()
60+
}
61+
} else {
62+
errchan <- fmt.Errorf("unexpected error string port-forward: %w", errors.New(serr.String()))
63+
if command.Process != nil {
64+
_ = command.Process.Kill()
65+
}
5466
}
5567
}
5668

5769
err = command.Wait()
5870
if err != nil {
59-
errchan <- fmt.Errorf("unexpected error string port-forward: %w", errors.New(serr.String()))
60-
if command.Process != nil {
61-
_ = command.Process.Kill()
71+
if strings.TrimSuffix(serr.String(), "\n") == errorDialingBackend {
72+
errchan <- io.EOF
73+
if command.Process != nil {
74+
_ = command.Process.Kill()
75+
}
76+
} else {
77+
errchan <- fmt.Errorf("unexpected error running port-forward: %w", errors.New(serr.String()))
78+
if command.Process != nil {
79+
_ = command.Process.Kill()
80+
}
6281
}
6382
}
6483
}()

0 commit comments

Comments
 (0)