Documentation
¶
Overview ¶
Package loadbalancer contains all logic related with the loadbalancer +groupName=pkg
Index ¶
- Constants
- Variables
- func IsValidBackendState(state string) bool
- func IsValidStateTransition(old, new BackendState) bool
- type Backend
- type BackendID
- type BackendState
- type BackendStateFlags
- type FEPortName
- type ID
- type L3n4Addr
- func (in *L3n4Addr) DeepCopy() *L3n4Addr
- func (in *L3n4Addr) DeepCopyInto(out *L3n4Addr)
- func (l *L3n4Addr) DeepEqual(o *L3n4Addr) bool
- func (a *L3n4Addr) GetModel() *models.FrontendAddress
- func (a L3n4Addr) Hash() string
- func (a *L3n4Addr) IsIPv6() bool
- func (a *L3n4Addr) String() string
- func (a *L3n4Addr) StringID() string
- func (a *L3n4Addr) StringWithProtocol() string
- type L3n4AddrID
- type L4Addr
- type L4Type
- type Preferred
- type SVC
- type SVCNatPolicy
- type SVCTrafficPolicy
- type SVCType
- type ServiceFlags
- type ServiceID
- type ServiceName
- type SvcFlagParam
Constants ¶
const ( SVCTypeNone = SVCType("NONE") SVCTypeHostPort = SVCType("HostPort") SVCTypeClusterIP = SVCType("ClusterIP") SVCTypeNodePort = SVCType("NodePort") SVCTypeExternalIPs = SVCType("ExternalIPs") SVCTypeLoadBalancer = SVCType("LoadBalancer") SVCTypeLocalRedirect = SVCType("LocalRedirect") )
const ( SVCTrafficPolicyNone = SVCTrafficPolicy("NONE") SVCTrafficPolicyCluster = SVCTrafficPolicy("Cluster") SVCTrafficPolicyLocal = SVCTrafficPolicy("Local") )
const ( SVCNatPolicyNone = SVCNatPolicy("NONE") SVCNatPolicyNat46 = SVCNatPolicy("Nat46") SVCNatPolicyNat64 = SVCNatPolicy("Nat64") )
const ( NONE = L4Type("NONE") // TCP type. TCP = L4Type("TCP") // UDP type. UDP = L4Type("UDP") // SCTP type. SCTP = L4Type("SCTP") )
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 )
const ( BackendStateActiveFlag = iota BackendStateTerminatingFlag BackendStateQuarantinedFlag BackendStateMaintenanceFlag )
const DefaultBackendWeight = 100
DefaultBackendWeight is used when backend weight is not set in ServiceSpec
Variables ¶
var ( // AllProtocols is the list of all supported L4 protocols AllProtocols = []L4Type{TCP, UDP, SCTP} )
Functions ¶
func IsValidBackendState ¶
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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Backend.
func (*Backend) DeepCopyInto ¶
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
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 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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L3n4Addr.
func (*L3n4Addr) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*L3n4Addr) GetModel ¶
func (a *L3n4Addr) GetModel() *models.FrontendAddress
func (L3n4Addr) Hash ¶
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 ¶
IsIPv6 returns true if the IP address in the given L3n4Addr is IPv6 or not.
func (*L3n4Addr) String ¶
String returns the L3n4Addr in the "IPv4:Port[/Scope]" format for IPv4 and "[IPv6]:Port[/Scope]" format for IPv6.
func (*L3n4Addr) StringID ¶
StringID returns the L3n4Addr as string to be used for unique identification
func (*L3n4Addr) StringWithProtocol ¶
StringWithProtocol returns the L3n4Addr in the "IPv4:Port/Protocol[/Scope]" format for IPv4 and "[IPv6]:Port/Protocol[/Scope]" format for IPv6.
type L3n4AddrID ¶
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 ¶
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 (*L4Addr) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new L4Addr.
func (*L4Addr) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
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 LoopbackHostport bool }
SVC is a structure for storing service details.
func (*SVC) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SVC.
func (*SVC) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
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 ServiceFlags ¶
type ServiceFlags uint16
ServiceFlags is the datapath representation of the service flags that can be used (lb{4,6}_service.flags)
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 ServiceName ¶
ServiceName represents the fully-qualified reference to the service by name, including both the namespace and name of the service (and optionally the cluster).
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.