network

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// VMNameLabel is the label put on a network interface CR that identifies its VM by name.
	VMNameLabel = pkg.VMOperatorKey + "/vm-name"
	// VMInterfaceNameLabel is the label put on the network interface CR identifies its name
	// in the VM network interface spec.
	VMInterfaceNameLabel = pkg.VMOperatorKey + "/vm-interface-name"
)
View Source
const (
	// VPCInterfaceRestoredAnnotation is the annotation that NSX puts on the VM
	// when an interface is restored. The value of the annotation is the interface
	// names of the restored interfaces, like "eth0, eth2".
	VPCInterfaceRestoredAnnotation = "nsx/reconfigure-nic"
)

Variables

View Source
var (
	// RetryTimeout is var so tests can change it to shorten tests until we get rid of the poll.
	RetryTimeout = 15 * time.Second
)

Functions

func ApplyInterfaceResultToVirtualEthCard

func ApplyInterfaceResultToVirtualEthCard(
	ctx context.Context,
	ethCard *vimtypes.VirtualEthernetCard,
	result *NetworkInterfaceResult) error

ApplyInterfaceResultToVirtualEthCard applies the interface result from the NetOP/NCP provider to an existing Ethernet device from the class ConfigSpec.

func CreateDefaultEthCard

func CreateDefaultEthCard(
	ctx context.Context,
	result *NetworkInterfaceResult) (vimtypes.BaseVirtualDevice, error)

CreateDefaultEthCard creates a default Ethernet card attached to the backing. This is used when the VM Class ConfigSpec does not have a device entry for a VM Spec network interface, so we need a new device.

func FindMatchingEthCard added in v1.10.0

func FindMatchingEthCard(
	currentEthCards object.VirtualDeviceList,
	ethCard vimtypes.BaseVirtualEthernetCard) int

func ListNetworkInterfaces added in v1.10.0

func ListNetworkInterfaces(
	vmCtx pkgctx.VirtualMachineContext,
	client ctrlclient.Client,
) ([]ctrlclient.Object, error)

ListNetworkInterfaces lists all the network interfaces for the VM.

func ListOrphanedNetworkInterfaces added in v1.10.0

func ListOrphanedNetworkInterfaces(
	vmCtx pkgctx.VirtualMachineContext,
	client ctrlclient.Client,
	results *NetworkInterfaceResults,
) error

ListOrphanedNetworkInterfaces gets the interfaces for a VM that are not referenced by the VM Spec.Network.Interfaces.

func MapEthernetDevicesToSpecIdx added in v1.10.0

func MapEthernetDevicesToSpecIdx(
	vmCtx pkgctx.VirtualMachineContext,
	client ctrlclient.Client,
	vmMO mo.VirtualMachine) map[int32]int

MapEthernetDevicesToSpecIdx maps the VM's ethernet devices to the corresponding entry in the VM's Spec.

func NCPCRName

func NCPCRName(vmName, networkName, interfaceName string, isV1A1 bool) string

NCPCRName returns the name to be used for the NCP VirtualNetworkInterface CR.

func NetOPCRName

func NetOPCRName(vmName, networkName, interfaceName string, isV1A1 bool) string

NetOPCRName returns the name to be used for the NetOP NetworkInterface CR.

func NetPlanCustomization

func NetPlanCustomization(result NetworkInterfaceResults) (*netplan.Network, error)

func NormalizeNetplanMac

func NormalizeNetplanMac(mac string) string

NormalizeNetplanMac normalizes the mac address format to one compatible with netplan.

func ReconcileNetworkInterfaces added in v1.10.0

func ReconcileNetworkInterfaces(
	ctx context.Context,
	results *NetworkInterfaceResults,
	currentEthCards object.VirtualDeviceList,
) ([]vimtypes.BaseVirtualDeviceConfigSpec, error)

func SetNetworkInterfaceOwnerRef added in v1.10.0

func SetNetworkInterfaceOwnerRef(vm *vmopv1.VirtualMachine, object metav1.Object, scheme *runtime.Scheme) error

func VPCCRName

func VPCCRName(vmName, networkName, interfaceName string) string

VPCCRName returns the name to be used for the VPC SubnetPort CR.

func VPCPostRestoreBackingFixup added in v1.10.0

func VPCPostRestoreBackingFixup(
	vmCtx pkgctx.VirtualMachineContext,
	currentEthCards []vimtypes.BaseVirtualDevice,
	networkResults NetworkInterfaceResults) ([]vimtypes.BaseVirtualDeviceConfigSpec, error)

Types

type NetworkInterfaceIPConfig

type NetworkInterfaceIPConfig struct {
	IPCIDR  string // IP address in CIDR notation e.g. 192.168.10.42/24
	IsIPv4  bool
	Gateway string
}

type NetworkInterfaceResult

type NetworkInterfaceResult struct {
	ObjectName string
	IPConfigs  []NetworkInterfaceIPConfig
	MacAddress string
	ExternalID string
	NetworkID  string
	Backing    object.NetworkReference

	Device    vimtypes.BaseVirtualDevice
	DeviceKey int32

	// Fields from the InterfaceSpec used later during customization.
	Name            string
	GuestDeviceName string
	NoIPAM          bool
	DHCP4           bool
	DHCP6           bool
	MTU             int64
	Nameservers     []string
	SearchDomains   []string
	Routes          []NetworkInterfaceRoute
}

type NetworkInterfaceResults

type NetworkInterfaceResults struct {
	Results                   []NetworkInterfaceResult
	UpdatedEthCards           bool
	OrphanedNetworkInterfaces []ctrlclient.Object
}

func CreateAndWaitForNetworkInterfaces

func CreateAndWaitForNetworkInterfaces(
	vmCtx pkgctx.VirtualMachineContext,
	client ctrlclient.Client,
	vimClient *vim25.Client,
	finder *find.Finder,
	clusterMoRef *vimtypes.ManagedObjectReference,
	networkSpec *vmopv1.VirtualMachineNetworkSpec) (NetworkInterfaceResults, error)

CreateAndWaitForNetworkInterfaces creates the appropriate CRs for the VM's network interfaces, and then waits for them to be reconciled by NCP (NSX-T) or NetOP (VDS).

Networking has always been kind of a pain and clunky for us, and unfortunately this code suffers gotchas and other not-so-great limitations.

  • Historically, this code used wait.PollImmediate() and we continue to do so here, but eventually we should Watch() these resources. Note though, that in the very common case, the CR is reconciled before our poll timeout, so that does save us from bailing out of the Reconcile.
  • NCP, NetOP and VPC CR Status inform us of the backing and IPAM info. However, for our InterfaceSpec we allow for DHCP but neither NCP nor NetOP has a way for us to mark the CR to don't do IPAM or to check DHCP is even enabled on the network. So this burns an IP, and the user must know that DHCP is actually configured.
  • CR naming has mostly been working by luck, and sometimes didn't offer very good discoverability. Here, with v1a2 we now have a "name" field in our InterfaceSpec, so we use that. A longer term option is to use GenerateName to ensure a unique name, and then client.List() and filter by the OwnerRef to find the VM's network CRs, and to annotate the CRs to help identify which VM InterfaceSpec it corresponds to. Note that for existing v1a1 VMs we may need to add legacy name support here to find their interface CRs.

type NetworkInterfaceRoute

type NetworkInterfaceRoute struct {
	To     string
	Via    string
	Metric int32
}

Jump to

Keyboard shortcuts

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