node

package
v1.19.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 37 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 AutoComplete added in v0.15.7

func AutoComplete(logger *slog.Logger, directRoutingDevice string) error

AutoComplete completes the parts of addressing that can be auto derived

func ExtractCiliumHostIPFromFS added in v1.15.0

func ExtractCiliumHostIPFromFS(logger *slog.Logger) (ipv4GW, ipv6Router net.IP)

ExtractCiliumHostIPFromFS returns the Cilium IPv4 gateway and router IPv6 address from the node_config.h file if is present; or by deriving it from defaults.HostDevice interface, on which only the IPv4 is possible to derive.

func GetBootID added in v1.13.14

func GetBootID(logger *slog.Logger) string

func GetCiliumEndpointNodeIP added in v0.15.7

func GetCiliumEndpointNodeIP(logger *slog.Logger) 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(logger *slog.Logger, wgCfg wgTypes.WireguardConfig) uint8

GetEndpointEncryptKeyIndex returns the encryption key value for an endpoint owned by the 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 GetEndpointHealthIPv4 added in v0.15.7

func GetEndpointHealthIPv4(logger *slog.Logger) net.IP

GetEndpointHealthIPv4 returns the IPv4 cilium-health endpoint address.

func GetEndpointHealthIPv6 added in v0.15.7

func GetEndpointHealthIPv6(logger *slog.Logger) net.IP

GetEndpointHealthIPv6 returns the IPv6 cilium-health endpoint address.

func GetEndpointID added in v0.15.7

func GetEndpointID() uint64

GetEndpointID returns the ID of the host endpoint for this node.

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 GetIPv4 added in v0.15.7

func GetIPv4(logger *slog.Logger) net.IP

GetIPv4 returns one of the IPv4 node address available with the following priority: - NodeInternalIP - NodeExternalIP - other IP address type. It must be reachable on the network.

func GetIPv4AllocRange added in v0.15.7

func GetIPv4AllocRange(logger *slog.Logger) *cidr.CIDR

GetIPv4AllocRange returns the IPv4 allocation prefix of this node

func GetIPv6 added in v0.15.7

func GetIPv6(logger *slog.Logger) net.IP

GetIPv6 returns the IPv6 address of the node

func GetIPv6AllocRange added in v0.15.7

func GetIPv6AllocRange(logger *slog.Logger) *cidr.CIDR

GetIPv6AllocRange returns the IPv6 allocation prefix of this node

func GetIPv6Router added in v0.15.7

func GetIPv6Router(logger *slog.Logger) net.IP

GetIPv6Router returns the IPv6 address of the router, e.g. address of cilium_host device.

func GetIngressIPv4 added in v0.15.7

func GetIngressIPv4(logger *slog.Logger) net.IP

GetIngressIPv4 returns the local IPv4 source address for Cilium Ingress.

func GetIngressIPv6 added in v0.15.7

func GetIngressIPv6(logger *slog.Logger) net.IP

GetIngressIPv6 returns the local IPv6 source address for Cilium Ingress.

func GetInternalIPv4 added in v0.15.7

func GetInternalIPv4(logger *slog.Logger) net.IP

GetInternalIPv4 returns node internal ipv4 address else return nil.

func GetInternalIPv4Router added in v0.15.7

func GetInternalIPv4Router(logger *slog.Logger) net.IP

GetInternalIPv4Router returns the cilium internal IPv4 node address. This must not be conflated with k8s internal IP as this IP address is only relevant within the Cilium-managed network (this means within the node for direct routing mode and on the overlay for tunnel mode).

func GetInternalIPv6 added in v0.15.7

func GetInternalIPv6(logger *slog.Logger) net.IP

GetInternalIPv6 returns node internal ipv6 address else return nil.

func GetNodeAddressing added in v0.15.7

func GetNodeAddressing(logger *slog.Logger) *models.NodeAddressing

GetNodeAddressing returns the NodeAddressing model for the local IPs.

func GetOptOutNodeEncryption added in v0.15.7

func GetOptOutNodeEncryption(logger *slog.Logger) bool

func GetServiceLoopbackIPv4 added in v1.18.0

func GetServiceLoopbackIPv4(logger *slog.Logger) net.IP

GetServiceLoopbackIPv4 returns the service loopback IPv4 address of this node.

func IsNodeIP added in v1.17.0

func IsNodeIP(logger *slog.Logger, addr netip.Addr) addressing.AddressType

