agent

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
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(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

	// ReconcileInstances evaluates the provided CiliumBGPNodeConfig
	// and the implementation will configure itself to apply this configuration.
	ReconcileInstances(ctx context.Context, bgpnc *v2alpha1api.CiliumBGPNodeConfig, 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

	// BGP v2 node store
	BGPNodeConfigStore store.BGPCPResourceStore[*v2alpha1api.CiliumBGPNodeConfig]

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

	// current configuration state
	ConfigMode *mode.ConfigMode
}

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

func (c *Controller) Reconcile(ctx context.Context) error

Reconcile is the main reconciliation loop for the BGP Control Plane Controller. It is responsible for determining the current mode of BGP control plane, which can be disabled, bgpv1 or bgpv2. Based on presence of BGP peering policy and BGP node config, it will apply the appropriate configuration. Following is the state transition table for the controller: Initial state | BGPPP exists | BGPNC exists | Action | Next state ----------------------|--------------|--------------|----------------------------|----------- disabled | true | don't care | Apply BGPv1 | bgpv1 disabled | false | true | Apply BGPv2 | bgpv2 disabled | false | false | Do nothing | disabled bgpv1 | true | don't care | Apply BGPv1 | bgpv1 bgpv1 | false | true | Delete BGPv1, Apply BGPv2 | bgpv2 bgpv1 | false | false | Delete BGPv1 | disabled bgpv2 | true | don't care | Delete BGPv2, Apply BGPv1 | bgpv1 bgpv2 | false | true | Apply BGPv2 | bgpv2 bgpv2 | false | false | Delete BGPv2 | disabled

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
	Health                  cell.Health
	JobGroup                job.Group
	Shutdowner              hive.Shutdowner
	Sig                     *signaler.BGPCPSignaler
	ConfigMode              *mode.ConfigMode
	RouteMgr                BGPRouterManager
	PolicyResource          resource.Resource[*v2alpha1api.CiliumBGPPeeringPolicy]
	BGPNodeConfigStore      store.BGPCPResourceStore[*v2alpha1api.CiliumBGPNodeConfig]
	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.

func (ErrAttrib) Error

func (e ErrAttrib) Error() string

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

Directories

Path Synopsis
SPDX-License-Identifier: Apache-2.0 Copyright Authors of Cilium
SPDX-License-Identifier: Apache-2.0 Copyright Authors of Cilium

Jump to

Keyboard shortcuts

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