Documentation ¶
Index ¶
- Variables
- func PolicySelection(ctx context.Context, labels map[string]string, ...) (*v2alpha1api.CiliumBGPPeeringPolicy, error)
- type AnnotationMap
- type Attributes
- type BGPRouterManager
- type Controller
- type ControllerParams
- type ErrASNAnno
- type ErrAttrib
- type ErrMulti
- type ErrNoASNAnno
- type ErrNotVRouterAnno
- type MockCiliumBGPPeeringPolicyLister
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMultiplePolicies is a static error typed when the controller encounters // multiple policies which apply to its host. ErrMultiplePolicies = fmt.Errorf("more then one CiliumBGPPeeringPolicy applies to this node, please ensure only a single Policy matches this node's labels") // ErrBGPControlPlaneDisabled is set when the BGP control plane is disabled ErrBGPControlPlaneDisabled = fmt.Errorf("BGP control plane is disabled") )
Functions ¶
func PolicySelection ¶
func PolicySelection(ctx context.Context, labels map[string]string, policies []*v2alpha1api.CiliumBGPPeeringPolicy) (*v2alpha1api.CiliumBGPPeeringPolicy, error)
PolicySelection returns a CiliumBGPPeeringPolicy which applies to the provided *corev1.Node, enforced by a set of policy selection rules.
Policy selection follows the following rules:
- A policy matches a node if said policy's "nodeSelector" field matches the node's labels. If "nodeSelector" is omitted, it is unconditionally selected.
- If (N > 1) policies match the provided *corev1.Node an error is returned. only a single policy may apply to a node to avoid ambiguity at this stage of development.
Types ¶
type AnnotationMap ¶
type AnnotationMap map[int64]Attributes
AnnotationMap coorelates a parsed Annotations structure with the local ASN its annotating.
func NewAnnotationMap ¶
func NewAnnotationMap(a map[string]string) (AnnotationMap, error)
NewAnnotationMap parses a Node's annotations into a AnnotationMap and returns the latter.
An error is returned containing one or more parsing errors.
This is for convenience so the caller can log all parsing errors at once. The error should still be treated as a normal descrete error and an empty AnnotationMap is returned.
func (AnnotationMap) ResolveRouterID ¶
func (a AnnotationMap) ResolveRouterID(localASN int64) (string, error)
type Attributes ¶
type Attributes struct { // The local ASN of the virtual router these Attributes targets. ASN int64 // The router ID to use for the virtual router with the above local ASN. RouterID string // The local BGP port to listen on. LocalPort int32 }
The BGP control plane may need some node-specific configuration for instantiating virtual routers.
For example, BGP router IDs cannot repeat in a BGP peering topology. When Cilium cannot generate a unique router ID it will look for a unique router ID for the virtual router identified by its local ASN.
We define a set of attributes which can be defined via Node-specific kubernetes annotations.
This Kubernetes annotation's syntax is: `cilium.io/bgp-virtual-router.{asn}="attr1=value1,attr2=value2"
Where {asn} is replaced by the local ASN of the virtual router.
Currently supported attributes are:
router-id=IPv4 (string): when present on a specific node, use this value for the router ID of the virtual router with local {asn} local-port=port (int): the local port to listen on for incoming BGP connections
type BGPRouterManager ¶
type BGPRouterManager interface { // ConfigurePeers evaluates the provided CiliumBGPPeeringPolicy // and the implementation will configure itself to apply this policy. // // A ControllerState structure is provided which captures Cilium's runtime // state at the time of this method's invocation. It must remain read-only. // // ConfigurePeers should block until it can ensure a subsequent call // to ConfigurePeers can occur without conflict. // // ConfigurePeers should not be called concurrently and expects invocations // to be serialized contingent to the method's completion. // // An error is returned only when the implementation can determine a // critical flaw with the peering policy, not when network connectivity // is an issue. // // Providing a nil policy to ConfigurePeers will withdrawal all routes // and disconnect from the peers. ConfigurePeers(ctx context.Context, policy *v2alpha1api.CiliumBGPPeeringPolicy, ciliumNode *v2api.CiliumNode) error // GetPeers fetches BGP peering state from underlying routing daemon. // // List of all peers will be returned and if there are multiple instances of // BGP daemon running locally, then peers can be differentiated based on // local AS number. GetPeers(ctx context.Context) ([]*models.BgpPeer, error) // GetRoutes fetches BGP routes from underlying routing daemon's RIBs. GetRoutes(ctx context.Context, params restapi.GetBgpRoutesParams) ([]*models.BgpRoute, error) // GetRoutePolicies fetches BGP routing policies from underlying routing daemon. GetRoutePolicies(ctx context.Context, params restapi.GetBgpRoutePoliciesParams) ([]*models.BgpRoutePolicy, error) // Stop will stop all BGP instances and clean up local state. Stop() }
BGPRouterManager provides a declarative API for defining BGP peers.
type Controller ¶
type Controller struct { // CiliumNodeResource provides a stream of events for changes to the local CiliumNode resource. CiliumNodeResource daemon_k8s.LocalCiliumNodeResource // LocalCiliumNode is the CiliumNode object for the local node. LocalCiliumNode *v2_api.CiliumNode // PolicyResource provides a store of cached policies and allows us to observe changes to the objects in its // store. PolicyResource resource.Resource[*v2alpha1api.CiliumBGPPeeringPolicy] // PolicyLister is an interface which allows for the listing of all known policies PolicyLister policyLister // Sig informs the Controller that a Kubernetes // event of interest has occurred. // // The signal itself provides no other information, // when it occurs the Controller will query each // informer for the latest API information required // to drive it's control loop. Sig *signaler.BGPCPSignaler // BGPMgr is an implementation of the BGPRouterManager interface // and provides a declarative API for configuring BGP peers. BGPMgr BGPRouterManager // contains filtered or unexported fields }
Controller is the agent side BGP Control Plane controller.
Controller listens for events and drives BGP related sub-systems to maintain a desired state.
func NewController ¶
func NewController(params ControllerParams) (*Controller, error)
NewController constructs a new BGP Control Plane Controller.
When the constructor returns the Controller will be actively watching for events and configuring BGP related sub-systems.
The constructor requires an implementation of BGPRouterManager to be provided. This implementation defines which BGP backend will be used (GoBGP, FRR, Bird, etc...) NOTE: only GoBGP currently implemented.
func (*Controller) FullWithdrawal ¶
func (c *Controller) FullWithdrawal(ctx context.Context)
FullWithdrawal will instruct the configured BGPRouterManager to withdraw all BGP servers and peers.
func (*Controller) Reconcile ¶
func (c *Controller) Reconcile(ctx context.Context) error
Reconcile is the control loop for the Controller.
Reconcile will be invoked when one or more event sources trigger a signal via the Controller's Signaler structure.
On signal, Reconcile will obtain the state of the world necessary to drive the BGP control plane toward any new BGP peering policies.
Reconcile will only allow a single CiliumBGPPeeringPolicy to apply to the node its running on.
func (*Controller) Run ¶
func (c *Controller) Run(ctx context.Context)
Run places the Controller into its control loop.
When new events trigger a signal the control loop will be evaluated.
A cancel of the provided ctx will kill the control loop along with the running informers.
type ControllerParams ¶
type ControllerParams struct { cell.In Lifecycle cell.Lifecycle Scope cell.Scope JobRegistry job.Registry Shutdowner hive.Shutdowner Sig *signaler.BGPCPSignaler RouteMgr BGPRouterManager PolicyResource resource.Resource[*v2alpha1api.CiliumBGPPeeringPolicy] DaemonConfig *option.DaemonConfig LocalCiliumNodeResource daemon_k8s.LocalCiliumNodeResource }
ControllerParams contains all parameters needed to construct a Controller
type ErrASNAnno ¶
type ErrASNAnno struct {
// contains filtered or unexported fields
}
ErrASN is an error returned from parseAnnotation() when the bgp-virtual-router annotation includes an ASN that cannot be parsed into an
func (ErrASNAnno) Error ¶
func (e ErrASNAnno) Error() string
type ErrAttrib ¶
type ErrAttrib struct {
// contains filtered or unexported fields
}
ErrAttrib is an error returned from parseAnnotation() when an attribute is provided but its value is malformed.
type ErrMulti ¶
type ErrMulti struct {
// contains filtered or unexported fields
}
ErrMulti holds multiple errors and formats them sanely when printed.
type ErrNoASNAnno ¶
type ErrNoASNAnno struct {
// contains filtered or unexported fields
}
ErrNoASNAnno is an error returned from parseAnnotation() when the bgp-virtual-router annotation does not include a local ASN.
func (ErrNoASNAnno) Error ¶
func (e ErrNoASNAnno) Error() string
type ErrNotVRouterAnno ¶
type ErrNotVRouterAnno struct {
// contains filtered or unexported fields
}
ErrNotVRouterAnno is an error returned from parseAnnotation() when the the casted string is not a `cilium.io/bgp-virtual-router` annotation
func (ErrNotVRouterAnno) Error ¶
func (e ErrNotVRouterAnno) Error() string
type MockCiliumBGPPeeringPolicyLister ¶
type MockCiliumBGPPeeringPolicyLister struct {
List_ func() ([]*v2alpha1.CiliumBGPPeeringPolicy, error)
}
func (*MockCiliumBGPPeeringPolicyLister) List ¶
func (m *MockCiliumBGPPeeringPolicyLister) List() ([]*v2alpha1.CiliumBGPPeeringPolicy, error)