proxy

package
v0.0.0-...-d216c5d Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReapTerminatingUDPAnnotation   = "projectcalico.org/udpConntrackCleanup"
	ReapTerminatingUDPImmediatelly = "TerminatingImmediately"

	ExcludeServiceAnnotation = "projectcalico.org/natExcludeService"
)

Variables

This section is empty.

Functions

func NewEndpointInfo

func NewEndpointInfo(ip string, port int, opts ...EndpoiontInfoOpt) k8sp.Endpoint

NewEndpointInfo creates a new endpointInfo, returning it as a k8s proxy Endpoint.

func NewK8sServicePort

func NewK8sServicePort(clusterIP net.IP, port int, proto v1.Protocol,
	opts ...K8sServicePortOption) k8sp.ServicePort

NewK8sServicePort creates a new k8s ServicePort

func ProtoV1ToInt

func ProtoV1ToInt(p v1.Protocol) (uint8, error)

ProtoV1ToInt translates k8s v1.Protocol to its IANA number and returns error if the proto is not recognized

func ProtoV1ToIntPanic

func ProtoV1ToIntPanic(p v1.Protocol) uint8

ProtoV1ToIntPanic translates k8s v1.Protocol to its IANA number and panics if the protocol is not recognized

func ServicePortEqual

func ServicePortEqual(a, b k8sp.ServicePort) bool

ServicePortEqual compares if two k8sp.ServicePort are equal, that is all of their methods return equal values, i.e., they may differ in implementation, but present themselves equally. String() is not considered as it may differ for debugging reasons.

func ShouldAppendTopologyAwareEndpoint

func ShouldAppendTopologyAwareEndpoint(nodeZone string, hintsAnnotation string, zoneHints sets.Set[string]) bool

Types

type DPSyncer

type DPSyncer interface {
	Apply(state DPSyncerState) error
	ConntrackScanStart()
	ConntrackScanEnd()
	ConntrackFrontendHasBackend(ip net.IP, port uint16, backendIP net.IP, backendPort uint16, proto uint8) bool
	Stop()
	SetTriggerFn(func())
}

DPSyncer is an interface representing the dataplane syncer that applies the observed changes to the dataplane

type DPSyncerState

type DPSyncerState struct {
	SvcMap   k8sp.ServicePortMap
	EpsMap   k8sp.EndpointsMap
	NodeZone string
}

DPSyncerState groups the information passed to the DPSyncer's Apply

type EndpoiontInfoOpt

type EndpoiontInfoOpt func(*endpointInfo)

func EndpointInfoOptIsLocal

func EndpointInfoOptIsLocal(b bool) EndpoiontInfoOpt

EndpointInfoOptIsLocal applies the given bool to the endpoint's isLocal field.

func EndpointInfoOptIsReady

func EndpointInfoOptIsReady(b bool) EndpoiontInfoOpt

EndpointInfoOptIsReady applies the given bool to the endpoint's ready field.

func EndpointInfoOptIsServing

func EndpointInfoOptIsServing(b bool) EndpoiontInfoOpt

EndpointInfoOptIsServing applies the given bool to the endpoint's serving field.

func EndpointInfoOptIsTerminating

func EndpointInfoOptIsTerminating(b bool) EndpoiontInfoOpt

EndpointInfoOptIsTerminating applies the given bool to the endpoint's terminating field.

func EndpointInfoOptZoneHints

func EndpointInfoOptZoneHints(b sets.Set[string]) EndpoiontInfoOpt

EndpointInfoOptZoneHints applies the given set to the endpoint's zoneHints field.

type K8sServicePortOption

type K8sServicePortOption func(interface{})

K8sServicePortOption defines options for NewK8sServicePort

func K8sSvcWithExternalIPs

func K8sSvcWithExternalIPs(ips []net.IP) K8sServicePortOption

K8sSvcWithExternalIPs sets ExternalIPs

func K8sSvcWithHintsAnnotation

func K8sSvcWithHintsAnnotation(hintsAnnotation string) K8sServicePortOption

K8sSvcWithHintsAnnotation sets hints annotation to service info object

func K8sSvcWithLBSourceRangeIPs

func K8sSvcWithLBSourceRangeIPs(ips []*net.IPNet) K8sServicePortOption

K8sSvcWithLBSourceRangeIPs sets LBSourcePortRangeIPs

func K8sSvcWithLoadBalancerIPs

func K8sSvcWithLoadBalancerIPs(ips []net.IP) K8sServicePortOption

K8sSvcWithLoadBalancerIPs set LoadBalancerIPStrings

func K8sSvcWithLocalOnly

func K8sSvcWithLocalOnly() K8sServicePortOption

K8sSvcWithLocalOnly sets OnlyNodeLocalEndpoints=true

func K8sSvcWithNodePort

func K8sSvcWithNodePort(np int) K8sServicePortOption

K8sSvcWithNodePort sets the nodeport

func K8sSvcWithReapTerminatingUDP

func K8sSvcWithReapTerminatingUDP() K8sServicePortOption

func K8sSvcWithStickyClientIP

func K8sSvcWithStickyClientIP(seconds int) K8sServicePortOption

K8sSvcWithStickyClientIP sets ServiceAffinityClientIP to seconds

type KubeProxy

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

KubeProxy is a wrapper of Proxy that deals with higher level issue like configuration, restarting etc.

func StartKubeProxy

func StartKubeProxy(k8s kubernetes.Interface, hostname string,
	bpfMaps *bpfmap.IPMaps, opts ...Option) (*KubeProxy, error)

StartKubeProxy start a new kube-proxy if there was no error

func (*KubeProxy) ConntrackFrontendHasBackend

func (kp *KubeProxy) ConntrackFrontendHasBackend(ip net.IP, port uint16, backendIP net.IP,
	backendPort uint16, proto uint8) bool

