fwdservice

package
v0.0.0-...-766fff1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PortMap

type PortMap struct {
	SourcePort string
	TargetPort string
}

* add port map @url https://github.com/txn2/kubefwd/issues/121

type ServiceFWD

type ServiceFWD struct {
	ClientSet    kubernetes.Clientset
	ListOptions  metav1.ListOptions
	Hostfile     *fwdport.HostFileWithLock
	ClientConfig restclient.Config
	RESTClient   restclient.RESTClient

	// Context is a unique key (string) in kubectl config representing
	// a user/cluster combination. Kubefwd uses context as the
	// cluster name when forwarding to more than one cluster.
	Context string

	// Namespace is the current Kubernetes Namespace to locate services
	// and the pods that back them for port-forwarding
	Namespace string

	// ClusterN is the ordinal index of the cluster (from configuration)
	// cluster 0 is considered local while > 0 is remote
	ClusterN int

	// NamespaceN is the ordinal index of the namespace from the
	// perspective of the user. Namespace 0 is considered local
	// while > 0 is an external namespace
	NamespaceN int

	// FwdInc the forward increment for ip
	FwdInc *int

	// Domain is specified by the user and used in place of .local
	Domain string

	PodLabelSelector     string      // The label selector to query for matching pods.
	NamespaceServiceLock *sync.Mutex //
	Svc                  *v1.Service // Reference to the k8s service.

	// Headless service will forward all of the pods,
	// while normally only a single pod is forwarded.
	Headless bool

	LastSyncedAt time.Time  // When was the set of pods last synced
	PortMap      *[]PortMap // port map array.

	// Use debouncer for listing pods so we don't hammer the k8s when a bunch of changes happen at once
	SyncDebouncer func(f func())

	// A mapping of all the pods currently being forwarded.
	// key = podName
	PortForwards map[string]*fwdport.PortForwardOpts
	DoneChannel  chan struct{} // After shutdown is complete, this channel will be closed

	ForwardConfigurationPath string   // file path to IP reservation configuration
	ForwardIPReservations    []string // cli passed IP reservations

	PortsConfigurationPath string // file path to IP reservation configuration

	CheckIPReservations bool //Check IP reservations

	CountErrors int //Count errors in a row
}

ServiceFWD Single service to forward, with a reference to all the pods being forwarded for it

func (*ServiceFWD) AddServicePod

func (svcFwd *ServiceFWD) AddServicePod(pfo *fwdport.PortForwardOpts)

AddServicePod

func (*ServiceFWD) GetPodsForService

func (svcFwd *ServiceFWD) GetPodsForService() []v1.Pod

GetPodsForService queries k8s and returns all pods backing this service which are eligible for port-forwarding; exclude some pods which are in final/failure state.

func (*ServiceFWD) ListServicePodNames

func (svcFwd *ServiceFWD) ListServicePodNames() []string

ListServicePodNames

func (*ServiceFWD) LoopPodsToForward

func (svcFwd *ServiceFWD) LoopPodsToForward(pods []v1.Pod, includePodNameInHost bool)

LoopPodsToForward starts the port-forwarding for each pod in the given list

func (*ServiceFWD) RemoveServicePod

func (svcFwd *ServiceFWD) RemoveServicePod(servicePodName string)

func (*ServiceFWD) String

func (svcFwd *ServiceFWD) String() string

String representation of a ServiceFWD returns a unique name in the form SERVICE_NAME.NAMESPACE.CONTEXT

func (*ServiceFWD) SyncPodForwards

func (svcFwd *ServiceFWD) SyncPodForwards(force bool)

SyncPodForwards selects one or all pods behind a service, and invokes the forwarding setup for that or those pod(s). It will remove pods in-mem that are no longer returned by k8s, should these not be correctly deleted.

Jump to

Keyboard shortcuts

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