util

package
v0.1.0-latest-stable Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NetplanConfigFilePrefix = "/etc/netplan/99-dpu"
	BridgeMTUNetplanFile    = "/etc/netplan/99-dpf-oob-bridge-mtu.yaml"
	// LegacyBridgeMTUNetplanFile is the old bridge MTU netplan file path used prior to bridge-name configurability.
	LegacyBridgeMTUNetplanFile = "/etc/netplan/99-br-dpu-interfaces-mtu.yaml"
)
View Source
const (
	DPFNamespace          = "dpf-operator-system"
	MaximumHostNameLength = 48
	NodeNameEnv           = "NODE_NAME"
	K8sNodeNameEnv        = "KUBERNETES_NODE_NAME"
	K8sPodNamespaceEnv    = "POD_NAMESPACE"

	// CATrustBundleDir is the directory where the dpf CA trust bundle ConfigMap is mounted into the
	// HostAgent (DMS) Pod. It is a non-subPath volume so kubelet keeps it in sync as the bundle is
	// updated during CA rotation.
	CATrustBundleDir = "/etc/dpf/ca"
	// CATrustBundleFile is the full path to the CA trust bundle PEM inside the HostAgent Pod. The
	// file name matches the ConfigMap data key (operatorv1.CATrustBundleKey = "ca.crt").
	CATrustBundleFile = CATrustBundleDir + "/ca.crt"
)
View Source
const (
	DeviceIDBlueField2 = "0xa2d6"
	DeviceIDBlueField3 = "0xa2dc"
	DeviceIDBlueField4 = "0xa2df"

	MLX5CoreDriver = "mlx5_core"
)
View Source
const (
	// SysFSRoot is the path to the sysfs directory.
	SysFSRoot = "/sys"
)

Mutable paths for sysfs directories - can be overridden in tests for mocking

Variables

View Source
var OOBBridge = &oobBridgeConfig{name: operatorv1.DefaultDPUNodeOOBBridgeName}

OOBBridge holds the process-wide OOB bridge name synced from DPFOperatorConfig.

Functions

func AddVFToBridge

func AddVFToBridge(vfName, bridgeName string) error

func ApplyNetplan

func ApplyNetplan() error

ApplyNetplan applies the netplan configuration.

func ConfigureBridgeMTU

func ConfigureBridgeMTU(controlPlaneMTU int) (bool, error)

ConfigureBridgeMTU configures the bridge and its member interfaces MTU using netplan. Returns (needsApply, error) where needsApply indicates if changes are needed.

func ConfigureBridgeMTUForBridge

func ConfigureBridgeMTUForBridge(bridgeName string, controlPlaneMTU int) (bool, error)

ConfigureBridgeMTUForBridge configures bridge and member MTU for a specific bridge via netplan. Returns (needsApply, error) where needsApply indicates if changes are needed.

func ConfigurePFs

func ConfigurePFs(pciAddress string, portConfigs []PortConfig) (bool, error)

ConfigurePFs configures the PF network interfaces using netplan. Returns (needsApply, error) where needsApply indicates if changes are needed.

func CreateBridgeIfNotExists

func CreateBridgeIfNotExists(bridgeName string) (netlink.Link, error)

func GetBridgeMembers

func GetBridgeMembers(bridgeName string) ([]string, error)

GetBridgeMembers returns the names of all member interfaces of the specified bridge

func GetCurrentMTU

func GetCurrentMTU(interfaceName string) (int, error)

GetCurrentMTU returns the current MTU of the specified interface

func GetDPUMode

func GetDPUMode(ctx context.Context, pciAddress string) (provisioningv1.DpuModeType, error)

func GetNodeName

func GetNodeName() (string, bool, error)

GetNodeName returns the name of the DPUNode. If the hostname is longer than MaximumHostNameLength, it is truncated and true is returned.

func IsDHCPConfigured

func IsDHCPConfigured(interfaceName string) (bool, error)

