node

package
v1.20.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 31 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 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) 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