node

package
v1.20.0-pre.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 32 Imported by: 111

Documentation

Overview

Package node provides functionality related to the local and remote node addresses

Index

Constants

View Source
const (
	LocalNodeTableName = "local-node"
)

Variables

View Source
var (
	LocalNodeNameIndex = statedb.Index[*LocalNode, string]{
		Name: "name",
		FromObject: func(obj *LocalNode) index.KeySet {
			return index.NewKeySet(index.String(obj.Fullname()))
		},
		FromKey:    index.String,
		FromString: index.FromString,
		Unique:     true,
	}
	NodeByName = LocalNodeNameIndex.Query

	LocalNodeLocalIndex = statedb.Index[*LocalNode, bool]{
		Name: "local",
		FromObject: func(obj *LocalNode) index.KeySet {
			if obj.Local == nil {

				return index.KeySet{}
			}
			return index.NewKeySet(index.Bool(true))
		},
		FromKey:    index.Bool,
		FromString: index.BoolString,
		Unique:     true,
	}

	NodeByLocal    = LocalNodeLocalIndex.Query
	LocalNodeQuery = NodeByLocal(true)
)
View Source
var LocalNodeStoreCell = cell.Module(
	"local-node-store",
	"Provides LocalNodeStore for observing and updating local node info",

	cell.Provide(
		NewLocalNodeTable,
		statedb.RWTable[*LocalNode].ToTable,
	),

	cell.Provide(NewLocalNodeStore),
)

LocalNodeStoreCell provides the LocalNodeStore instance. The LocalNodeStore is the canonical owner of `types.Node` for the local node and provides a reactive API for observing and updating it.

LocalNodeStoreTestCell is a convenience for tests that provides a no-op LocalNodeSynchronizer. Use LocalNodeStoreCell in tests when you want to provide your own LocalNodeSynchronizer.

Functions

func FirstGlobalV4Addr

func FirstGlobalV4Addr(intf string, preferredIP net.IP) (net.IP, error)

firstGlobalV4Addr returns the first IPv4 global IP of an interface, where the IPs are sorted in creation order (oldest to newest).

All secondary IPs, except the preferredIP, are filtered out.

Public IPs are preferred over private ones. When intf is defined only IPs belonging to that interface are considered.

If preferredIP is present in the IP list it is returned irrespective of the sort order. However, if preferredIP is a private IP, a public IP will be returned if it is assigned to the intf

Passing intf and preferredIP will only return preferredIP if it is in the IPs that belong to intf.

In all cases, if intf is not found all interfaces are considered.

If a intf-specific global address couldn't be found, we retry to find an address with reduced scope (site, custom) on that particular device.

If the latter fails as well, we retry on all interfaces beginning with universe scope again (and then falling back to reduced scope).

In case none of the above helped, we bail out with error.

func FirstGlobalV6Addr

func FirstGlobalV6Addr(intf string, preferredIP net.IP) (net.IP, error)

firstGlobalV6Addr returns first IPv6 global IP of an interface, see firstGlobalV4Addr for more details.

func GetBootID added in v1.13.14

func GetBootID(logger *slog.Logger) string

func GetCiliumEndpointNodeIP added in v0.15.7

func GetCiliumEndpointNodeIP(localNode LocalNode) string

GetCiliumEndpointNodeIP is the node IP that will be referenced by CiliumEndpoints with endpoints running on this node.

func GetEndpointEncryptKeyIndex added in v1.14.7

func GetEndpointEncryptKeyIndex(localNode LocalNode, wgEnabled, ipsecEnabled bool) uint8

GetEndpointEncryptKeyIndex returns the encryption key value for an endpoint owned by the given local node. With IPSec encryption, this is the ID of the currently loaded key. With WireGuard, this returns a non-zero static value. Note that the key index returned by this function is only valid for _endpoints_ of the local node. If you want to obtain the key index of the local node itself, access the `EncryptionKey` field via the LocalNodeStore.

func GetEndpointID added in v0.15.7

func GetEndpointID() (uint64, bool)

GetEndpointID returns the ID of the host endpoint for this node. The boolean return value indicates whether the host endpoint ID has been set (true) or is still the uninitialized template value (false).

func GetExcludedIPs added in v0.15.7

func GetExcludedIPs() []net.IP

GetExcludedIPs returns a list of IPs from netdevices that Cilium needs to exclude to operate

func NewLocalNodeStore added in v0.15.7

func NewLocalNodeStore(params LocalNodeStoreParams) (*LocalNodeStore, NodeGetter, error)

func NewLocalNodeTable added in v1.19.0

func NewLocalNodeTable(db *statedb.DB) (statedb.RWTable[*LocalNode], error)

func SetEndpointID added in v0.15.7

func SetEndpointID(id uint64)

SetEndpointID sets the ID of the host endpoint for this node.

func SetRouterInfo added in v0.15.7

func SetRouterInfo(info RouterInfo)

SetRouterInfo sets additional information for the router, the cilium_host interface.

Types

type Addressing

type Addressing interface {
	IPv6() AddressingFamily
	IPv4() AddressingFamily
}

Addressing implements addressing of a node

type AddressingFamily

type AddressingFamily interface {
	// Router is the address that will act as the router on each node where
	// an agent is running on. Endpoints have a default route that points
	// to this address.
	Router() net.IP

	// PrimaryExternal is the primary external address of the node. Nodes
	// must be able to reach each other via this address.
	PrimaryExternal() net.IP

	// AllocationCIDR is the CIDR used for IP allocation of all endpoints
	// on the node
	AllocationCIDR() *cidr.CIDR
}

AddressingFamily is the node addressing information for a particular address family

type Handler

type Handler interface {
	// Name identifies the handler, this is used in logging/reporting handler
	// reconciliation errors.
	Name() string

	// NodeAdd is called when a node is discovered for the first time.
	NodeAdd(newNode types.Node) error

	// NodeUpdate is called when a node definition changes. Both the old
	// and new node definition is provided. NodeUpdate() is never called
	// before NodeAdd() is called for a particular node.
	NodeUpdate(oldNode, newNode types.Node) error

	// NodeDelete is called after a node has been deleted
	NodeDelete(node types.Node) error

	// AllNodeValidateImplementation is called to validate the implementation
	// of all nodes in the node cache.
	AllNodeValidateImplementation()

	// NodeValidateImplementation is called to validate the implementation of
	// the node in the datapath. This function is intended to be run on an
	// interval to ensure that the datapath is consistently converged.
	NodeValidateImplementation(node types.Node) error
}

Handler handles node related events such as addition, update or deletion of nodes or changes to the local node configuration.

Node events apply to the local node as well as to remote nodes. The implementation can differ between the own local node and remote nodes by calling node.IsLocal().

type IDHandler

type IDHandler interface {
	// GetNodeIP returns the string node IP that was previously registered as the given node ID.
	GetNodeIP(uint16) string

	// GetNodeID gets the node ID for the given node IP. If none is found, exists is false.
	GetNodeID(nodeIP net.IP) (nodeID uint16, exists bool)

	// DumpNodeIDs returns all node IDs and their associated IP addresses.
	DumpNodeIDs() []*models.NodeID

	// RestoreNodeIDs restores node IDs and their associated IP addresses from the
	// BPF map and into the node handler in-memory copy.
	RestoreNodeIDs()
}

type LocalNode added in v0.15.7

type LocalNode struct {
	types.Node

	// Local is non-nil if this is the local node. This carries additional
	// information about the local node that is not shared outside.
	Local *LocalNodeInfo
}

LocalNode is the local Cilium node. This is derived from the k8s corev1.Node object.

+k8s:deepcopy-gen=true +deepequal-gen=true

func (*LocalNode) DeepCopy added in v1.19.0

func (in *LocalNode) DeepCopy() *LocalNode

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LocalNode.

func (*LocalNode) DeepCopyInto added in v1.19.0

func (in *LocalNode) DeepCopyInto(out *LocalNode)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*LocalNode) DeepEqual added in v1.17.0

func (in *LocalNode) DeepEqual(other *LocalNode) bool

DeepEqual is an autogenerated deepequal function, deeply comparing the receiver with other. in must be non-nil.

func (*LocalNode) RemoteSNATDstAddrExclusionCIDRv4

func (n *LocalNode) RemoteSNATDstAddrExclusionCIDRv4() *cidr.CIDR

RemoteSNATDstAddrExclusionCIDRv4 returns a CIDR for SNAT exclusion. Any packet sent from a local endpoint to an IP address belonging to the CIDR should not be SNAT'd.

func (*LocalNode) RemoteSNATDstAddrExclusionCIDRv6

func (n *LocalNode) RemoteSNATDstAddrExclusionCIDRv6() *cidr.CIDR

RemoteSNATDstAddrExclusionCIDRv6 returns a IPv6 CIDR for SNAT exclusion. Any packet sent from a local endpoint to an IP address belonging to the CIDR should not be SNAT'd.

func (*LocalNode) TableHeader added in v1.19.0

func (n *LocalNode) TableHeader() []string

TableHeader implements statedb.TableWritable.

func (*LocalNode) TableRow added in v1.19.0

func (n *LocalNode) TableRow() []string

TableRow implements statedb.TableWritable.

type LocalNodeInfo added in v1.19.0

