loadbalancer

package
v1.13.11 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 32

Documentation

Overview

Package loadbalancer contains all logic related with the loadbalancer +groupName=pkg

Index

Constants

View Source
const (
	SVCTypeNone          = SVCType("NONE")
	SVCTypeHostPort      = SVCType("HostPort")
	SVCTypeClusterIP     = SVCType("ClusterIP")
	SVCTypeNodePort      = SVCType("NodePort")
	SVCTypeExternalIPs   = SVCType("ExternalIPs")
	SVCTypeLoadBalancer  = SVCType("LoadBalancer")
	SVCTypeLocalRedirect = SVCType("LocalRedirect")
)
View Source
const (
	SVCTrafficPolicyNone    = SVCTrafficPolicy("NONE")
	SVCTrafficPolicyCluster = SVCTrafficPolicy("Cluster")
	SVCTrafficPolicyLocal   = SVCTrafficPolicy("Local")
)
View Source
const (
	SVCNatPolicyNone  = SVCNatPolicy("NONE")
	SVCNatPolicyNat46 = SVCNatPolicy("Nat46")
	SVCNatPolicyNat64 = SVCNatPolicy("Nat64")
)
View Source
const (
	NONE = L4Type("NONE")
	// TCP type.
	TCP = L4Type("TCP")
	// UDP type.
	UDP = L4Type("UDP")
	// SCTP type.
	SCTP = L4Type("SCTP")
)
View Source
const (
	// ScopeExternal is the lookup scope for services from outside the node.
	ScopeExternal uint8 = iota
	// ScopeInternal is the lookup scope for services from inside the node.
	ScopeInternal
)
View Source
const (
	BackendStateActiveFlag = iota
	BackendStateTerminatingFlag
	BackendStateQuarantinedFlag
	BackendStateMaintenanceFlag
)
View Source
const DefaultBackendWeight = 100

DefaultBackendWeight is used when backend weight is not set in ServiceSpec

Variables

View Source
var (
	// AllProtocols is the list of all supported L4 protocols
	AllProtocols = []L4Type{TCP, UDP, SCTP}
)

Functions

func IsValidBackendState

func IsValidBackendState(state string) bool

func IsValidStateTransition

func IsValidStateTransition(old, new BackendState) bool

Types

type Backend

type Backend struct {
	// FEPortName is the frontend port name. This is used to filter backends sending to EDS.
	FEPortName string
	// ID of the backend
	ID BackendID
	// Weight of backend
	Weight uint16
	// Node hosting this backend. This is used to determine backends local to
	// a node.
	NodeName string
	L3n4Addr
	// State of the backend for load-balancing service traffic
	State BackendState
	// Preferred indicates if the healthy backend is preferred
	Preferred Preferred
}

Backend represents load balancer backend.

func NewBackend

func NewBackend(id BackendID, protocol L4Type, addrCluster cmtypes.AddrCluster, portNumber uint16) *Backend

NewBackend creates the Backend struct instance from given params. The default state for the returned Backend is BackendStateActive.

func NewBackendFromBackendModel

func NewBackendFromBackendModel(base *models.BackendAddress) (*Backend, error)

func NewBackendWithState

func NewBackendWithState(id BackendID, protocol L4Type, addrCluster cmtypes.AddrCluster, portNumber uint16,
	state BackendState) *Backend

NewBackendWithState creates the Backend struct instance from given params.

func (*Backend) DeepCopy

func (in *Backend) DeepCopy() *Backend

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Backend.

func (*Backend) DeepCopyInto

func (in *Backend) DeepCopyInto(out *Backend)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Backend) GetBackendModel

func (b *Backend) GetBackendModel() *models.BackendAddress

func (*Backend) String

func (b *Backend) String() string

type BackendID

type BackendID uint32

BackendID is the backend's ID.

type BackendState

type BackendState uint8

BackendState is the state of a backend for load-balancing service traffic.

const (
	// BackendStateActive refers to the backend state when it's available for
	// load-balancing traffic. It's the default state for a backend.
	// Backends in this state can be health-checked.
	BackendStateActive BackendState = iota
	// BackendStateTerminating refers to the terminating backend state so that
	// it can be gracefully removed.
	// Backends in this state won't be health-checked.
	BackendStateTerminating
	// BackendStateQuarantined refers to the backend state when it's unreachable,
	// and will not be selected for load-balancing traffic.
	// Backends in this state can be health-checked.
	BackendStateQuarantined
	// BackendStateMaintenance refers to the backend state where the backend
	// is put under maintenance, and will neither be selected for load-balancing
	// traffic nor be health-checked.
	BackendStateMaintenance
	// BackendStateInvalid is an invalid state, and is used to report error conditions.
	// Keep this as the last entry.
	BackendStateInvalid
)

BackendState tracks backend's ability to load-balance service traffic.

Valid transition states for a backend - BackendStateActive -> BackendStateTerminating, BackendStateQuarantined, BackendStateMaintenance BackendStateTerminating -> No valid state transition BackendStateQuarantined -> BackendStateActive, BackendStateTerminating BackendStateMaintenance -> BackendStateActive

