remote command turn on feature gates

Kubernetes-commit: a147693deb2e7f040cf367aae4a7ae5d1cb3e7aa
This commit is contained in:
Sean Sullivan 2024-02-13 14:10:40 -08:00 committed by Kubernetes Publisher
parent 8c4efe8d07
commit 7eae79e001
2 changed files with 7 additions and 7 deletions

View File

@ -20,9 +20,9 @@ import (
"context" "context"
) )
var _ Executor = &fallbackExecutor{} var _ Executor = &FallbackExecutor{}
type fallbackExecutor struct { type FallbackExecutor struct {
primary Executor primary Executor
secondary Executor secondary Executor
shouldFallback func(error) bool shouldFallback func(error) bool
@ -33,7 +33,7 @@ type fallbackExecutor struct {
// websocket "StreamWithContext" call fails. // websocket "StreamWithContext" call fails.
// func NewFallbackExecutor(config *restclient.Config, method string, url *url.URL) (Executor, error) { // func NewFallbackExecutor(config *restclient.Config, method string, url *url.URL) (Executor, error) {
func NewFallbackExecutor(primary, secondary Executor, shouldFallback func(error) bool) (Executor, error) { func NewFallbackExecutor(primary, secondary Executor, shouldFallback func(error) bool) (Executor, error) {
return &fallbackExecutor{ return &FallbackExecutor{
primary: primary, primary: primary,
secondary: secondary, secondary: secondary,
shouldFallback: shouldFallback, shouldFallback: shouldFallback,
@ -41,14 +41,14 @@ func NewFallbackExecutor(primary, secondary Executor, shouldFallback func(error)
} }
// Stream is deprecated. Please use "StreamWithContext". // Stream is deprecated. Please use "StreamWithContext".
func (f *fallbackExecutor) Stream(options StreamOptions) error { func (f *FallbackExecutor) Stream(options StreamOptions) error {
return f.StreamWithContext(context.Background(), options) return f.StreamWithContext(context.Background(), options)
} }
// StreamWithContext initially attempts to call "StreamWithContext" using the // StreamWithContext initially attempts to call "StreamWithContext" using the
// primary executor, falling back to calling the secondary executor if the // primary executor, falling back to calling the secondary executor if the
// initial primary call to upgrade to a websocket connection fails. // initial primary call to upgrade to a websocket connection fails.
func (f *fallbackExecutor) StreamWithContext(ctx context.Context, options StreamOptions) error { func (f *FallbackExecutor) StreamWithContext(ctx context.Context, options StreamOptions) error {
err := f.primary.StreamWithContext(ctx, options) err := f.primary.StreamWithContext(ctx, options)
if f.shouldFallback(err) { if f.shouldFallback(err) {
return f.secondary.StreamWithContext(ctx, options) return f.secondary.StreamWithContext(ctx, options)

View File

@ -193,8 +193,8 @@ func TestFallbackClient_PrimaryAndSecondaryFail(t *testing.T) {
exec, err := NewFallbackExecutor(websocketExecutor, spdyExecutor, func(error) bool { return true }) exec, err := NewFallbackExecutor(websocketExecutor, spdyExecutor, func(error) bool { return true })
require.NoError(t, err) require.NoError(t, err)
// Update the websocket executor to request remote command v4, which is unsupported. // Update the websocket executor to request remote command v4, which is unsupported.
fallbackExec, ok := exec.(*fallbackExecutor) fallbackExec, ok := exec.(*FallbackExecutor)
assert.True(t, ok, "error casting executor as fallbackExecutor") assert.True(t, ok, "error casting executor as FallbackExecutor")
websocketExec, ok := fallbackExec.primary.(*wsStreamExecutor) websocketExec, ok := fallbackExec.primary.(*wsStreamExecutor)
assert.True(t, ok, "error casting executor as websocket executor") assert.True(t, ok, "error casting executor as websocket executor")
// Set the attempted subprotocol version to V4; websocket server only accepts V5. // Set the attempted subprotocol version to V4; websocket server only accepts V5.