IsDHCPConfigured checks if DHCP is configured for the interface. It uses a two-tier approach: 1. First checks runtime state via networkctl (if DHCP obtained an address, it's definitely configured) 2. If no address found, checks the configuration file (DHCP may be configured but no address yet)

func IsVF

func IsVF(interfaceName string) bool

IsVF returns true if the given network interface is a PCI Virtual Function.

func ReadDeviceSerialNumberFromVPD

func ReadDeviceSerialNumberFromVPD(sysFSRoot string, pciAddress string) (string, error)

ReadDeviceSerialNumberFromVPD reads the serial number from a PCI device's VPD data via sysfs configuration space. The pciAddress should be in format like "0000:4d:00.0"

func RemoveVFFromBridge

func RemoveVFFromBridge(vfName string) error

func RunBash

func RunBash(cmdStr string) (stdout, stderr bytes.Buffer, err error)

func SetDPUMode

func SetDPUMode(pciAddress string) error

func SetLinkMTU

func SetLinkMTU(linkName string, mtu int) error

Types

type ConditionBuilder

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

func NewCondition

func NewCondition(condType string) *ConditionBuilder

func (*ConditionBuilder) Failure

func (b *ConditionBuilder) Failure(err error, reason string) *ConditionSetter

func (*ConditionBuilder) Success

func (b *ConditionBuilder) Success(message string) *ConditionSetter

type ConditionSetter

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

ConditionSetter is a struct that sets a condition on a list of conditions. todo: move the setter and builder to controller util and substitute the existing condition functions

func (*ConditionSetter) Set

func (s *ConditionSetter) Set(conditions *[]metav1.Condition)

type Device

type Device struct {
	// Address is the PCI address of the device after truncating the function number, e.g. "0000:4d:00"
	Address string
	// SerialNumber is the serial number of the device
	SerialNumber string
	// NumOfPFs is the number of PFs of the device
	NumOfPFs int
}

func DiscoverDPUs

func DiscoverDPUs(sysFSRoot string) ([]Device, error)

func (Device) PFPCIAddress

func (d Device) PFPCIAddress(pf int) string

PFPCIAddress returns the full PCI BDF for a PF index on this device.

func (Device) PFPCIAddresses

func (d Device) PFPCIAddresses() []string

PFPCIAddresses returns full PCI BDFs for discovered PFs in deterministic order.

type PCIHelper

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

func NewPCIHelper

func NewPCIHelper(pciAddress string) *PCIHelper

func (*PCIHelper) BindDriver

func (h *PCIHelper) BindDriver(driverName string) error

BindDriver writes the device's BDF to /sys/bus/pci/drivers/<driverName>/bind, causing the kernel to attempt to bind the named driver to the device. No-op if the named driver is already bound. Returns an error if a *different* driver is bound — silently overriding could disrupt setups that intentionally bound the device to another driver (e.g. vfio-pci for passthrough). May block while the kernel runs the driver's probe routine; if the device's firmware is in pre-init, the bind can return -ETIMEDOUT after the kernel's wait_fw_init timeout.

func (*PCIHelper) BoundDriver

func (h *PCIHelper) BoundDriver() (string, error)

BoundDriver returns the name of the driver currently bound to the device, or empty string if no driver is bound.

func (*PCIHelper) DeviceID

func (h *PCIHelper) DeviceID() (string, error)

DeviceID returns the normalized PCI device ID from sysfs.

func (*PCIHelper) GetMTU

func (h *PCIHelper) GetMTU() (int, error)

GetMTU returns the current MTU of the PF interface

func (*PCIHelper) InterfaceName

func (h *PCIHelper) InterfaceName() (string, error)

InterfaceName returns the name of the network interface of the device.

func (*PCIHelper) IsDPU

func (h *PCIHelper) IsDPU() (bool, error)

IsDPU checks if the device is a DPU.

func (*PCIHelper) PF

func (h *PCIHelper) PF(pf int) *PCIHelper

func (*PCIHelper) Path

func (h *PCIHelper) Path() string

Path returns the full path to the PCI device.

func (*PCIHelper) RebindDriver

func (h *PCIHelper) RebindDriver(ctx context.Context, driverName string) error

RebindDriver unbinds and rebinds a PF to driverName, then waits until a netdev appears. Callers should pass a ctx with a deadline; if none is set, waitForNetdev falls back to a 2-minute timeout so a missing netdev cannot poll forever.

func (*PCIHelper) SerialNumber

func (h *PCIHelper) SerialNumber() (string, error)

func (*PCIHelper) SetNumOfVFs

func (h *PCIHelper) SetNumOfVFs(num int) error

func (*PCIHelper) SetSysFS

func (h *PCIHelper) SetSysFS(newPath string) *PCIHelper

func (*PCIHelper) UnbindDriver

func (h *PCIHelper) UnbindDriver() error

UnbindDriver removes the current driver binding for this PCI device.

func (*PCIHelper) VF

func (h *PCIHelper) VF(vf int) *PCIHelper

type PortConfig

type PortConfig struct {
	// PortNumber identifies the port (0 for P0, 1 for P1, etc.)
	PortNumber int32 `json:"portNumber"`
	// MTU is the MTU value for the port. nil means "no configuration requested, keep current"
	MTU *int32 `json:"mtu,omitempty"`
	// DHCP configuration for the port. nil when no configuration requested
	DHCP *bool `json:"dhcp,omitempty"`
}

PortConfig holds the configuration for a specific network port

type RshimInfo

type RshimInfo struct {
	// RshimName is the rshim device name (e.g., "rshim0", "rshim1")
	RshimName string
	// SecureBootEnabled indicates UEFI Secure Boot status (nil if not found in output)
	SecureBootEnabled *bool
	// RawOutput contains the full output from rshim for additional parsing if needed
	RawOutput string
}

RshimInfo contains comprehensive information from querying a rshim device with DISPLAY_LEVEL 2.

func QueryRshimByPCI

func QueryRshimByPCI(pciAddress string) (*RshimInfo, error)

QueryRshimByPCI is a convenience wrapper around RshimQuerier.QueryByPCI for backward compatibility. It uses the default RunBash implementation for bash execution.

For testing with mocked bash commands, use RshimQuerier directly with an injected runBash function.

type RshimQuerier

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

RshimQuerier provides methods for querying rshim devices with injectable bash execution for testing.

func (*RshimQuerier) QueryByPCI

func (r *RshimQuerier) QueryByPCI(pciAddress string) (*RshimInfo, error)

QueryByPCI finds the rshim device for a given PCI address and queries it with DISPLAY_LEVEL 2. This is the single comprehensive method for all rshim operations to avoid duplication.

DISPLAY_LEVEL 2 returns all available information including:

  • PCI address (for device matching)
  • UEFI Secure Boot status
  • Firmware version, BIOS version, etc.

Args:

  • pciAddress: PCI address of the DPU (e.g., "0000:4d:00")

Returns:

  • RshimInfo: Comprehensive information from the rshim device
  • error: Any error encountered during discovery/query

Usage examples:

  • Secure Boot detection: Check info.SecureBootEnabled
  • General rshim lookup: Use info.RshimName

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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