type LocalNodeInfo struct {
	// OptOutNodeEncryption will make the local node opt-out of node-to-node
	// encryption
	OptOutNodeEncryption bool
	// Unique identifier of the Kubernetes node, used to construct the
	// corresponding owner reference.
	UID k8stypes.UID
	// ID of the node assigned by the cloud provider.
	ProviderID string
	// v4 CIDR in which pod IPs are routable
	IPv4NativeRoutingCIDR *cidr.CIDR
	// v6 CIDR in which pod IPs are routable
	IPv6NativeRoutingCIDR *cidr.CIDR
	// ServiceLoopbackIPv4 is the source address used for SNAT when a Pod talks to
	// itself through a Service.
	// +deepequal-gen=false
	ServiceLoopbackIPv4 netip.Addr
	// ServiceLoopbackIPv6 is the source address used for SNAT when a Pod talks to
	// itself through a Service.
	// +deepequal-gen=false
	ServiceLoopbackIPv6 netip.Addr
	// IsBeingDeleted indicates that the local node is being deleted.
	IsBeingDeleted bool
	// UnderlayProtocol is the IP family of our underlay.
	UnderlayProtocol tunnel.UnderlayProtocol
}

LocalNodeInfo is the additional information about the local node that is only used internally.

+k8s:deepcopy-gen=false +deepequal-gen=true +deepequal-gen:private-method=true

func (*LocalNodeInfo) DeepCopy added in v1.19.0

func (in *LocalNodeInfo) DeepCopy() *LocalNodeInfo

DeepCopy creates a deep copy of the LocalNodeInfo.

func (*LocalNodeInfo) DeepCopyInto added in v1.19.0

func (in *LocalNodeInfo) DeepCopyInto(out *LocalNodeInfo)

DeepCopyInto copies the receiver into out. in must be non-nil.

func (*LocalNodeInfo) DeepEqual added in v1.19.0

func (in *LocalNodeInfo) DeepEqual(other *LocalNodeInfo) bool

DeepEqual compares two LocalNodeInfo structs for equality.

type LocalNodeStore added in v0.15.7

type LocalNodeStore struct {
	// contains filtered or unexported fields
}

LocalNodeStore is the canonical owner for the local node object and provides a reactive API for observing and updating the state.

func NewTestLocalNodeStore added in v0.15.7

func NewTestLocalNodeStore(mockNode LocalNode) *LocalNodeStore

func (*LocalNodeStore) Get added in v0.15.7

func (s *LocalNodeStore) Get(ctx context.Context) (LocalNode, error)

Get retrieves the current local node. Use Get() only for inspecting the state, e.g. in API handlers. Do not assume the value does not change over time. Blocks until the store has been initialized.

func (*LocalNodeStore) Observe added in v1.13.0

func (s *LocalNodeStore) Observe(ctx context.Context, next func(LocalNode), complete func(error))

Observe changes to the local node state.

func (*LocalNodeStore) Update added in v0.15.7

func (s *LocalNodeStore) Update(update func(*LocalNode))

Update modifies the local node with a mutator.

func (*LocalNodeStore) WaitForNodeInformation

func (s *LocalNodeStore) WaitForNodeInformation(ctx context.Context) error

type LocalNodeStoreParams added in v0.15.7

type LocalNodeStoreParams struct {
	cell.In

	Logger      *slog.Logger
	Lifecycle   cell.Lifecycle
	Sync        LocalNodeSynchronizer
	DB          *statedb.DB
	Nodes       statedb.RWTable[*LocalNode]
	Jobs        job.Group
	ClusterInfo cmtypes.ClusterInfo
}

LocalNodeStoreParams are the inputs needed for constructing LocalNodeStore.

type LocalNodeSynchronizer added in v1.15.0

type LocalNodeSynchronizer interface {
	InitLocalNode(context.Context, *LocalNode) error
	SyncLocalNode(context.Context, *LocalNodeStore)
	WaitForNodeInformation(context.Context, *LocalNodeStore) error
}

LocalNodeSynchronizer specifies how to build, and keep synchronized the local node object.

func NewNopLocalNodeSynchronizer added in v1.19.0

func NewNopLocalNodeSynchronizer() LocalNodeSynchronizer

type NodeGetter

type NodeGetter interface {
	Get(ctx context.Context) (LocalNode, error)
}

NodeGetter describes the behavior of a node store used for retrieving the local node.

type RouterInfo added in v0.15.7

type RouterInfo interface {
	GetCIDRs() []net.IPNet
}

func GetRouterInfo added in v0.15.7

func GetRouterInfo() RouterInfo

GetRouterInfo returns additional information for the router, the cilium_host interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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