speaker

package
v1.13.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Overview

Package speaker abstracts the BGP speaker controller from MetalLB. This package provides BGP announcements based on K8s object event handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShutDown = errors.New("cannot enqueue event, speaker is shutdown")
)

Functions

This section is empty.

Types

type CidrSlice

type CidrSlice []string

CidrSlice is a slice of Cidr strings with a method set for converting them to MetalLB advertisements.

func (CidrSlice) ToAdvertisements

func (cs CidrSlice) ToAdvertisements() []*metallbbgp.Advertisement

ToAdvertisements converts the CidrSlice into metallb Advertisements.

If a cidr cannot be parsed it is omitted from the array of Advertisements returned an an error is logged.

type MetalLBSpeaker

type MetalLBSpeaker struct {
	// Our speaker requeues our own event structures on failure.
	// Use a fence to avoid replaying stale events.
	fence.Fencer

	lock.Mutex
	// contains filtered or unexported fields
}

MetalLBSpeaker represents the BGP speaker. It integrates Cilium's K8s events with MetalLB's logic for making BGP announcements. It is responsible for announcing BGP messages containing a loadbalancer IP address to peers.

func New

func New(ctx context.Context, opts Opts) (*MetalLBSpeaker, error)

New creates a new MetalLB BGP speaker controller. Options are provided to specify what the Speaker should announce via BGP.

func (*MetalLBSpeaker) OnAddCiliumNode

func (s *MetalLBSpeaker) OnAddCiliumNode(node *ciliumv2.CiliumNode, swg *lock.StoppableWaitGroup) error

OnAddCiliumNode notifies the Speaker of a new CiliumNode.

func (*MetalLBSpeaker) OnAddNode

func (s *MetalLBSpeaker) OnAddNode(node *v1.Node, swg *lock.StoppableWaitGroup) error

OnAddNode notifies the Speaker of a new node.

func (*MetalLBSpeaker) OnDeleteCiliumNode

func (s *MetalLBSpeaker) OnDeleteCiliumNode(node *ciliumv2.CiliumNode, swg *lock.StoppableWaitGroup) error

OnDeleteCiliumNode notifies the Speaker of a CiliumNode deletion.

When the speaker discovers the node that it is running on is shuttig down it will send a BGP message to its peer instructing it to withdrawal all previously advertised routes.

func (*MetalLBSpeaker) OnDeleteNode

func (s *MetalLBSpeaker) OnDeleteNode(node *v1.Node, swg *lock.StoppableWaitGroup) error

OnDeleteNode notifies the Speaker of a node deletion.

When the speaker discovers the node that it is running on is shuttig down it will send a BGP message to its peer instructing it to withdrawal all previously advertised routes.

func (*MetalLBSpeaker) OnDeleteService

func (s *MetalLBSpeaker) OnDeleteService(svc *slim_corev1.Service) error

OnDeleteService notifies the Speaker of a delete of a service.

func (*MetalLBSpeaker) OnUpdateCiliumNode

func (s *MetalLBSpeaker) OnUpdateCiliumNode(oldNode, newNode *ciliumv2.CiliumNode, swg *lock.StoppableWaitGroup) error

OnUpdateCiliumNode notifies the Speaker of an update to a CiliumNode.

func (*MetalLBSpeaker) OnUpdateEndpointSliceV1 added in v1.11.0

func (s *MetalLBSpeaker) OnUpdateEndpointSliceV1(eps *slim_discover_v1.EndpointSlice) error

OnUpdateEndpointSliceV1 notifies the Speaker of an update to the backends of a service as endpoint slices.

func (*MetalLBSpeaker) OnUpdateEndpointSliceV1Beta1 added in v1.11.0

func (s *MetalLBSpeaker) OnUpdateEndpointSliceV1Beta1(eps *slim_discover_v1beta1.EndpointSlice) error

OnUpdateEndpointSliceV1Beta1 is the same as OnUpdateEndpointSliceV1() but for the v1beta1 variant.

func (*MetalLBSpeaker) OnUpdateEndpoints

func (s *MetalLBSpeaker) OnUpdateEndpoints(eps *slim_corev1.Endpoints) error

OnUpdateEndpoints notifies the Speaker of an update to the backends of a service.

func (*MetalLBSpeaker) OnUpdateNode

func (s *MetalLBSpeaker) OnUpdateNode(oldNode, newNode *v1.Node, swg *lock.StoppableWaitGroup) error

func (*MetalLBSpeaker) OnUpdateService

func (s *MetalLBSpeaker) OnUpdateService(svc *slim_corev1.Service) error

OnUpdateService notifies the Speaker of an update to a service.

func (*MetalLBSpeaker) RegisterSvcCache

func (s *MetalLBSpeaker) RegisterSvcCache(cache endpointsGetter)

RegisterSvcCache registers the K8s watcher cache with this Speaker.

type Op

type Op int

Op enumerates the operation an event demonstrates.

const (
	Undefined Op = iota
	Add
	Update
	Delete
)

func (Op) String

func (o Op) String() string

type Opts

type Opts struct {
	LoadBalancerIP bool
	PodCIDR        bool
}

Opts represents what the Speaker can announce.

type Speaker

type Speaker interface {
	// SetService will announce the provided Service of type LoadBalancer to BGP peers.
	SetService(name string, svc *metallbspr.Service, eps *metallbspr.Endpoints) types.SyncState
	// SetNodeLabels will create or delete any BGP sessions given the provided labels
	// allow for this.
	//
	// The provided labels will be used to determine if the Speaker allows for BGP
	// peering.
	SetNodeLabels(labels map[string]string) types.SyncState
	// PeerSessions returns any active BGP sessions.
	PeerSessions() []metallbspr.Session
	// GetBGPController returns the BGPController of the speaker
	GetBGPController() *metallbspr.BGPController
}

Speaker provides a method set for interfacing with a BGP speaker.

This interface is heavily modeled after MetalLB's speaker as it's the first BGP integration for Cilium's use cases.

If other BGP integrations are desired, consider building out custom types and a more abstracted method set.

Jump to

Keyboard shortcuts

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