package proxy
import "k8s.io/apiserver/pkg/util/proxy"
Among other files, this directory contains functionality for two stream proxies: streamtranslator.go and streamtunnel.go. Both of these proxies allow the inter-connection of WebSocket and SPDY streaming connections.
The stream translator proxy is used for the RemoteCommand subprotocol (e.g. kubectl exec, cp, and attach), and it connects the output streams of a WebSocket connection (e.g. STDIN, STDOUT, STDERR, TTY resize, and error streams) to the input streams of a SPDY connection.
The stream tunnel proxy tunnels SPDY frames through a WebSocket connection, and it is used for the PortForward subprotocol (e.g. kubectl port-forward). This proxy implements tunneling by transparently encoding and decoding SPDY framed data into and out of the payload of a WebSocket data frame. The primary structure for this tunneling is the TunnelingConnection. A lot of the other code in streamtunnel.go is for properly upgrading both the upstream SPDY connection and the downstream WebSocket connection before streaming begins.
Index ¶
- func NewRequestForProxy(location *url.URL, req *http.Request) (*http.Request, context.CancelFunc)
- func NewTranslatingHandler(delegate http.Handler, translator http.Handler, shouldTranslate func(*http.Request) bool) http.Handler
- func ResolveCluster(services listersv1.ServiceLister, namespace, id string, port int32) (*url.URL, error)
- func ResolveEndpoint(services listersv1.ServiceLister, endpointSlices EndpointSliceGetter, namespace, id string, port int32) (*url.URL, error)
- type EndpointSliceGetter
- func NewEndpointSliceIndexerGetter(sliceInformer discoveryv1informer.EndpointSliceInformer) (EndpointSliceGetter, error)
- func NewEndpointSliceListerGetter(sliceLister discoveryv1lister.EndpointSliceLister) (EndpointSliceGetter, error)
- type Options
- type StreamTranslatorHandler
- func NewStreamTranslatorHandler(location *url.URL, transport http.RoundTripper, maxBytesPerSec int64, opts Options) *StreamTranslatorHandler
- func (h *StreamTranslatorHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type TunnelingHandler
Functions ¶
func NewRequestForProxy ¶
NewRequestForProxy returns a shallow copy of the original request with a context that may include a timeout for discovery requests
func NewTranslatingHandler ¶
func NewTranslatingHandler(delegate http.Handler, translator http.Handler, shouldTranslate func(*http.Request) bool) http.Handler
func ResolveCluster ¶
func ResolveCluster(services listersv1.ServiceLister, namespace, id string, port int32) (*url.URL, error)
func ResolveEndpoint ¶
func ResolveEndpoint(services listersv1.ServiceLister, endpointSlices EndpointSliceGetter, namespace, id string, port int32) (*url.URL, error)
ResolveEndpoint returns a URL to which one can send traffic for the specified service. If the service is dual-stack, the URL will preferentially point to an endpoint of the service's primary IP family.
Types ¶
type EndpointSliceGetter ¶
type EndpointSliceGetter interface { // GetEndpointSlices returns all of the known slices associated with the given // service. If there are no slices associated with the service, it will return an // empty list, not an error. GetEndpointSlices(namespaceName, serviceName string) ([]*discoveryv1.EndpointSlice, error) }
EndpointSliceGetter is an interface for a helper that lets you easily get all EndpointSlices for a Service.
func NewEndpointSliceIndexerGetter ¶
func NewEndpointSliceIndexerGetter(sliceInformer discoveryv1informer.EndpointSliceInformer) (EndpointSliceGetter, error)
NewEndpointSliceIndexerGetter returns an EndpointSliceGetter that wraps an informer and updates its indexes so that you can efficiently find the EndpointSlices associated with a Service later. (Note that sliceInformer will continue the additional indexing for as long as it runs, even if if the EndpointSliceGetter is destroyed. Use NewEndpointSliceListerGetter if you want want to fetch EndpointSlices without changing the underlying cache.)
func NewEndpointSliceListerGetter ¶
func NewEndpointSliceListerGetter(sliceLister discoveryv1lister.EndpointSliceLister) (EndpointSliceGetter, error)
NewEndpointSliceListerGetter returns an EndpointSliceGetter that uses a lister to do a full selection on every lookup.
type Options ¶
Options contains details about which streams are required for remote command execution.
type StreamTranslatorHandler ¶
type StreamTranslatorHandler struct { // Location is the location of the upstream proxy. It is used as the location to Dial on the upstream server // for upgrade requests. Location *url.URL // Transport provides an optional round tripper to use to proxy. If nil, the default proxy transport is used Transport http.RoundTripper // MaxBytesPerSec throttles stream Reader/Writer if necessary MaxBytesPerSec int64 // Options define the requested streams (e.g. stdin, stdout). Options Options }
StreamTranslatorHandler is a handler which translates WebSocket stream data to SPDY to proxy to kubelet (and ContainerRuntime).
func NewStreamTranslatorHandler ¶
func NewStreamTranslatorHandler(location *url.URL, transport http.RoundTripper, maxBytesPerSec int64, opts Options) *StreamTranslatorHandler
NewStreamTranslatorHandler creates a new proxy handler. Responder is required for returning errors to the caller.
func (*StreamTranslatorHandler) ServeHTTP ¶
func (h *StreamTranslatorHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type TunnelingHandler ¶
type TunnelingHandler struct {
// contains filtered or unexported fields
}
TunnelingHandler is a handler which tunnels SPDY through WebSockets.
func NewTunnelingHandler ¶
func NewTunnelingHandler(upgradeHandler http.Handler) *TunnelingHandler
NewTunnelingHandler is used to create the tunnel between an upstream SPDY connection and a downstream tunneling connection through the stored UpgradeAwareProxy.
func (*TunnelingHandler) ServeHTTP ¶
func (h *TunnelingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP uses the upgradeHandler to tunnel between a downstream tunneling connection and an upstream SPDY connection. The tunneling connection is a wrapped WebSockets connection which communicates SPDY framed data. In the case the upstream upgrade fails, we delegate communication to the passed in "w" ResponseWriter.
Source Files ¶
doc.go endpointslice.go proxy.go streamtranslator.go streamtunnel.go translatinghandler.go websocket.go
Directories ¶
Path | Synopsis |
---|---|
pkg/util/proxy/metrics |
- Version
- v0.35.0-alpha.0
- Published
- Aug 6, 2025
- Platform
- js/wasm
- Imports
- 42 packages
- Last checked
- 27 minutes ago –
Tools for package owners.