mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
e2e test use websockets as default for exec operations
This commit is contained in:
parent
3985b78f06
commit
071b1bd839
@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/remotecommand"
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
@ -80,8 +81,8 @@ func ExecWithOptionsContext(ctx context.Context, f *framework.Framework, options
|
|||||||
}, scheme.ParameterCodec)
|
}, scheme.ParameterCodec)
|
||||||
|
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
framework.Logf("ExecWithOptions: execute(POST %s)", req.URL())
|
framework.Logf("ExecWithOptions: execute(%s)", req.URL())
|
||||||
err := execute(ctx, "POST", req.URL(), f.ClientConfig(), options.Stdin, &stdout, &stderr, tty)
|
err := execute(ctx, req.URL(), f.ClientConfig(), options.Stdin, &stdout, &stderr, tty)
|
||||||
|
|
||||||
if options.PreserveWhitespace {
|
if options.PreserveWhitespace {
|
||||||
return stdout.String(), stderr.String(), err
|
return stdout.String(), stderr.String(), err
|
||||||
@ -181,11 +182,29 @@ func VerifyExecInPodFail(ctx context.Context, f *framework.Framework, pod *v1.Po
|
|||||||
return fmt.Errorf("%q should fail with exit code %d, but exit without error", shExec, exitCode)
|
return fmt.Errorf("%q should fail with exit code %d, but exit without error", shExec, exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func execute(ctx context.Context, method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {
|
func execute(ctx context.Context, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {
|
||||||
exec, err := remotecommand.NewSPDYExecutor(config, method, url)
|
// WebSocketExecutor executor is default
|
||||||
|
// WebSocketExecutor must be "GET" method as described in RFC 6455 Sec. 4.1 (page 17).
|
||||||
|
websocketExec, err := remotecommand.NewWebSocketExecutor(config, "GET", url.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
spdyExec, err := remotecommand.NewSPDYExecutor(config, "POST", url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
exec, err := remotecommand.NewFallbackExecutor(websocketExec, spdyExec, func(err error) bool {
|
||||||
|
if httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err) {
|
||||||
|
framework.Logf("fallback to secondary dialer from primary dialer err: %v", err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
framework.Logf("unexpected error trying to use websockets for pod exec: %v", err)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return exec.StreamWithContext(ctx, remotecommand.StreamOptions{
|
return exec.StreamWithContext(ctx, remotecommand.StreamOptions{
|
||||||
Stdin: stdin,
|
Stdin: stdin,
|
||||||
Stdout: stdout,
|
Stdout: stdout,
|
||||||
|
Loading…
Reference in New Issue
Block a user