Sources setting the states - BackendStateActive - Kubernetes events, service API BackendStateTerminating - Kubernetes events BackendStateQuarantined - service API BackendStateMaintenance - service API

func GetBackendState

func GetBackendState(state string) (BackendState, error)

func GetBackendStateFromFlags

func GetBackendStateFromFlags(flags uint8) BackendState

func (BackendState) String

func (state BackendState) String() (string, error)

type BackendStateFlags

type BackendStateFlags = uint8

BackendStateFlags is the datapath representation of the backend flags that are used in (lb{4,6}_backend.flags) to store backend state.

func NewBackendFlags

func NewBackendFlags(state BackendState) BackendStateFlags

type FEPortName

type FEPortName string

FEPortName is the name of the frontend's port.

type ID

type ID uint32

ID is the ID of L3n4Addr endpoint (either service or backend).

type L3n4Addr

type L3n4Addr struct {
	AddrCluster cmtypes.AddrCluster
	L4Addr
	Scope uint8
}

L3n4Addr is used to store, as an unique L3+L4 address in the KVStore. It also includes the lookup scope for frontend addresses which is used in service handling for externalTrafficPolicy=Local and internalTrafficPolicy=Local, that is, Scope{External,Internal}.

+deepequal-gen=true +deepequal-gen:private-method=true

func NewL3n4Addr

func NewL3n4Addr(protocol L4Type, addrCluster cmtypes.AddrCluster, portNumber uint16, scope uint8) *L3n4Addr

NewL3n4Addr creates a new L3n4Addr.

func NewL3n4AddrFromBackendModel

func NewL3n4AddrFromBackendModel(base *models.BackendAddress) (*L3n4Addr, error)

func NewL3n4AddrFromModel

func NewL3n4AddrFromModel(base *models.FrontendAddress) (*L3n4Addr, error)

func (*L3n4Addr) DeepCopy

func (in *L3n4Addr) DeepCopy() *L3n4Addr

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L3n4Addr.

func (*L3n4Addr) DeepCopyInto

func (in *L3n4Addr) DeepCopyInto(out *L3n4Addr)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*L3n4Addr) DeepEqual

func (l *L3n4Addr) DeepEqual(o *L3n4Addr) bool

DeepEqual returns true if both the receiver and 'o' are deeply equal.

func (*L3n4Addr) GetModel

func (a *L3n4Addr) GetModel() *models.FrontendAddress

func (L3n4Addr) Hash

func (a L3n4Addr) Hash() string

Hash calculates a unique string of the L3n4Addr e.g for use as a key in maps. Note: the resulting string is meant to be used as a key for maps and is not readable by a human eye when printed out.

func (*L3n4Addr) IsIPv6

func (a *L3n4Addr) IsIPv6() bool

IsIPv6 returns true if the IP address in the given L3n4Addr is IPv6 or not.

func (*L3n4Addr) String

func (a *L3n4Addr) String() string

String returns the L3n4Addr in the "IPv4:Port[/Scope]" format for IPv4 and "[IPv6]:Port[/Scope]" format for IPv6.

func (*L3n4Addr) StringID

func (a *L3n4Addr) StringID() string

StringID returns the L3n4Addr as string to be used for unique identification

func (*L3n4Addr) StringWithProtocol

func (a *L3n4Addr) StringWithProtocol() string

StringWithProtocol returns the L3n4Addr in the "IPv4:Port/Protocol[/Scope]" format for IPv4 and "[IPv6]:Port/Protocol[/Scope]" format for IPv6.

type L3n4AddrID

type L3n4AddrID struct {
	L3n4Addr
	ID ID
}

L3n4AddrID is used to store, as an unique L3+L4 plus the assigned ID, in the KVStore.

+deepequal-gen=true +deepequal-gen:private-method=true

func NewL3n4AddrID

func NewL3n4AddrID(protocol L4Type, addrCluster cmtypes.AddrCluster, portNumber uint16, scope uint8, id ID) *L3n4AddrID

NewL3n4AddrID creates a new L3n4AddrID.

func (*L3n4AddrID) DeepCopy

func (in *L3n4AddrID) DeepCopy() *L3n4AddrID

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L3n4AddrID.

func (*L3n4AddrID) DeepCopyInto

func (in *L3n4AddrID) DeepCopyInto(out *L3n4AddrID)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*L3n4AddrID) DeepEqual

func (l *L3n4AddrID) DeepEqual(o *L3n4AddrID) bool

DeepEqual returns true if both the receiver and 'o' are deeply equal.

func (*L3n4AddrID) IsIPv6

func (l *L3n4AddrID) IsIPv6() bool

IsIPv6 returns true if the IP address in L3n4Addr's L3n4AddrID is IPv6 or not.

type L4Addr

type L4Addr struct {
	Protocol L4Type
	Port     uint16
}