IsNodeIP determines if addr is one of the node's IP addresses, and returns which type of address it is. "" is returned if addr is not one of the node's IP addresses.

func NewLocalNodeTable

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

func SetEndpointHealthIPv4 added in v0.15.7

func SetEndpointHealthIPv4(ip net.IP)

SetEndpointHealthIPv4 sets the IPv4 cilium-health endpoint address.

func SetEndpointHealthIPv6 added in v0.15.7

func SetEndpointHealthIPv6(ip net.IP)

SetEndpointHealthIPv6 sets the IPv6 cilium-health endpoint address.

func SetEndpointID added in v0.15.7

func SetEndpointID(id uint64)

SetEndpointID sets the ID of the host endpoint this node.

func SetIPsecKeyIdentity added in v0.15.7

func SetIPsecKeyIdentity(id uint8)

SetIPsecKeyIdentity sets the IPsec key identity an opaque value used to identity encryption keys used on the node.

func SetIPv4AllocRange added in v0.15.7

func SetIPv4AllocRange(net *cidr.CIDR)

SetIPv4AllocRange sets the IPv4 address pool to use when allocating addresses for local endpoints

func SetIPv6NodeRange added in v0.15.7

func SetIPv6NodeRange(net *cidr.CIDR)

SetIPv6NodeRange sets the IPv6 address pool to be used on this node

func SetIPv6Router added in v0.15.7

func SetIPv6Router(ip net.IP)

SetIPv6Router sets the IPv6 address of the router address, e.g. address of cilium_host device.

func SetIngressIPv4 added in v0.15.7

func SetIngressIPv4(ip net.IP)

SetIngressIPv4 sets the local IPv4 source address for Cilium Ingress.

func SetIngressIPv6 added in v0.15.7

func SetIngressIPv6(ip net.IP)

SetIngressIPv6 sets the local IPv6 source address for Cilium Ingress.

func SetInternalIPv4Router added in v0.15.7

func SetInternalIPv4Router(ip net.IP)

SetInternalIPv4Router sets the cilium internal IPv4 node address, it is allocated from the node prefix. This must not be conflated with k8s internal IP as this IP address is only relevant within the Cilium-managed network (this means within the node for direct routing mode and on the overlay for tunnel mode).

func SetRouterInfo added in v0.15.7

func SetRouterInfo(info RouterInfo)

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

func SetServiceLoopbackIPv4 added in v1.18.0

func SetServiceLoopbackIPv4(ip net.IP)

SetIPv4Loopback sets the service loopback IPv4 address of this node.

func SetTestLocalNodeStore added in v0.15.7

func SetTestLocalNodeStore()

func UnsetTestLocalNodeStore added in v0.15.7

func UnsetTestLocalNodeStore()

func UpdateLocalNodeInTest added in v0.15.7

func UpdateLocalNodeInTest(mod func(n *LocalNode))

UpdateLocalNodeInTest provides access to modifying the local node information from tests that are not yet using hive and the LocalNodeStoreCell.

func ValidatePostInit added in v0.15.7

func ValidatePostInit(logger *slog.Logger) error

ValidatePostInit validates the entire addressing setup and completes it as required

func WithTestLocalNodeStore added in v0.15.7

func WithTestLocalNodeStore(runTest func())

WithTestLocalNodeStore sets the 'localNode' to a temporary instance and runs the given test. Afterwards the 'localNode' is restored to nil. This is a temporary workaround for tests until the LocalNodeStoreCell can be used.

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

func (in *LocalNode) DeepCopy() *LocalNode

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

func (*LocalNode) DeepCopyInto

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

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

TableHeader implements statedb.TableWritable.

func (*LocalNode) TableRow

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

TableRow implements statedb.TableWritable.

type LocalNodeInfo

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.
	ServiceLoopbackIPv4 net.IP
	// 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=true +deepequal-gen=true

func (*LocalNodeInfo) DeepCopy

func (in *LocalNodeInfo) DeepCopy() *LocalNodeInfo

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

func (*LocalNodeInfo) DeepCopyInto

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

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

func (*LocalNodeInfo) DeepEqual

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

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

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 NewLocalNodeStore added in v0.15.7

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

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.

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
}

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

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

func NewNopLocalNodeSynchronizer

func NewNopLocalNodeSynchronizer() LocalNodeSynchronizer

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