device

package
v1.21.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DesiredDeviceIndex = statedb.Index[*DesiredDevice, DesiredDeviceKey]{
		Name: "id",
		FromObject: func(obj *DesiredDevice) index.KeySet {
			return index.NewKeySet(obj.GetKey().Key())
		},
		FromKey:    DesiredDeviceKey.Key,
		FromString: index.FromString,
		Unique:     true,
	}
	DesiredDeviceNameIndex = statedb.Index[*DesiredDevice, string]{
		Name: "name",
		FromObject: func(obj *DesiredDevice) index.KeySet {
			return index.NewKeySet(index.String(obj.Name))
		},
		FromKey:    index.String,
		FromString: index.FromString,
		Unique:     true,
	}
)
View Source
var Cell = cell.Module(
	"device-reconciler",
	"Reconciles desired devices to the Linux kernel links",
	TableCell,
	cell.Provide(newDeviceManager),
	cell.Invoke(registerReconciler),
)
View Source
var (
	ErrOwnerDoesNotExist = errors.New("owner does not exist")
)
View Source
var TableCell = cell.Group(
	cell.ProvidePrivate(newDesiredDeviceTable),
	cell.Provide(statedb.RWTable[*DesiredDevice].ToTable),
)

Functions

func EnableForwarding

func EnableForwarding(logger *slog.Logger, sysctl sysctl.Sysctl, link netlink.Link) error

EnableForwarding puts the given link into the up state and enables IP forwarding.

func EnsureDevice

func EnsureDevice(logger *slog.Logger, sysctl sysctl.Sysctl, attrs netlink.Link) (netlink.Link, error)

EnsureDevice ensures a device with the given attrs is present on the system. If a device with the given name already exists, device creation is skipped and the existing device will be used as-is for the subsequent configuration steps. The device is never recreated.

The device's state is set to 'up', L3 forwarding sysctls are applied, and MTU is set.

func RemoveDevice

func RemoveDevice(name string) error

RemoveDevice removes the device with the given name. Returns error if the device exists but was unable to be removed.

func SetupIPIPDevices

func SetupIPIPDevices(logger *slog.Logger, sysctl sysctl.Sysctl, ipv4, ipv6 bool, mtu int) error

SetupIPIPDevices ensures the specified v4 and/or v6 devices are created and configured with their respective sysctls.

Calling this function may result in tunl0 (v4) or ip6tnl0 (v6) fallback interfaces being created as a result of loading the ipip and ip6_tunnel kernel modules by creating cilium_ tunnel interfaces. These are catch-all interfaces for the ipip decapsulation stack. By default, these interfaces will be created in new network namespaces, but Cilium disables this behaviour by setting net.core.fb_tunnels_only_for_init_net = 2.

In versions of Cilium prior to 1.15, the behaviour was as follows:

  • Repurpose the default tunl0 by setting it into collect_md mode and renaming it to cilium_ipip4. Use the interface for production traffic.
  • The same cannot be done for ip6tunl0, as collect_md cannot be enabled on this interface. Leave it unused.
  • Rename sit0 to cilium_sit, if present. This was potentially a mistake, as the sit module is not involved with ip6tnl interfaces.

As of Cilium 1.15, if present, tunl0 is renamed to cilium_tunl and ip6tnl0 is renamed to cilium_ip6tnl. This is to communicate to the user that Cilium has taken control of the encapsulation stack on the node, as it currently doesn't explicitly support sharing it with other tools/CNIs. Fallback devices are left unused for production traffic. Only devices that were explicitly created are used. As of Cilium 1.18, cilium_tunl and cilium_ip6tnl are not created anymore.

Types

type DesiredDevice

type DesiredDevice struct {
	Owner      DeviceOwner       `json:"owner" yaml:"owner"`
	Name       string            `json:"name" yaml:"name"`
	DeviceSpec DesiredDeviceSpec `json:"spec" yaml:"spec"`
	// contains filtered or unexported fields
}

func (*DesiredDevice) Clone

func (dd *DesiredDevice) Clone() *DesiredDevice

func (*DesiredDevice) GetKey

func (dd *DesiredDevice) GetKey() DesiredDeviceKey

func (*DesiredDevice) GetStatus

func (dd *DesiredDevice) GetStatus() reconciler.Status

func (*DesiredDevice) SetStatus