L4Addr is an abstraction for the backend port with a L4Type, usually tcp or udp, and the Port number.

+deepequal-gen=true +deepequal-gen:private-method=true

func NewL4Addr

func NewL4Addr(protocol L4Type, number uint16) *L4Addr

NewL4Addr creates a new L4Addr.

func (*L4Addr) DeepCopy

func (in *L4Addr) DeepCopy() *L4Addr

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L4Addr.

func (*L4Addr) DeepCopyInto

func (in *L4Addr) DeepCopyInto(out *L4Addr)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*L4Addr) DeepEqual

func (l *L4Addr) DeepEqual(o *L4Addr) bool

DeepEqual returns true if both the receiver and 'o' are deeply equal.

type L4Type

type L4Type = string

L4Type name.

func NewL4Type

func NewL4Type(name string) (L4Type, error)

type Preferred

type Preferred bool

Preferred indicates if this backend is preferred to be load balanced.

type SVC

type SVC struct {
	Frontend                  L3n4AddrID       // SVC frontend addr and an allocated ID
	Backends                  []*Backend       // List of service backends
	Type                      SVCType          // Service type
	ExtTrafficPolicy          SVCTrafficPolicy // Service external traffic policy
	IntTrafficPolicy          SVCTrafficPolicy // Service internal traffic policy
	NatPolicy                 SVCNatPolicy     // Service NAT 46/64 policy
	SessionAffinity           bool
	SessionAffinityTimeoutSec uint32
	HealthCheckNodePort       uint16      // Service health check node port
	Name                      ServiceName // Fully qualified service name
	LoadBalancerSourceRanges  []*cidr.CIDR
	L7LBProxyPort             uint16   // Non-zero for L7 LB services
	L7LBFrontendPorts         []string // Non-zero for L7 LB frontend service ports
	LoopbackHostport          bool
}

SVC is a structure for storing service details.

func (*SVC) DeepCopy

func (in *SVC) DeepCopy() *SVC

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SVC.

func (*SVC) DeepCopyInto

func (in *SVC) DeepCopyInto(out *SVC)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*SVC) GetModel

func (s *SVC) GetModel() *models.Service

type SVCNatPolicy

type SVCNatPolicy string

SVCNatPolicy defines whether we need NAT46/64 translation for backends

type SVCTrafficPolicy

type SVCTrafficPolicy string

SVCTrafficPolicy defines which backends are chosen

type SVCType

type SVCType string

SVCType is a type of a service.

type ServiceFlags

type ServiceFlags uint16

ServiceFlags is the datapath representation of the service flags that can be used (lb{4,6}_service.flags)

func NewSvcFlag

func NewSvcFlag(p *SvcFlagParam) ServiceFlags

NewSvcFlag creates service flag

func (ServiceFlags) SVCExtTrafficPolicy

func (s ServiceFlags) SVCExtTrafficPolicy() SVCTrafficPolicy

SVCExtTrafficPolicy returns a service traffic policy from the flags

func (ServiceFlags) SVCIntTrafficPolicy

func (s ServiceFlags) SVCIntTrafficPolicy() SVCTrafficPolicy

SVCIntTrafficPolicy returns a service traffic policy from the flags

func (ServiceFlags) SVCNatPolicy

func (s ServiceFlags) SVCNatPolicy(fe L3n4Addr) SVCNatPolicy

SVCNatPolicy returns a service NAT policy from the flags

func (ServiceFlags) SVCType

func (s ServiceFlags) SVCType() SVCType

SVCType returns a service type from the flags

func (ServiceFlags) String

func (s ServiceFlags) String() string

String returns the string implementation of ServiceFlags.

func (ServiceFlags) UInt16

func (s ServiceFlags) UInt16() uint16

UInt8 returns the UInt16 representation of the ServiceFlags.

type ServiceID

type ServiceID uint16

ServiceID is the service's ID.

type ServiceName

type ServiceName struct {
	Namespace string
	Name      string
}

ServiceName represents the fully-qualified reference to the service by name, including both the namespace and name of the service.

func (*ServiceName) DeepCopy

func (in *ServiceName) DeepCopy() *ServiceName

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceName.

func (*ServiceName) DeepCopyInto

func (in *ServiceName) DeepCopyInto(out *ServiceName)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (ServiceName) String

func (n ServiceName) String() string

type SvcFlagParam

type SvcFlagParam struct {
	SvcType          SVCType
	SvcNatPolicy     SVCNatPolicy
	SvcExtLocal      bool
	SvcIntLocal      bool
	SessionAffinity  bool
	IsRoutable       bool
	CheckSourceRange bool
	L7LoadBalancer   bool
	LoopbackHostport bool
}

func (*SvcFlagParam) DeepCopy

func (in *SvcFlagParam) DeepCopy() *SvcFlagParam

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SvcFlagParam.

func (*SvcFlagParam) DeepCopyInto

func (in *SvcFlagParam) DeepCopyInto(out *SvcFlagParam)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Jump to

Keyboard shortcuts

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