Documentation
¶
Overview ¶
Package experimental contains a new experimental load-balancer control-plane based on StateDB. It aims to simplify the control-plane down to fewer layers and open up the ability to modify and observe frontends and backends for variaty of use-cases without the need to special-case them.
Index ¶
- Constants
- Variables
- func FastCheckEmptyTablesAndState(db *statedb.DB, writer *Writer, bo *BPFOps) bool
- func FastCheckTables(db *statedb.DB, writer *Writer, expectedFrontends int, ...) (reconciled bool, nextRevision statedb.Revision)
- func NewBackendsTable(cfg Config, db *statedb.DB) (statedb.RWTable[*Backend], error)
- func NewFrontendsTable(cfg Config, db *statedb.DB) (statedb.RWTable[*Frontend], error)
- func NewServicesTable(cfg Config, db *statedb.DB) (statedb.RWTable[*Service], error)
- type BPFLBMaps
- func (r *BPFLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
- func (r *BPFLBMaps) DeleteBackend(key lbmap.BackendKey) error
- func (r *BPFLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
- func (r *BPFLBMaps) DeleteRevNat(key lbmap.RevNatKey) error
- func (r *BPFLBMaps) DeleteService(key lbmap.ServiceKey) error
- func (r *BPFLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
- func (r *BPFLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
- func (r *BPFLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
- func (r *BPFLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, ...)) error
- func (r *BPFLBMaps) DumpRevNat(cb func(lbmap.RevNatKey, lbmap.RevNatValue)) error
- func (r *BPFLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
- func (r *BPFLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
- func (r *BPFLBMaps) IsEmpty() bool
- func (r *BPFLBMaps) Start(ctx cell.HookContext) (err error)
- func (r *BPFLBMaps) Stop(cell.HookContext) error
- func (r *BPFLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
- func (r *BPFLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
- func (r *BPFLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
- func (r *BPFLBMaps) UpdateRevNat(key lbmap.RevNatKey, value lbmap.RevNatValue) error
- func (r *BPFLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
- func (r *BPFLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
- type BPFOps
- type Backend
- func (be *Backend) Clone() *Backend
- func (be *Backend) GetInstance(name loadbalancer.ServiceName) *BackendParams
- func (be *Backend) GetInstanceForFrontend(fe *Frontend) *BackendParams
- func (be *Backend) GetInstanceFromSource(name loadbalancer.ServiceName, src source.Source) *BackendParams
- func (be *Backend) PreferredInstances() iter.Seq2[BackendInstanceKey, BackendParams]
- func (be *Backend) String() string
- func (be *Backend) TableHeader() []string
- func (be *Backend) TableRow() []string
- type BackendInstanceKey
- type BackendParams
- type Config
- type ExternalConfig
- type FakeLBMaps
- func (f *FakeLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
- func (f *FakeLBMaps) DeleteBackend(key lbmap.BackendKey) error
- func (f *FakeLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
- func (f *FakeLBMaps) DeleteRevNat(key lbmap.RevNatKey) error
- func (f *FakeLBMaps) DeleteService(key lbmap.ServiceKey) error
- func (f *FakeLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
- func (f *FakeLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
- func (f *FakeLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
- func (f *FakeLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, ...)) error
- func (f *FakeLBMaps) DumpRevNat(cb func(lbmap.RevNatKey, lbmap.RevNatValue)) error
- func (f *FakeLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
- func (f *FakeLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
- func (f *FakeLBMaps) IsEmpty() bool
- func (f *FakeLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
- func (f *FakeLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
- func (f *FakeLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
- func (f *FakeLBMaps) UpdateRevNat(key lbmap.RevNatKey, value lbmap.RevNatValue) error
- func (f *FakeLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
- func (f *FakeLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
- type FaultyLBMaps
- func (f *FaultyLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
- func (f *FaultyLBMaps) DeleteBackend(key lbmap.BackendKey) error
- func (f *FaultyLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
- func (f *FaultyLBMaps) DeleteRevNat(key lbmap.RevNatKey) error
- func (f *FaultyLBMaps) DeleteService(key lbmap.ServiceKey) error
- func (f *FaultyLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
- func (f *FaultyLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
- func (f *FaultyLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
- func (f *FaultyLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, ...)) error
- func (f *FaultyLBMaps) DumpRevNat(cb func(lbmap.RevNatKey, lbmap.RevNatValue)) error
- func (f *FaultyLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
- func (f *FaultyLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
- func (f *FaultyLBMaps) IsEmpty() bool
- func (f *FaultyLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
- func (f *FaultyLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
- func (f *FaultyLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
- func (f *FaultyLBMaps) UpdateRevNat(key lbmap.RevNatKey, value lbmap.RevNatValue) error
- func (f *FaultyLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
- func (f *FaultyLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
- type Frontend
- type FrontendParams
- type HaveNetNSCookieSupport
- type LBMaps
- type LBMapsConfig
- type MapDump
- type ProxyRedirect
- type Service
- type ServiceHook
- type StreamsOut
- type TestConfig
- type WriteTxn
- type Writer
- func (w *Writer) Backends() statedb.Table[*Backend]
- func (w *Writer) DebugDump(txn statedb.ReadTxn, to io.Writer)
- func (w *Writer) DeleteBackendsBySource(txn WriteTxn, src source.Source) error
- func (w *Writer) DeleteBackendsOfService(txn WriteTxn, name loadbalancer.ServiceName, src source.Source) error
- func (w *Writer) DeleteServiceAndFrontends(txn WriteTxn, name loadbalancer.ServiceName) error
- func (w *Writer) DeleteServicesBySource(txn WriteTxn, source source.Source) error
- func (w *Writer) Frontends() statedb.Table[*Frontend]
- func (w *Writer) IsEnabled() bool
- func (w *Writer) ReadTxn() statedb.ReadTxn
- func (w *Writer) RefreshFrontendByAddress(txn WriteTxn, addr loadbalancer.L3n4Addr) error
- func (w *Writer) RefreshFrontends(txn WriteTxn, name loadbalancer.ServiceName) error
- func (w *Writer) RegisterInitializer(name string) (complete func(WriteTxn))
- func (w *Writer) ReleaseBackend(txn WriteTxn, name loadbalancer.ServiceName, addr loadbalancer.L3n4Addr) error
- func (w *Writer) ReleaseBackendsForService(txn WriteTxn, name loadbalancer.ServiceName) error
- func (w *Writer) ReleaseBackendsFromSource(txn WriteTxn, name loadbalancer.ServiceName, source source.Source) error
- func (w *Writer) Services() statedb.Table[*Service]
- func (w *Writer) SetBackends(txn WriteTxn, name loadbalancer.ServiceName, source source.Source, ...) error
- func (w *Writer) SetRedirectToByName(txn WriteTxn, name loadbalancer.ServiceName, to *loadbalancer.ServiceName)
- func (w *Writer) UpsertBackends(txn WriteTxn, serviceName loadbalancer.ServiceName, source source.Source, ...) error
- func (w *Writer) UpsertFrontend(txn WriteTxn, params FrontendParams) (old *Frontend, err error)
- func (w *Writer) UpsertService(txn WriteTxn, svc *Service) (old *Service, err error)
- func (w *Writer) UpsertServiceAndFrontends(txn WriteTxn, svc *Service, fes ...FrontendParams) error
- func (w *Writer) WriteTxn(extraTables ...statedb.TableMeta) WriteTxn
Constants ¶
const (
BackendTableName = "backends"
)
const (
FrontendTableName = "frontends"
)
const (
ServiceTableName = "services"
)
Variables ¶
var ( BackendByAddress = backendAddrIndex.Query BackendByServiceName = backendServiceIndex.Query )
var ( // ErrServiceNotFound occurs when a frontend is being upserted that refers to // a non-existing service. ErrServiceNotFound = errors.New("service not found") // ErrFrontendConflict occurs when a frontend is being upserted but it already // exists and is owned by a different service. ErrFrontendConflict = errors.New("frontend already owned by another service") )
var ( FrontendByAddress = frontendAddressIndex.Query FrontendByServiceName = frontendServiceIndex.Query )
var Cell = cell.Module( "loadbalancer-experimental", "Experimental load-balancing control-plane", cell.Config(DefaultConfig), cell.ProvidePrivate(newExternalConfig), TablesCell, ReflectorCell, cell.ProvidePrivate(resourcesToStreams), ReconcilerCell, cell.ProvidePrivate(newLBMaps), cell.Provide(scriptCommands), healthServerCell, cell.Invoke(registerNodePortAddressReconciler), cell.Provide(newAdapters), cell.DecorateAll(decorateAdapters), )
var DefaultConfig = Config{ EnableExperimentalLB: false, RetryBackoffMin: 50 * time.Millisecond, RetryBackoffMax: time.Minute, }
var ReconcilerCell = cell.Module( "reconciler", "Reconciles load-balancing state with BPF maps", cell.Provide( newBPFOps, newBPFReconciler, ), cell.Invoke( func(reconciler.Reconciler[*Frontend]) {}, ), )
ReconcilerCell reconciles the load-balancing state with the BPF maps.
var ReflectorCell = cell.Module( "reflector", "Reflects load-balancing state from Kubernetes", cell.Invoke(registerK8sReflector), cell.Provide(netnsCookieSupportFunc), )
ReflectorCell reflects Kubernetes Service and EndpointSlice objects to the load-balancing tables.
Note that this implementation uses Resource[*Service] and Resource[*Endpoints], which is not the desired end-game as we'll hold onto the same data multiple times. We should instead have a reflector that is built directly on the client-go reflector (k8s.RegisterReflector) and not populate an intermediate cache.Store. But as we're still experimenting it's easier to build on what already exists.
var (
ServiceByName = serviceNameIndex.Query
)
var TablesCell = cell.Module( "tables", "Experimental load-balancing control-plane", cell.ProvidePrivate( NewServicesTable, NewFrontendsTable, NewBackendsTable, ), cell.Provide( NewWriter, toReadOnlyTable[*Service], toReadOnlyTable[*Frontend], toReadOnlyTable[*Backend], ), )
TablesCell provides the Writer API for configuring load-balancing and the Table[*Service], Table[*Frontend] and Table[*Backend] for read-only access to load-balancing state.
Functions ¶
func FastCheckTables ¶
func NewBackendsTable ¶
func NewFrontendsTable ¶
Types ¶
type BPFLBMaps ¶
type BPFLBMaps struct { // Pinned if true will pin the maps to a file. Tests may turn this off. Pinned bool Log *slog.Logger Cfg ExternalConfig MaglevCfg maglev.Config // contains filtered or unexported fields }
func (*BPFLBMaps) DeleteAffinityMatch ¶
func (r *BPFLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
DeleteAffinityMatch implements lbmaps.
func (*BPFLBMaps) DeleteBackend ¶
func (r *BPFLBMaps) DeleteBackend(key lbmap.BackendKey) error
DeleteBackend implements lbmaps.
func (*BPFLBMaps) DeleteMaglev ¶
func (r *BPFLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
DeleteMaglev implements lbmaps.
func (*BPFLBMaps) DeleteRevNat ¶
DeleteRevNat implements lbmaps.
func (*BPFLBMaps) DeleteService ¶
func (r *BPFLBMaps) DeleteService(key lbmap.ServiceKey) error
DeleteService implements lbmaps.
func (*BPFLBMaps) DeleteSourceRange ¶
func (r *BPFLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
DeleteSourceRange implements lbmaps.
func (*BPFLBMaps) DumpAffinityMatch ¶
func (r *BPFLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
DumpAffinityMatch implements lbmaps.
func (*BPFLBMaps) DumpBackend ¶
func (r *BPFLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
DumpBackend implements lbmaps.
func (*BPFLBMaps) DumpMaglev ¶
func (r *BPFLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, *lbmap.MaglevInnerVal, bool)) error
func (*BPFLBMaps) DumpRevNat ¶
DumpRevNat implements lbmaps.
func (*BPFLBMaps) DumpService ¶
func (r *BPFLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
DumpService implements lbmaps.
func (*BPFLBMaps) DumpSourceRange ¶
func (r *BPFLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
DumpSourceRange implements lbmaps.
func (*BPFLBMaps) Start ¶
func (r *BPFLBMaps) Start(ctx cell.HookContext) (err error)
Start implements cell.HookInterface.
func (*BPFLBMaps) Stop ¶
func (r *BPFLBMaps) Stop(cell.HookContext) error
Stop implements cell.HookInterface.
func (*BPFLBMaps) UpdateAffinityMatch ¶
func (r *BPFLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
UpdateAffinityMatch implements lbmaps.
func (*BPFLBMaps) UpdateBackend ¶
func (r *BPFLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
UpdateBackend implements lbmaps.
func (*BPFLBMaps) UpdateMaglev ¶
func (r *BPFLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
UpdateMaglev implements lbmaps.
func (*BPFLBMaps) UpdateRevNat ¶
UpdateRevNat4 implements lbmaps.
func (*BPFLBMaps) UpdateService ¶
func (r *BPFLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
UpdateService implements lbmaps.
func (*BPFLBMaps) UpdateSourceRange ¶
func (r *BPFLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
UpdateSourceRange implements lbmaps.
type BPFOps ¶
type BPFOps struct { LBMaps LBMaps // contains filtered or unexported fields }
type Backend ¶
type Backend struct { loadbalancer.L3n4Addr // Instances of this backend. A backend is always linked to a specific // service and the instances may call the backend by different name // (PortName) or they may come from differents sources. // Instances may contain multiple [BackendInstance]s per service // coming from different sources. The version from the source with the // highest priority (smallest uint8) is used. This is needed for smooth // transitions when ownership of endpoints is passed between upstream // data sources. Instances part.Map[BackendInstanceKey, BackendParams] }
Backend is a composite of the per-service backend instances that share the same IP address and port.
func (*Backend) GetInstance ¶
func (be *Backend) GetInstance(name loadbalancer.ServiceName) *BackendParams
func (*Backend) GetInstanceForFrontend ¶
func (be *Backend) GetInstanceForFrontend(fe *Frontend) *BackendParams
func (*Backend) GetInstanceFromSource ¶
func (be *Backend) GetInstanceFromSource(name loadbalancer.ServiceName, src source.Source) *BackendParams
func (*Backend) PreferredInstances ¶
func (be *Backend) PreferredInstances() iter.Seq2[BackendInstanceKey, BackendParams]
func (*Backend) TableHeader ¶
type BackendInstanceKey ¶
type BackendInstanceKey struct { ServiceName loadbalancer.ServiceName SourcePriority uint8 }
func (BackendInstanceKey) Key ¶
func (k BackendInstanceKey) Key() []byte
type BackendParams ¶
type BackendParams struct { loadbalancer.L3n4Addr // PortNames are the optional names for the ports. A frontend can specify which // backends to select by port name. PortNames []string // Weight of backend for load-balancing. Weight uint16 // Node hosting this backend. This is used to determine backends local to // a node. NodeName string // Zone where backend is located. ZoneID uint8 // Source of the backend. Source source.Source // State of the backend, e.g. active, quarantined or terminating. State loadbalancer.BackendState }
BackendParams defines the parameters of a backend for insertion into the backends table.
type Config ¶
type ExternalConfig ¶
type ExternalConfig struct { LBMapsConfig EnableIPv4, EnableIPv6 bool ExternalClusterIP bool EnableHealthCheckNodePort bool KubeProxyReplacement bool NodePortMin, NodePortMax uint16 NodePortAlg string LoadBalancerAlgorithmAnnotation bool }
ExternalConfig are configuration options derived from external sources such as DaemonConfig. This avoids direct access of larger configuration structs.
type FakeLBMaps ¶
type FakeLBMaps struct {
// contains filtered or unexported fields
}
func (*FakeLBMaps) DeleteAffinityMatch ¶
func (f *FakeLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
DeleteAffinityMatch implements lbmaps.
func (*FakeLBMaps) DeleteBackend ¶
func (f *FakeLBMaps) DeleteBackend(key lbmap.BackendKey) error
DeleteBackend implements lbmaps.
func (*FakeLBMaps) DeleteMaglev ¶
func (f *FakeLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
DeleteMaglev implements lbmaps.
func (*FakeLBMaps) DeleteRevNat ¶
func (f *FakeLBMaps) DeleteRevNat(key lbmap.RevNatKey) error
DeleteRevNat implements lbmaps.
func (*FakeLBMaps) DeleteService ¶
func (f *FakeLBMaps) DeleteService(key lbmap.ServiceKey) error
DeleteService implements lbmaps.
func (*FakeLBMaps) DeleteSourceRange ¶
func (f *FakeLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
DeleteSourceRange implements lbmaps.
func (*FakeLBMaps) DumpAffinityMatch ¶
func (f *FakeLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
DumpAffinityMatch implements lbmaps.
func (*FakeLBMaps) DumpBackend ¶
func (f *FakeLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
DumpBackend implements lbmaps.
func (*FakeLBMaps) DumpMaglev ¶
func (f *FakeLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, *lbmap.MaglevInnerVal, bool)) error
func (*FakeLBMaps) DumpRevNat ¶
func (f *FakeLBMaps) DumpRevNat(cb func(lbmap.RevNatKey, lbmap.RevNatValue)) error
DumpRevNat implements lbmaps.
func (*FakeLBMaps) DumpService ¶
func (f *FakeLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
DumpService implements lbmaps.
func (*FakeLBMaps) DumpSourceRange ¶
func (f *FakeLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
DumpSourceRange implements lbmaps.
func (*FakeLBMaps) UpdateAffinityMatch ¶
func (f *FakeLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
UpdateAffinityMatch implements lbmaps.
func (*FakeLBMaps) UpdateBackend ¶
func (f *FakeLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
UpdateBackend implements lbmaps.
func (*FakeLBMaps) UpdateMaglev ¶
func (f *FakeLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
UpdateMaglev implements lbmaps.
func (*FakeLBMaps) UpdateRevNat ¶
func (f *FakeLBMaps) UpdateRevNat(key lbmap.RevNatKey, value lbmap.RevNatValue) error
UpdateRevNat implements lbmaps.
func (*FakeLBMaps) UpdateService ¶
func (f *FakeLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
UpdateService implements lbmaps.
func (*FakeLBMaps) UpdateSourceRange ¶
func (f *FakeLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
UpdateSourceRange implements lbmaps.
type FaultyLBMaps ¶
type FaultyLBMaps struct {
// contains filtered or unexported fields
}
func (*FaultyLBMaps) DeleteAffinityMatch ¶
func (f *FaultyLBMaps) DeleteAffinityMatch(key *lbmap.AffinityMatchKey) error
DeleteAffinityMatch implements lbmaps.
func (*FaultyLBMaps) DeleteBackend ¶
func (f *FaultyLBMaps) DeleteBackend(key lbmap.BackendKey) error
DeleteBackend implements lbmaps.
func (*FaultyLBMaps) DeleteMaglev ¶
func (f *FaultyLBMaps) DeleteMaglev(key lbmap.MaglevOuterKey, ipv6 bool) error
DeleteMaglev implements lbmaps.
func (*FaultyLBMaps) DeleteRevNat ¶
func (f *FaultyLBMaps) DeleteRevNat(key lbmap.RevNatKey) error
DeleteRevNat implements lbmaps.
func (*FaultyLBMaps) DeleteService ¶
func (f *FaultyLBMaps) DeleteService(key lbmap.ServiceKey) error
DeleteService implements lbmaps.
func (*FaultyLBMaps) DeleteSourceRange ¶
func (f *FaultyLBMaps) DeleteSourceRange(key lbmap.SourceRangeKey) error
DeleteSourceRange implements lbmaps.
func (*FaultyLBMaps) DumpAffinityMatch ¶
func (f *FaultyLBMaps) DumpAffinityMatch(cb func(*lbmap.AffinityMatchKey, *lbmap.AffinityMatchValue)) error
DumpAffinityMatch implements lbmaps.
func (*FaultyLBMaps) DumpBackend ¶
func (f *FaultyLBMaps) DumpBackend(cb func(lbmap.BackendKey, lbmap.BackendValue)) error
DumpBackend implements lbmaps.
func (*FaultyLBMaps) DumpMaglev ¶
func (f *FaultyLBMaps) DumpMaglev(cb func(lbmap.MaglevOuterKey, lbmap.MaglevOuterVal, lbmap.MaglevInnerKey, *lbmap.MaglevInnerVal, bool)) error
DumpMaglev implements lbmaps.
func (*FaultyLBMaps) DumpRevNat ¶
func (f *FaultyLBMaps) DumpRevNat(cb func(lbmap.RevNatKey, lbmap.RevNatValue)) error
DumpRevNat implements lbmaps.
func (*FaultyLBMaps) DumpService ¶
func (f *FaultyLBMaps) DumpService(cb func(lbmap.ServiceKey, lbmap.ServiceValue)) error
DumpService implements lbmaps.
func (*FaultyLBMaps) DumpSourceRange ¶
func (f *FaultyLBMaps) DumpSourceRange(cb func(lbmap.SourceRangeKey, *lbmap.SourceRangeValue)) error
DumpSourceRange implements lbmaps.
func (*FaultyLBMaps) UpdateAffinityMatch ¶
func (f *FaultyLBMaps) UpdateAffinityMatch(key *lbmap.AffinityMatchKey, value *lbmap.AffinityMatchValue) error
UpdateAffinityMatch implements lbmaps.
func (*FaultyLBMaps) UpdateBackend ¶
func (f *FaultyLBMaps) UpdateBackend(key lbmap.BackendKey, value lbmap.BackendValue) error
UpdateBackend implements lbmaps.
func (*FaultyLBMaps) UpdateMaglev ¶
func (f *FaultyLBMaps) UpdateMaglev(key lbmap.MaglevOuterKey, backendIDs []loadbalancer.BackendID, ipv6 bool) error
UpdateMaglev implements lbmaps.
func (*FaultyLBMaps) UpdateRevNat ¶
func (f *FaultyLBMaps) UpdateRevNat(key lbmap.RevNatKey, value lbmap.RevNatValue) error
UpdateRevNat implements lbmaps.
func (*FaultyLBMaps) UpdateService ¶
func (f *FaultyLBMaps) UpdateService(key lbmap.ServiceKey, value lbmap.ServiceValue) error
UpdateService implements lbmaps.
func (*FaultyLBMaps) UpdateSourceRange ¶
func (f *FaultyLBMaps) UpdateSourceRange(key lbmap.SourceRangeKey, value *lbmap.SourceRangeValue) error
UpdateSourceRange implements lbmaps.
type Frontend ¶
type Frontend struct { FrontendParams // Status is the reconciliation status for this frontend and // reflects whether or not the frontend and the associated backends // have been reconciled with the BPF maps. // Managed by [Writer]. Status reconciler.Status // Backends associated with the frontend. Backends backendsSeq2 // ID is the identifier allocated to this frontend. Used as the key // in the services BPF map. This field is populated by the reconciler // and is initially set to zero. It can be considered valid only when // [Status] is set to done. ID loadbalancer.ServiceID // RedirectTo if set selects the backends from this service name instead // of that of [FrontendParams.ServiceName]. This is used to implement the // local redirect policies where traffic going to a specific service/frontend // is redirected to a local pod instead. RedirectTo *loadbalancer.ServiceName // contains filtered or unexported fields }
func (*Frontend) TableHeader ¶
type FrontendParams ¶
type FrontendParams struct { // Frontend address and port Address loadbalancer.L3n4Addr // Service type (e.g. ClusterIP, NodePort, ...) Type loadbalancer.SVCType // Name of the associated service ServiceName loadbalancer.ServiceName // PortName if set will select only backends with matching // port name. PortName loadbalancer.FEPortName // ServicePort is the associated "ClusterIP" port of this frontend. // Same as [Address.L4Addr.Port] except when [Type] NodePort or // LoadBalancer. This is used to match frontends with the [Ports] of // [Service.ProxyRedirect]. ServicePort uint16 }
FrontendParams defines the static parameters of a frontend. This is separate from Frontend to clearly separate which fields can be manipulated and which are internally managed by Writer.
type HaveNetNSCookieSupport ¶
type HaveNetNSCookieSupport func() bool
type LBMaps ¶
type LBMaps interface { IsEmpty() bool // contains filtered or unexported methods }
LBMaps defines the map operations performed by the reconciliation. Depending on this interface instead of on the underlying maps allows testing the implementation with a fake map or injected errors.
func NewFakeLBMaps ¶
func NewFakeLBMaps() LBMaps
type LBMapsConfig ¶
type LBMapsConfig struct { MaxSockRevNatMapEntries int ServiceMapMaxEntries, BackendMapMaxEntries, RevNatMapMaxEntries int AffinityMapMaxEntries int SourceRangeMapMaxEntries int MaglevMapMaxEntries int }
LBMapsConfig specifies the configuration for the load-balancing BPF maps.
type MapDump ¶
type MapDump = string
MapDump is a dump of a BPF map. These are generated by the dump() method, which solely defines the format.
type ProxyRedirect ¶
type ProxyRedirect struct { ProxyPort uint16 // Ports if non-empty will only redirect a frontend with a matching port. Ports []uint16 }
func (*ProxyRedirect) Equal ¶
func (pr *ProxyRedirect) Equal(other *ProxyRedirect) bool
func (*ProxyRedirect) Redirects ¶
func (pr *ProxyRedirect) Redirects(port uint16) bool
func (*ProxyRedirect) String ¶
func (pr *ProxyRedirect) String() string
type Service ¶
type Service struct { // Name is the fully qualified service name, e.g. (<cluster>/)<namespace>/<name>. Name loadbalancer.ServiceName // Source is the data source from which this service was ingested from. Source source.Source // Labels associated with the service. Labels labels.Labels // Annotations associated with this service. Annotations map[string]string // Selector specifies which pods should be associated with this service. If // this is empty the backends associated to this service are managed externally // and not by Kubernetes. Selector map[string]string // NatPolicy defines whether we need NAT46/64 translation for backends. NatPolicy loadbalancer.SVCNatPolicy // ExtTrafficPolicy controls how backends are selected for North-South traffic. // If set to "Local", only node-local backends are chosen. ExtTrafficPolicy loadbalancer.SVCTrafficPolicy // IntTrafficPolicy controls how backends are selected for East-West traffic. // If set to "Local", only node-local backends are chosen. IntTrafficPolicy loadbalancer.SVCTrafficPolicy SessionAffinity bool SessionAffinityTimeout time.Duration // ProxyRedirect if non-nil redirects the traffic going to the frontends // towards a locally running proxy. ProxyRedirect *ProxyRedirect // HealthCheckNodePort defines on which port the node runs a HTTP health // check server which may be used by external loadbalancers to determine // if a node has local backends. This will only have effect if both // LoadBalancerIPs is not empty and ExtTrafficPolicy is SVCTrafficPolicyLocal. HealthCheckNodePort uint16 // LoopbackHostPort defines that HostPort frontends for this service should // only be exposed internally to the node. LoopbackHostPort bool // SourceRanges if non-empty will restrict access to the service to the specified // client addresses. SourceRanges []cidr.CIDR // PortNames maps a port name to a port number. PortNames map[string]uint16 // Properties are additional untyped properties that can carry feature // specific metadata about the service. Properties part.Map[string, any] }
Service defines the common properties for a load-balancing service. Associated with a service are a set of frontends that receive the traffic, and a set of backends to which the traffic is directed. A single frontend can map to a partial subset of backends depending on its properties.
func (*Service) Clone ¶
Clone returns a shallow clone of the service, e.g. for updating a service with UpsertService. Fields that are references (e.g. Labels or Annotations) must be further cloned if mutated.
func (*Service) GetLBAlgorithmAnnotation ¶
func (svc *Service) GetLBAlgorithmAnnotation() loadbalancer.SVCLoadBalancingAlgorithm
func (*Service) TableHeader ¶
type ServiceHook ¶
ServiceHook is a function invoked when a frontend has been updated. A hook can manipulate the frontend before the changes are seen by other components.
The main use-case for a hook is to set e.g. L7 proxy port before the frontend is reconciled and thus avoid unnecessary work.
For consistency the hook should only access StateDB tables via the provided read transaction.
type StreamsOut ¶
type StreamsOut struct { cell.Out ServicesStream stream.Observable[resource.Event[*slim_corev1.Service]] EndpointsStream stream.Observable[resource.Event[*k8s.Endpoints]] }
type TestConfig ¶
type TestConfig struct { TestFaultProbability float32 `mapstructure:"lb-test-fault-probability"` // NodePortAlg mirrors option.Config.NodePortAlg. This can be removed when the NodePort config // flags move away from option.DaemonConfig and can thus be set directly. NodePortAlg string `mapstructure:"node-port-algorithm"` // EnableHealthCheckNodePort is defined here to allow script tests to enable this. // Can be removed once this option moves out from DaemonConfig into [Config]. EnableHealthCheckNodePort bool `mapstructure:"enable-health-check-nodeport"` // LoadBalancerAlgorithmAnnotation mirrors option.Config.LoadBalancerAlgorithmAnnotation. LoadBalancerAlgorithmAnnotation bool `mapstructure:"bpf-lb-algorithm-annotation"` // ExternalClusterIP mirrors option.Config.ExternalClusterIP ExternalClusterIP bool `mapstructure:"bpf-lb-external-clusterip"` }
TestConfig are the configuration options for testing. Only provided by tests and not present in the agent.
func (TestConfig) Flags ¶
func (def TestConfig) Flags(flags *pflag.FlagSet)
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides validated write access to the service load-balancing state.
func (*Writer) Backends ¶
Backends returns the backend table for reading. Convenience method for reducing dependencies.
func (*Writer) DeleteBackendsBySource ¶
func (*Writer) DeleteBackendsOfService ¶
func (w *Writer) DeleteBackendsOfService(txn WriteTxn, name loadbalancer.ServiceName, src source.Source) error
func (*Writer) DeleteServiceAndFrontends ¶
func (w *Writer) DeleteServiceAndFrontends(txn WriteTxn, name loadbalancer.ServiceName) error
func (*Writer) DeleteServicesBySource ¶
DeleteServicesBySource deletes all services from the specific source. This is used to implement "resynchronization", for example with K8s when the Watch() call fails and we need to start over with a List().
func (*Writer) Frontends ¶
Frontends returns the frontend table for reading. Convenience method for reducing dependencies.
func (*Writer) ReadTxn ¶
ReadTxn returns a StateDB read transaction. Convenience method to be used with the above table getters.
func (*Writer) RefreshFrontendByAddress ¶
func (w *Writer) RefreshFrontendByAddress(txn WriteTxn, addr loadbalancer.L3n4Addr) error
func (*Writer) RefreshFrontends ¶
func (w *Writer) RefreshFrontends(txn WriteTxn, name loadbalancer.ServiceName) error
func (*Writer) RegisterInitializer ¶
RegisterInitializer registers a component as an initializer to the load-balancing tables. This blocks pruning of data until this and all other registered initializers have called the returned 'complete' function.
func (*Writer) ReleaseBackend ¶
func (w *Writer) ReleaseBackend(txn WriteTxn, name loadbalancer.ServiceName, addr loadbalancer.L3n4Addr) error
func (*Writer) ReleaseBackendsForService ¶
func (w *Writer) ReleaseBackendsForService(txn WriteTxn, name loadbalancer.ServiceName) error
func (*Writer) ReleaseBackendsFromSource ¶
func (w *Writer) ReleaseBackendsFromSource(txn WriteTxn, name loadbalancer.ServiceName, source source.Source) error
func (*Writer) Services ¶
Services returns the service table for reading. Convenience method for reducing dependencies.
func (*Writer) SetBackends ¶
func (w *Writer) SetBackends(txn WriteTxn, name loadbalancer.ServiceName, source source.Source, bes ...BackendParams) error
SetBackends sets the backends associated with a service. Existing backends from this source that are associated with the service but are not given are released.
func (*Writer) SetRedirectToByName ¶
func (w *Writer) SetRedirectToByName(txn WriteTxn, name loadbalancer.ServiceName, to *loadbalancer.ServiceName)
func (*Writer) UpsertBackends ¶
func (w *Writer) UpsertBackends(txn WriteTxn, serviceName loadbalancer.ServiceName, source source.Source, bes ...BackendParams) error
UpsertBackends adds/updates backends for the given service.
func (*Writer) UpsertFrontend ¶
func (w *Writer) UpsertFrontend(txn WriteTxn, params FrontendParams) (old *Frontend, err error)
func (*Writer) UpsertService ¶
func (*Writer) UpsertServiceAndFrontends ¶
func (w *Writer) UpsertServiceAndFrontends(txn WriteTxn, svc *Service, fes ...FrontendParams) error
UpsertServiceAndFrontends upserts the service and updates the set of associated frontends. Any frontends that do not exist in the new set are deleted.