mirror of
https://github.com/kubernetes/client-go.git
synced 2026-05-18 21:55:25 +00:00
Extract streaming code into dedicated staging modules while keeping stable compatibility APIs for external client-go consumers. This commit: - adds `k8s.io/cri-streaming` for CRI exec/attach/portforward server code - adds `k8s.io/streaming` as the canonical home for shared transport primitives (`httpstream`, `spdy`, `wsstream`, runtime helpers) - switches in-tree transport consumers to `k8s.io/streaming` - removes in-tree kubelet CRI streaming package - preserves NO_PROXY/no_proxy CIDR handling in extracted SPDY proxier logic - adds deprecated `k8s.io/apimachinery/pkg/util/httpstream` compatibility wrappers (`httpstream`, `spdy`, `wsstream`) backed by `k8s.io/streaming` - restores exported client-go SPDY/portforward API signatures to apimachinery `httpstream` types for downstream compatibility - adds streaming-native client-go adapters/constructors so in-tree callers can use `k8s.io/streaming` without changing external compatibility APIs - deduplicates SPDY-over-websocket dial negotiation shared by compat and streaming tunneling dialers - logs dropped unknown stream types in `RemoveStreams` adapter fallbacks to improve compatibility-path debuggability - adds integration coverage for the streaming-upgrader-to-client-go-compat adapter path against a real cri-streaming exec endpoint - clarifies kubectl streaming import aliasing to avoid `httpstream` package ambiguity - updates tests, import restrictions, publishing metadata, and vendor/module metadata for the new staging modules Signed-off-by: Davanum Srinivas <davanum@gmail.com> Kubernetes-commit: 1ee1ff97fb7f9755a44d29bee0c80d2ccbed68dc
89 lines
3.3 KiB
Go
89 lines
3.3 KiB
Go
/*
|
|
Copyright 2024 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package portforward
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/util/httpstream"
|
|
"k8s.io/klog/v2"
|
|
streamhttp "k8s.io/streaming/pkg/httpstream"
|
|
)
|
|
|
|
var _ httpstream.Dialer = &FallbackDialer{}
|
|
var _ streamhttp.Dialer = &StreamingFallbackDialer{}
|
|
|
|
// FallbackDialer encapsulates a primary and secondary dialer, including
|
|
// the boolean function to determine if the primary dialer failed. Implements
|
|
// the httpstream.Dialer interface.
|
|
type FallbackDialer struct {
|
|
primary httpstream.Dialer
|
|
secondary httpstream.Dialer
|
|
shouldFallback func(error) bool
|
|
}
|
|
|
|
// NewFallbackDialer creates the FallbackDialer with the primary and secondary dialers,
|
|
// as well as the boolean function to determine if the primary dialer failed.
|
|
func NewFallbackDialer(primary, secondary httpstream.Dialer, shouldFallback func(error) bool) httpstream.Dialer {
|
|
return &FallbackDialer{
|
|
primary: primary,
|
|
secondary: secondary,
|
|
shouldFallback: shouldFallback,
|
|
}
|
|
}
|
|
|
|
// StreamingFallbackDialer encapsulates a primary and secondary streaming dialer
|
|
// with fallback behavior.
|
|
type StreamingFallbackDialer struct {
|
|
primary streamhttp.Dialer
|
|
secondary streamhttp.Dialer
|
|
shouldFallback func(error) bool
|
|
}
|
|
|
|
// NewFallbackDialerForStreaming creates a fallback dialer for in-tree callers
|
|
// that use k8s.io/streaming/pkg/httpstream types.
|
|
func NewFallbackDialerForStreaming(primary, secondary streamhttp.Dialer, shouldFallback func(error) bool) streamhttp.Dialer {
|
|
return &StreamingFallbackDialer{
|
|
primary: primary,
|
|
secondary: secondary,
|
|
shouldFallback: shouldFallback,
|
|
}
|
|
}
|
|
|
|
// Dial is the single function necessary to implement the "httpstream.Dialer" interface.
|
|
// It takes the protocol version strings to request, returning an the upgraded
|
|
// httstream.Connection and the negotiated protocol version accepted. If the initial
|
|
// primary dialer fails, this function attempts the secondary dialer. Returns an error
|
|
// if one occurs.
|
|
func (f *FallbackDialer) Dial(protocols ...string) (httpstream.Connection, string, error) {
|
|
conn, version, err := f.primary.Dial(protocols...)
|
|
if err != nil && f.shouldFallback(err) {
|
|
klog.V(4).Infof("fallback to secondary dialer from primary dialer err: %v", err)
|
|
return f.secondary.Dial(protocols...)
|
|
}
|
|
return conn, version, err
|
|
}
|
|
|
|
// Dial is the single function necessary to implement the
|
|
// "k8s.io/streaming/pkg/httpstream.Dialer" interface.
|
|
func (f *StreamingFallbackDialer) Dial(protocols ...string) (streamhttp.Connection, string, error) {
|
|
conn, version, err := f.primary.Dial(protocols...)
|
|
if err != nil && f.shouldFallback(err) {
|
|
klog.V(4).Infof("fallback to secondary dialer from primary dialer err: %v", err)
|
|
return f.secondary.Dial(protocols...)
|
|
}
|
|
return conn, version, err
|
|
}
|