ConntrackFrontendHasBackend to satisfy conntrack.NATChecker - forwards to syncer.

func (*KubeProxy) ConntrackScanEnd

func (kp *KubeProxy) ConntrackScanEnd()

ConntrackScanEnd to satisfy conntrack.NATChecker - forwards to syncer.

func (*KubeProxy) ConntrackScanStart

func (kp *KubeProxy) ConntrackScanStart()

ConntrackScanStart to satisfy conntrack.NATChecker - forwards to syncer.

func (*KubeProxy) OnHostIPsUpdate

func (kp *KubeProxy) OnHostIPsUpdate(IPs []net.IP)

OnHostIPsUpdate should be used by an external user to update the proxy's list of host IPs

func (*KubeProxy) OnRouteDelete

func (kp *KubeProxy) OnRouteDelete(k routes.KeyInterface)

OnRouteDelete should be used to update the internal state of routing tables

func (*KubeProxy) OnRouteUpdate

func (kp *KubeProxy) OnRouteUpdate(k routes.KeyInterface, v routes.ValueInterface)

OnRouteUpdate should be used to update the internal state of routing tables

func (*KubeProxy) Stop

func (kp *KubeProxy) Stop()

Stop stops KubeProxy and waits for it to exit

type Option

type Option func(Proxy) error

Option defines Proxy options

func WithDSREnabled

func WithDSREnabled() Option

WithDSREnabled sets the DSR mode

func WithExcludedCIDRs

func WithExcludedCIDRs(cidrs []string) Option

func WithIPFamily

func WithIPFamily(ipFamily int) Option

func WithImmediateSync

func WithImmediateSync() Option

WithImmediateSync triggers sync with dataplane on immediately on every update

func WithMinSyncPeriod

func WithMinSyncPeriod(min time.Duration) Option

WithMinSyncPeriod sets the minimum duration between two attempts to sync with the dataplane

func WithTopologyNodeZone

func WithTopologyNodeZone(nodeZone string) Option

WithTopologyNodeZone sets the topology node zone

type Proxy

type Proxy interface {
	// Stop stops the proxy and waits for its exit
	Stop()
	// contains filtered or unexported methods
}

Proxy watches for updates of Services and Endpoints, maintains their mapping and programs it into the dataplane

type ProxyFrontend

type ProxyFrontend interface {
	Proxy
	SetSyncer(DPSyncer)
}

func New

func New(k8s kubernetes.Interface, dp DPSyncer, hostname string, opts ...Option) (ProxyFrontend, error)

New returns a new Proxy for the given k8s interface

type RTCache

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

RTCache is a lookup data structure that allow inserting and deleting routes and to do a LPM prefix match for IP addresses

func NewRTCache

func NewRTCache() *RTCache

NewRTCache creates an empty routing cache

func (*RTCache) Delete

func (rt *RTCache) Delete(k routes.KeyInterface)

Delete deletes and entry if it exists, does not return error if not

func (*RTCache) Lookup

func (rt *RTCache) Lookup(addr ip.Addr) (routes.ValueInterface, bool)

Lookup looks LPM match for an address and returns the associated data.

func (*RTCache) Update

func (rt *RTCache) Update(k routes.KeyInterface, v routes.ValueInterface)

Update either creates an entry or updates an existing one

func (*RTCache) WaitAfter

func (rt *RTCache) WaitAfter(ctx context.Context,
	fn func(lookup func(addr ip.Addr) (routes.ValueInterface, bool)) bool)

WaitAfter executes a function and if it returns false, it blocks until another update or until the provided context is canceled. The function can do only lookups as the state of the cache is read-locked. It must use the provided lookup function.

type Routes

type Routes interface {
	Lookup(ip.Addr) (routes.ValueInterface, bool)
	WaitAfter(ctx context.Context, fn func(lookup func(addr ip.Addr) (routes.ValueInterface, bool)) bool)
}

Routes is an interface to query routes

type Service

type Service interface {
	k8sp.ServicePort
	ServiceAnnotations
}

Service combines k8s service properties with the service annotations

type ServiceAnnotations

type ServiceAnnotations interface {
	ReapTerminatingUDP() bool
	ExcludeService() bool
}

type Syncer

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

Syncer is an implementation of DPSyncer interface. It is not thread safe and should be called only once at a time

func NewSyncer

func NewSyncer(family int, nodePortIPs []net.IP,
	frontendMap maps.MapWithExistsCheck, backendMap maps.MapWithExistsCheck,
	affmap maps.Map, rt Routes,
	excludedCIDRs *ip.CIDRTrie,
) (*Syncer, error)

NewSyncer returns a new Syncer

func (*Syncer) Apply

func (s *Syncer) Apply(state DPSyncerState) error

Apply applies the new state

func (*Syncer) ConntrackFrontendHasBackend

func (s *Syncer) ConntrackFrontendHasBackend(ip net.IP, port uint16,
	backendIP net.IP, backendPort uint16, proto uint8) (ret bool)

ConntrackFrontendHasBackend returns true if the given front-backend pair exists

func (*Syncer) ConntrackScanEnd

func (s *Syncer) ConntrackScanEnd()

ConntrackScanEnd enables Apply and frees active maps

func (*Syncer) ConntrackScanStart

func (s *Syncer) ConntrackScanStart()

ConntrackScanStart excludes Apply from running and builds the active maps for ConntrackFrontendHasBackend

func (*Syncer) SetTriggerFn

func (s *Syncer) SetTriggerFn(f func())

func (*Syncer) Stop

func (s *Syncer) Stop()

Stop stops the syncer

func (*Syncer) StopExpandNPFixup

func (s *Syncer) StopExpandNPFixup()

Jump to

Keyboard shortcuts

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