portforward

package
v0.28.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

portforward contains functionality for port-forwarding an entire application from Kubernetes. This functionality is based on the kubernetes client APIs and implemented inside this package.

Package portforward is a generated GoMock package.

Index

Constants

View Source
const (
	KindConnected    = "connected"
	KindDisconnected = "disconnected"
)

Variables

This section is empty.

Functions

func NewApplicationWatcher

func NewApplicationWatcher(options Options) *applicationWatcher

NewApplicationWatcher creates a new applicationWatcher struct with the given options and initializes the done channel and deploymentWatchers map.

func NewDeploymentWatcher

func NewDeploymentWatcher(options Options, matchLabels map[string]string, revision string, cancel func()) *deploymentWatcher

NewDeploymentWatcher creates a new deploymentWatcher struct with the given parameters and returns a pointer to it.

func NewFakeForwarder

func NewFakeForwarder(ports map[int32]bool) forwarder

NewFakeForwarder takes in a map of ports and returns a fakeforwarder which contains a ready channel and a list of ForwardedPort objects with the same local and remote ports.

func NewPodWatcher

func NewPodWatcher(options Options, pod *corev1.Pod, cancel func()) *podWatcher

"NewPodWatcher" creates a new podWatcher struct with the given options, pod and cancel function, and initializes the done, forwarderDone, log, and Updated channels.

Types

type Impl

type Impl struct {
}

func (*Impl) Run

func (i *Impl) Run(ctx context.Context, options Options) error

Run sets up a watcher to monitor deployments in an application, and if a pod shuts down, it will pick the newest replica and forward to that. It returns an error if there is an issue with initializing the clientset.

type Interface

type Interface interface {
	// Run will establish port-forward connections to every Kubernetes pod that
	// is labeled as being part of the Radius Application. Basing the logic on Kubernetes deployments rather
	// than Radius containers allows us to support resources created in recipes.
	//
	// Run will block until the provided context is cancelled.
	//
	// Run will allocate local ports that match the container ports of the deployments/pods where possible.
	// When a conflict occurs or when the local port is unavailable, a random port will be chosen.
	Run(ctx context.Context, options Options) error
}

Interface is the interface type for port-forwarding.

type MockInterface

type MockInterface struct {
	// contains filtered or unexported fields
}

MockInterface is a mock of Interface interface.

func NewMockInterface

func NewMockInterface(ctrl *gomock.Controller) *MockInterface

NewMockInterface creates a new mock instance.

func (*MockInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockInterface) Run

func (m *MockInterface) Run(arg0 context.Context, arg1 Options) error

Run mocks base method.

type MockInterfaceMockRecorder

type MockInterfaceMockRecorder struct {
	// contains filtered or unexported fields
}

MockInterfaceMockRecorder is the mock recorder for MockInterface.

func (*MockInterfaceMockRecorder) Run

func (mr *MockInterfaceMockRecorder) Run(arg0, arg1 interface{}) *gomock.Call

Run indicates an expected call of Run.

type Options

type Options struct {
	// ApplicationName is the name of the application.
	ApplicationName string

	// Namespace is the kubernetes namespace of the application.
	Namespace string

	// KubeContext is the kubernetes context to use. If Client or RESTConfig is unset, this will be
	// used to initialize those fields.
	KubeContext string

	// Client is the Kubernetes client used to access the cluster. If this is set then RESTConfig
	// must also be set.
	//
	// We are using client-go here because the fake client from client-go has
	// better support for watch.
	Client k8sclient.Interface

	// Out is where output will be written.
	Out io.Writer

	// RESTConfig is the Kubernetes configuration for connecting to the server. If this is set then
	// Client must also be set.
	RESTConfig *rest.Config

	// Status chan will receive StatusMessage updates if provided.
	StatusChan chan<- StatusMessage
}

Options specifies the options for port-forwarding.

type StatusKind

type StatusKind = string

type StatusMessage

type StatusMessage struct {
	Kind          StatusKind
	ContainerName string
	ReplicaName   string
	LocalPort     uint16
	RemotePort    uint16
}

StatusMessage is the type used to communicate a change in port-forward status.

Jump to

Keyboard shortcuts

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