proxy

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.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.ServiceMap
	EpsMap   k8sp.EndpointsMap
	NodeZone string
}

DPSyncerState groups the information passed to the DPSyncer's Apply

type K8sServicePortOption

type K8sServicePortOption func(interface{})

K8sServicePortOption defines options for NewK8sServicePort

func K8sSvcWithExternalIPs

func K8sSvcWithExternalIPs(ips []string) K8sServicePortOption

K8sSvcWithExternalIPs sets ExternalIPs

func K8sSvcWithHintsAnnotation

func K8sSvcWithHintsAnnotation(hintsAnnotation string) K8sServicePortOption

K8sSvcWithHintsAnnotation sets hints annotation to service info object

func K8sSvcWithLBSourceRangeIPs

func K8sSvcWithLBSourceRangeIPs(ips []string) K8sServicePortOption

K8sSvcWithLBSourceRangeIPs sets LBSourcePortRangeIPs

func K8sSvcWithLoadBalancerIPs

func K8sSvcWithLoadBalancerIPs(ips []string) 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 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.Maps, 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.Key)

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

func (*KubeProxy) OnRouteUpdate

func (kp *KubeProxy) OnRouteUpdate(k routes.Key, v routes.Value)

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 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()
}

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

func New

func New(k8s kubernetes.Interface, dp DPSyncer, hostname string, opts ...Option) (Proxy, 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.Key) error

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

func (*RTCache) DeleteV4

func (rt *RTCache) DeleteV4(k routes.Key) error

DeleteV4 deletes an entry and errors if the key is not V4

func (*RTCache) Lookup

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

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

func (*RTCache) LookupV4

func (rt *RTCache) LookupV4(addr ip.V4Addr) (routes.Value, bool)

LookupV4 is the same as Lookup for V4 only

func (*RTCache) Update

func (rt *RTCache) Update(k routes.Key, v routes.Value) error

Update either creates an entry or updates an existing one

func (*RTCache) UpdateV4

func (rt *RTCache) UpdateV4(k routes.Key, v routes.Value) error

UpdateV4 makes an update with V4 CIDR or errors

func (*RTCache) WaitAfter

func (rt *RTCache) WaitAfter(ctx context.Context,
	fn func(lookup func(addr ip.Addr) (routes.Value, 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.Value, bool)
	WaitAfter(ctx context.Context, fn func(lookup func(addr ip.Addr) (routes.Value, bool)) bool)
}

Routes is an interface to query routes

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(nodePortIPs []net.IP,
	svcsmap *cachingmap.CachingMap[nat.FrontendKey, nat.FrontendValue],
	epsmap *cachingmap.CachingMap[nat.BackendKey, nat.BackendValue],
	affmap maps.Map, rt Routes) (*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 from 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