@@ -27,8 +27,6 @@ import (
2727 "golang.org/x/net/websocket"
2828
2929 "k8s.io/apimachinery/pkg/util/httpstream"
30- "k8s.io/apimachinery/pkg/util/portforward"
31- "k8s.io/apimachinery/pkg/util/remotecommand"
3230 "k8s.io/apimachinery/pkg/util/runtime"
3331 "k8s.io/klog/v2"
3432)
@@ -312,17 +310,24 @@ func (conn *Conn) Close() error {
312310 return conn .closeNonThreadSafe ()
313311}
314312
313+ const (
314+ StreamProtocolV5Name = "v5.channel.k8s.io"
315+ WebsocketsSPDYTunnelingPrefix = "SPDY/3.1+"
316+ KubernetesSuffix = ".k8s.io"
317+ StreamClose = 255
318+ )
319+
315320// protocolSupportsStreamClose returns true if the passed protocol
316321// supports the stream close signal (currently only V5 remotecommand);
317322// false otherwise.
318323func protocolSupportsStreamClose (protocol string ) bool {
319- return protocol == remotecommand . StreamProtocolV5Name
324+ return protocol == StreamProtocolV5Name
320325}
321326
322327// protocolSupportsWebsocketTunneling returns true if the passed protocol
323328// is a tunneled Kubernetes spdy protocol; false otherwise.
324329func protocolSupportsWebsocketTunneling (protocol string ) bool {
325- return strings .HasPrefix (protocol , portforward . WebsocketsSPDYTunnelingPrefix ) && strings .HasSuffix (protocol , portforward . KubernetesSuffix )
330+ return strings .HasPrefix (protocol , WebsocketsSPDYTunnelingPrefix ) && strings .HasSuffix (protocol , KubernetesSuffix )
326331}
327332
328333// handle implements a websocket handler.
@@ -343,7 +348,7 @@ func (conn *Conn) handle(ws *websocket.Conn) {
343348 if len (data ) == 0 {
344349 continue
345350 }
346- if supportsStreamClose && data [0 ] == remotecommand . StreamClose {
351+ if supportsStreamClose && data [0 ] == StreamClose {
347352 if len (data ) != 2 {
348353 klog .Errorf ("Single channel byte should follow stream close signal. Got %d bytes" , len (data )- 1 )
349354 break
0 commit comments