loadbalancer

package
Version: v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: Apache-2.0 Imports: 6 Imported by: 15

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")
)
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
)

Variables

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

Functions

func IsValidBackendState added in v1.12.0

func IsValidBackendState(state string) bool

func IsValidStateTransition added in v1.12.0

func IsValidStateTransition(old, new BackendState) bool

Types

type Backend added in v1.7.0

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
	// 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

	// RestoredFromDatapath indicates whether the backend was restored from BPF maps
	RestoredFromDatapath bool
}

Backend represents load balancer backend.

func NewBackend added in v1.7.0

func NewBackend(id BackendID, protocol L4Type, ip net.IP, portNumber uint16) *Backend

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

func NewBackendFromBackendModel added in v1.7.0

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

func NewBackendWithState added in v1.12.0

func NewBackendWithState(id BackendID, protocol L4Type, ip net.IP, portNumber uint16,
	state BackendState, restored bool) *Backend

NewBackendWithState creates the Backend struct instance from given params, and sets the restore state for the Backend.

func (*Backend) DeepCopy added in v1.7.0

func (in *Backend) DeepCopy() *Backend

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

func (*Backend) DeepCopyInto added in v1.7.0

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 added in v1.7.0

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

func (*Backend) String added in v1.7.0

func (b *Backend) String() string

type BackendID

type BackendID uint32

BackendID is the backend's ID.

type BackendState added in v1.12.0

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 added in v1.12.0

func GetBackendState(state string) (BackendState, error)

func GetBackendStateFromFlags added in v1.12.0

func GetBackendStateFromFlags(flags uint8) BackendState

func (BackendState) String added in v1.12.0

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

type BackendStateFlags added in v1.12.0

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 added in v1.12.0

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 {
	// +deepequal-gen=false
	IP net.IP
	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, that is, Scope{External,Internal}.

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

func NewL3n4Addr

func NewL3n4Addr(protocol L4Type, ip net.IP, 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 added in v1.7.0

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 added in v1.8.10

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 added in v1.7.0

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, ip net.IP, 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 added in v1.7.0

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 added in v1.8.10

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 added in v1.7.0

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 added in v1.8.10

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 added in v1.12.0

type Preferred bool

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

type SVC added in v1.7.0

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

SVC is a structure for storing service details.

func (*SVC) DeepCopy added in v1.7.0

func (in *SVC) DeepCopy() *SVC

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

func (*SVC) DeepCopyInto added in v1.7.0

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 added in v1.7.0

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

type SVCNatPolicy added in v1.12.0

type SVCNatPolicy string

SVCNatPolicy defines whether we need NAT46/64 translation for backends

type SVCTrafficPolicy added in v1.7.0

type SVCTrafficPolicy string

SVCTrafficPolicy defines which backends are chosen

type SVCType added in v1.7.0

type SVCType string

SVCType is a type of a service.

type ServiceFlags added in v1.7.0

type ServiceFlags uint16

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

func NewSvcFlag added in v1.8.3

func NewSvcFlag(p *SvcFlagParam) ServiceFlags

NewSvcFlag creates service flag

func (ServiceFlags) SVCNatPolicy added in v1.12.0

func (s ServiceFlags) SVCNatPolicy(fe L3n4Addr) SVCNatPolicy

SVCNatPolicy returns a service NAT policy from the flags

func (ServiceFlags) SVCTrafficPolicy added in v1.7.0

func (s ServiceFlags) SVCTrafficPolicy() SVCTrafficPolicy

SVCTrafficPolicy returns a service traffic policy from the flags

func (ServiceFlags) SVCType added in v1.7.0

func (s ServiceFlags) SVCType() SVCType

SVCType returns a service type from the flags

func (ServiceFlags) String added in v1.7.0

func (s ServiceFlags) String() string

String returns the string implementation of ServiceFlags.

func (ServiceFlags) UInt16 added in v1.9.0

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 SvcFlagParam added in v1.8.3

type SvcFlagParam struct {
	SvcType          SVCType
	SvcNatPolicy     SVCNatPolicy
	SvcLocal         bool
	SessionAffinity  bool
	IsRoutable       bool
	CheckSourceRange bool
	L7LoadBalancer   bool
}

func (*SvcFlagParam) DeepCopy added in v1.8.3

func (in *SvcFlagParam) DeepCopy() *SvcFlagParam

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

func (*SvcFlagParam) DeepCopyInto added in v1.8.3

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