func (dd *DesiredDevice) SetStatus(s reconciler.Status) *DesiredDevice

func (*DesiredDevice) TableHeader

func (dd *DesiredDevice) TableHeader() []string

func (*DesiredDevice) TableRow

func (dd *DesiredDevice) TableRow() []string

func (*DesiredDevice) Validate

func (dd *DesiredDevice) Validate() error

type DesiredDeviceKey

type DesiredDeviceKey struct {
	Owner DeviceOwner
	Name  string
}

func (DesiredDeviceKey) Key

func (k DesiredDeviceKey) Key() index.Key

func (*DesiredDeviceKey) MarshalBinary

func (k *DesiredDeviceKey) MarshalBinary() ([]byte, error)

func (DesiredDeviceKey) String

func (k DesiredDeviceKey) String() string

func (*DesiredDeviceKey) UnmarshalBinary

func (k *DesiredDeviceKey) UnmarshalBinary(data []byte) error

type DesiredDeviceSpec

type DesiredDeviceSpec interface {
	ToNetlink() (netlink.Link, error)
	Properties() string
	MarshalJSON() ([]byte, error)
	MarshalYAML() (any, error)
	// NeedsRecreate reports whether the existing kernel device must be deleted
	// and re-added rather than modified in-place. It is only called when a
	// device with this name already exists.
	//
	// It must return true ONLY when an immutable kernel attribute (e.g. VRF
	// table ID, VLAN ID) actually differs between the desired spec and the
	// existing device. Returning true unconditionally causes a destructive
	// delete+add on every reconcile (including periodic refresh).
	NeedsRecreate(existing netlink.Link) bool
}

type DesiredVLANDeviceSpec

type DesiredVLANDeviceSpec struct {
	Name        string `json:"name" yaml:"name"`
	VLANID      int    `json:"vlanID" yaml:"vlanID"`
	MTU         int    `json:"mtu" yaml:"mtu"`
	ParentName  string `json:"parentName" yaml:"parentName"`
	ParentIndex int    `json:"parentIndex" yaml:"parentIndex"`
}

func (*DesiredVLANDeviceSpec) MarshalJSON

func (d *DesiredVLANDeviceSpec) MarshalJSON() ([]byte, error)

func (*DesiredVLANDeviceSpec) MarshalYAML

func (d *DesiredVLANDeviceSpec) MarshalYAML() (any, error)

func (*DesiredVLANDeviceSpec) NeedsRecreate

func (d *DesiredVLANDeviceSpec) NeedsRecreate(existing netlink.Link) bool

NeedsRecreate reports whether the existing VLAN device must be recreated. The VLAN ID and parent interface are immutable, so a recreate is only needed when one of those differs from the desired spec. Mutable attributes (e.g. MTU) are handled in-place via LinkModify.

func (*DesiredVLANDeviceSpec) Properties

func (d *DesiredVLANDeviceSpec) Properties() string
func (d *DesiredVLANDeviceSpec) ToNetlink() (netlink.Link, error)

type DeviceOwner

type DeviceOwner struct {
	Name string `json:"name" yaml:"name"`
}

type Initializer

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

type ManagerOperations

type ManagerOperations interface {
	// UpsertDevice upserts a desired device into the desired device table.
	UpsertDevice(device DesiredDevice) error
	// UpsertDeviceWait upserts a desired device into the desired device table
	// and waits for the device to be reconciled.
	UpsertDeviceWait(device DesiredDevice, timeout time.Duration) error
	// DeleteDevice deletes a desired device from the desired device table.
	DeleteDevice(device DesiredDevice) error
	// GetOrRegisterOwner gets or registers an owner with the given name.
	GetOrRegisterOwner(name string) DeviceOwner
	// RemoveOwner removes an owner and associated devices with the given owner.
	RemoveOwner(owner DeviceOwner) error
	// RegisterInitializer registers an initializer with the given name and returns
	// the initializer to the caller.
	RegisterInitializer(name string) Initializer
	// FinalizeInitializer should be called by the caller with registered initializer
	// once callers initial sync is completed. Once all initializers are finalized,
	// the reconciler will start initial pruning.
	FinalizeInitializer(initializer Initializer)
}

ManagerOperations is the interface for the desired device reconciler manager

Jump to

Keyboard shortcuts

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