portforwarding

package
v0.0.0-...-37f102e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Sessions = SessionMap{Sessions: make(map[string]*Session)}

Sessions holds all active port forwarding sessions.

Functions

This section is empty.

Types

type CreateRequest

type CreateRequest struct {
	ClusterServer                   string `json:"clusterServer"`
	ClusterCertificateAuthorityData string `json:"clusterCertificateAuthorityData"`
	ClusterInsecureSkipTLSVerify    bool   `json:"clusterInsecureSkipTLSVerify"`
	UserClientCertificateData       string `json:"userClientCertificateData"`
	UserClientKeyData               string `json:"userClientKeyData"`
	UserToken                       string `json:"userToken"`
	UserUsername                    string `json:"userUsername"`
	UserPassword                    string `json:"userPassword"`
	Proxy                           string `json:"proxy"`
	Timeout                         int64  `json:"timeout"`
	PodName                         string `json:"podName"`
	PodNamespace                    string `json:"podNamespace"`
	PodContainer                    string `json:"podContainer"`
	PodPort                         int64  `json:"podPort"`
	ServiceSelector                 string `json:"serviceSelector"`
	ServiceTargetPort               string `json:"serviceTargetPort"`
}

CreateRequest is the structure of a request to initalize a port forwarding session. It contains all the required fields to create a Kubernetes client as well as the pod name and namespace and the port which should be forwarded.

type DeleteRequest

type DeleteRequest struct {
	SessionID string `json:"sessionID"`
}

DeleteRequest is the structure of a request to delete a port forwarding session, for that is just contains the session id.

type GetResponse

type GetResponse struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Namespace  string `json:"namespace"`
	Container  string `json:"container"`
	RemotePort int64  `json:"remotePort"`
	LocalPort  int64  `json:"localPort"`
}

GetResponse is the structure of the returned sessions for a get request.

type Session

type Session struct {
	ID         string
	Name       string
	Namespace  string
	Container  string
	RemotePort int64
	LocalPort  int64
	StopCh     chan struct{}
	ReadyCh    chan struct{}
	Streams    genericclioptions.IOStreams
}

Session is the structure for an establish port forwading session. It contains the session id, the local port which should be used for the port forwarding, a channel to close the connection, a channel which can be used to check if the connection is ready and the IO streams.

func CreateSession

func CreateSession(sessionPrefix, name, namespace, container string, remotePort int64) (*Session, error)

CreateSession creates a new port forwarding session. To create a new session the function requires a session prefix, which can be used to differentiate between user initiated sessions and plugin sessions.

func (*Session) Start

func (s *Session) Start(restConfig *rest.Config, path string, remotePort int64) error

Start starts the port forwarding request. For that we are need a rest config to interact with the Kubernets API, the request path for the port forwarding endpoint and the remote port shich should be forwarded.

type SessionMap

type SessionMap struct {
	Sessions map[string]*Session
	Lock     sync.RWMutex
}

SessionMap stores a map of all PortForwardSession objects and a lock to avoid concurrent conflict.

func (*SessionMap) Delete

func (sm *SessionMap) Delete(sessionID string)

Delete removes a session from the active sessions.

func (*SessionMap) Get

func (sm *SessionMap) Get(sessionID string) (*Session, bool)

Get return a given portForwardSession by sessionID.

func (*SessionMap) Set

func (sm *SessionMap) Set(sessionID string, session *Session)

Set store a PortForwardSession to SessionMap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL