Documentation ¶
Index ¶
- Constants
- Variables
- func AcquireBackendID(l3n4Addr loadbalancer.L3n4Addr) (loadbalancer.BackendID, error)
- func AcquireID(l3n4Addr loadbalancer.L3n4Addr, baseID uint32) (*loadbalancer.L3n4AddrID, error)
- func DeleteBackendID(id loadbalancer.BackendID)
- func DeleteID(id uint32) error
- func GetID(id uint32) (*loadbalancer.L3n4AddrID, error)
- func LookupBackendID(l3n4Addr loadbalancer.L3n4Addr) (loadbalancer.BackendID, error)
- func NewErrLocalRedirectServiceExists(frontend lb.L3n4AddrID, name lb.ServiceName) error
- func RestoreBackendID(l3n4Addr loadbalancer.L3n4Addr, id loadbalancer.BackendID) error
- func RestoreID(l3n4Addr loadbalancer.L3n4Addr, baseID uint32) (*loadbalancer.L3n4AddrID, error)
- type BackendSyncer
- type ErrLocalRedirectServiceExists
- type IDAllocator
- type L7LBInfo
- type L7LBResourceName
- type NodeMetaCollector
- type Service
- func (s *Service) DeleteService(frontend lb.L3n4Addr) (bool, error)
- func (s *Service) DeleteServiceByID(id lb.ServiceID) (bool, error)
- func (s *Service) DeregisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error
- func (s *Service) DeregisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName) error
- func (s *Service) GetCurrentTs() time.Time
- func (s *Service) GetDeepCopyServiceByFrontend(frontend lb.L3n4Addr) (*lb.SVC, bool)
- func (s *Service) GetDeepCopyServiceByID(id lb.ServiceID) (*lb.SVC, bool)
- func (s *Service) GetDeepCopyServices() []*lb.SVC
- func (s *Service) GetDeepCopyServicesByName(name, namespace string) (svcs []*lb.SVC)
- func (s *Service) GetLastUpdatedTs() time.Time
- func (s *Service) GetServiceNameByAddr(addr lb.L3n4Addr) (string, string, bool)
- func (s *Service) InitMaps(ipv6, ipv4, sockMaps, restore bool) error
- func (s *Service) RegisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error
- func (s *Service) RegisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName, proxyPort uint16) error
- func (s *Service) RestoreServices() error
- func (s *Service) SyncNodePortFrontends(addrs sets.Set[netip.Addr]) error
- func (s *Service) SyncWithK8sFinished(localOnly bool, localServices sets.Set[k8s.ServiceID]) (stale []k8s.ServiceID, err error)
- func (s *Service) UpdateBackendsState(backends []*lb.Backend) error
- func (s *Service) UpsertService(params *lb.SVC) (bool, lb.ID, error)
- type ServiceManager
Constants ¶
const ( // FirstFreeServiceID is the first ID for which the services should be assigned. FirstFreeServiceID = uint32(1) // MaxSetOfServiceID is maximum number of set of service IDs that can be stored // in the kvstore or the local ID allocator. MaxSetOfServiceID = uint32(0xFFFF) // FirstFreeBackendID is the first ID for which the backend should be assigned. // BPF datapath assumes that backend_id cannot be 0. FirstFreeBackendID = uint32(1) // MaxSetOfBackendID is maximum number of set of backendIDs IDs that can be // stored in the local ID allocator. MaxSetOfBackendID = uint32(0xFFFFFFFF) )
Variables ¶
var Cell = cell.Module( "service-manager", "Service Manager", cell.Provide(newServiceManager), cell.ProvidePrivate(func(sm ServiceManager) syncNodePort { return sm }), cell.Invoke(registerServiceReconciler), )
Cell provides access to the Service Manager.
Functions ¶
func AcquireBackendID ¶
func AcquireBackendID(l3n4Addr loadbalancer.L3n4Addr) (loadbalancer.BackendID, error)
AcquireBackendID acquires a new local ID for the given backend.
func AcquireID ¶
func AcquireID(l3n4Addr loadbalancer.L3n4Addr, baseID uint32) (*loadbalancer.L3n4AddrID, error)
AcquireID acquires a service ID
func DeleteBackendID ¶
func DeleteBackendID(id loadbalancer.BackendID)
DeleteBackendID releases the given backend ID. TODO(brb) maybe provide l3n4Addr as an arg for the extra safety.
func GetID ¶
func GetID(id uint32) (*loadbalancer.L3n4AddrID, error)
GetID returns the L3n4AddrID that belongs to the given id.
func LookupBackendID ¶
func LookupBackendID(l3n4Addr loadbalancer.L3n4Addr) (loadbalancer.BackendID, error)
LookupBackendID looks up already allocated backend ID for the given backend addr. If such cannot be found, returns an error.
func NewErrLocalRedirectServiceExists ¶
func NewErrLocalRedirectServiceExists(frontend lb.L3n4AddrID, name lb.ServiceName) error
NewErrLocalRedirectServiceExists returns a new ErrLocalRedirectServiceExists
func RestoreBackendID ¶
func RestoreBackendID(l3n4Addr loadbalancer.L3n4Addr, id loadbalancer.BackendID) error
RestoreBackendID tries to restore the given local ID for the given backend.
If ID cannot be restored (ID already taken), returns an error.
func RestoreID ¶
func RestoreID(l3n4Addr loadbalancer.L3n4Addr, baseID uint32) (*loadbalancer.L3n4AddrID, error)
RestoreID restores previously used service ID
Types ¶
type BackendSyncer ¶ added in v1.16.0
type BackendSyncer interface { // ProxyName returns a human readable name of the L7 Proxy that acts as // // L7 loadbalancer. ProxyName() string // Sync triggers the actual synchronization and passes the information // about the service that should be synchronized. Sync(svc *lb.SVC) error }
BackendSyncer performs a synchronization of service backends to an external loadbalancer (e.g. Envoy L7 Loadbalancer).
type ErrLocalRedirectServiceExists ¶
type ErrLocalRedirectServiceExists struct {
// contains filtered or unexported fields
}
ErrLocalRedirectServiceExists represents an error when a Local redirect service exists with the same Frontend.
func (ErrLocalRedirectServiceExists) Error ¶
func (e ErrLocalRedirectServiceExists) Error() string
func (*ErrLocalRedirectServiceExists) Is ¶
func (e *ErrLocalRedirectServiceExists) Is(target error) bool
type IDAllocator ¶
type IDAllocator struct { // Protects entitiesID, entities, nextID and maxID lock.RWMutex // contains filtered or unexported fields }
IDAllocator contains an internal state of the ID allocator.
func NewIDAllocator ¶
func NewIDAllocator(nextID uint32, maxID uint32) *IDAllocator
NewIDAllocator creates a new ID allocator instance.
type L7LBResourceName ¶ added in v1.16.0
type Service ¶
Service is a service handler. Its main responsibility is to reflect service-related changes into BPF maps used by datapath BPF programs. The changes can be triggered either by k8s_watcher or directly by API calls to the /services endpoint.
func NewService ¶
func NewService(monitorAgent monitorAgent.Agent, lbmap datapathTypes.LBMap, backendDiscoveryHandler datapathTypes.NodeNeighbors) *Service
NewService creates a new instance of the service handler.
func (*Service) DeleteService ¶
DeleteService removes the given service.
func (*Service) DeleteServiceByID ¶
DeleteServiceByID removes a service identified by the given ID.
func (*Service) DeregisterL7LBServiceBackendSync ¶ added in v1.16.0
func (s *Service) DeregisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error
func (*Service) DeregisterL7LBServiceRedirect ¶ added in v1.16.0
func (s *Service) DeregisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName) error
func (*Service) GetCurrentTs ¶
func (*Service) GetDeepCopyServiceByFrontend ¶
GetDeepCopyServiceByFrontend returns a deep-copy of the service that matches the Frontend address.
func (*Service) GetDeepCopyServiceByID ¶
GetDeepCopyServiceByID returns a deep-copy of a service identified with the given ID.
If a service cannot be found, returns false.
func (*Service) GetDeepCopyServices ¶
GetDeepCopyServices returns a deep-copy of all installed services.
func (*Service) GetDeepCopyServicesByName ¶
GetDeepCopyServicesByName returns a deep-copy all matching services.
func (*Service) GetLastUpdatedTs ¶
func (*Service) GetServiceNameByAddr ¶
GetServiceNameByAddr returns namespace and name of the service with a given L3n4Addr. The third return value is set to true if and only if the service is found in the map.
func (*Service) InitMaps ¶
InitMaps opens or creates BPF maps used by services.
If restore is set to false, entries of the maps are removed.
func (*Service) RegisterL7LBServiceBackendSync ¶
func (s *Service) RegisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error
RegisterL7LBServiceBackendSync registers a BackendSync to be informed when the backends of a Service change.
func (*Service) RegisterL7LBServiceRedirect ¶ added in v1.16.0
func (s *Service) RegisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName, proxyPort uint16) error
RegisterL7LBServiceRedirect makes the given service to be locally redirected to the given proxy port.
func (*Service) RestoreServices ¶
RestoreServices restores services from BPF maps.
It first restores all the service entries, followed by backend entries. In the process, it deletes any duplicate backend entries that were leaked, and are not referenced by any service entries.
The method should be called once before establishing a connectivity to kube-apiserver.
func (*Service) SyncNodePortFrontends ¶ added in v1.16.0
SyncNodePortFrontends updates all NodePort services with a new set of frontend IP addresses.
func (*Service) SyncWithK8sFinished ¶
func (s *Service) SyncWithK8sFinished(localOnly bool, localServices sets.Set[k8s.ServiceID]) (stale []k8s.ServiceID, err error)
SyncWithK8sFinished removes services which we haven't heard about during a sync period of cilium-agent's k8s service cache.
The removal is based on an assumption that during the sync period UpsertService() is going to be called for each alive service.
Additionally, it returns a list of services which are associated with stale backends, and which shall be refreshed. Stale services shall be refreshed regardless of whether an error is also returned or not.
The localOnly flag allows to perform a two pass removal, handling local services first, and processing global ones only after full synchronization with all remote clusters.
func (*Service) UpdateBackendsState ¶
UpdateBackendsState updates all the service(s) with the updated state of the given backends. It also persists the updated backend states to the BPF maps.
Backend state transitions are validated before processing.
In case of duplicated backends in the list, the state will be updated to the last duplicate entry.
type ServiceManager ¶ added in v1.15.0
type ServiceManager interface { // DeleteService removes the given service. DeleteService(frontend lb.L3n4Addr) (bool, error) // DeleteServiceByID removes a service identified by the given ID. DeleteServiceByID(id lb.ServiceID) (bool, error) // GetCurrentTs retrieves the current timestamp. GetCurrentTs() time.Time // GetDeepCopyServices returns a deep-copy of all installed services. GetDeepCopyServices() []*lb.SVC // GetDeepCopyServiceByFrontend returns a deep-copy of the service that matches the Frontend address. GetDeepCopyServiceByFrontend(frontend lb.L3n4Addr) (*lb.SVC, bool) // GetDeepCopyServiceByID returns a deep-copy of a service identified with the given ID. GetDeepCopyServiceByID(id lb.ServiceID) (*lb.SVC, bool) // GetLastUpdatedTs retrieves the last updated timestamp. GetLastUpdatedTs() time.Time // GetServiceNameByAddr looks up service by IP/port. Hubble uses this function // to annotate flows with service information. GetServiceNameByAddr(addr lb.L3n4Addr) (string, string, bool) // InitMaps opens or creates BPF maps used by services. InitMaps(ipv6, ipv4, sockMaps, restore bool) error // RegisterL7LBServiceRedirect makes the given service to be locally redirected to the given proxy port. RegisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName, proxyPort uint16) error // DeregisterL7LBServiceRedirect deregisters a Service from being redirected to a L7 LB. DeregisterL7LBServiceRedirect(serviceName lb.ServiceName, resourceName L7LBResourceName) error // RegisterL7LBServiceBackendSync registers a backend sync registration for the service. RegisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error // DeregisterL7LBServiceBackendSync deregisters a backend sync registration for the service. DeregisterL7LBServiceBackendSync(serviceName lb.ServiceName, backendSyncRegistration BackendSyncer) error // RestoreServices restores services from BPF maps. RestoreServices() error // SyncNodePortFrontends updates all NodePort service frontends with a new set of frontend // IP addresses. SyncNodePortFrontends(sets.Set[netip.Addr]) error // SyncWithK8sFinished removes services which we haven't heard about during // a sync period of cilium-agent's k8s service cache. SyncWithK8sFinished(localOnly bool, localServices sets.Set[k8s.ServiceID]) (stale []k8s.ServiceID, err error) // UpdateBackendsState updates all the service(s) with the updated state of // the given backends. It also persists the updated backend states to the BPF maps. UpdateBackendsState(backends []*lb.Backend) error // UpsertService inserts or updates the given service. UpsertService(*lb.SVC) (bool, lb.ID, error) }
ServiceManager provides an interface for service related operations. It is implemented by service handler which main responsibility is to reflect service-related changes into BPF maps used by datapath BPF programs.