network

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 26 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"
)

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 goctx.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 goctx.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 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 NormalizeNetplanMac

func NormalizeNetplanMac(mac string) string

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

func ResolveBackingPostPlacement

func ResolveBackingPostPlacement(
	ctx goctx.Context,
	vimClient *vim25.Client,
	clusterMoRef vimtypes.ManagedObjectReference,
	results *NetworkInterfaceResults) (bool, error)

ResolveBackingPostPlacement fixes up the backings where we did not know the CCR until after placement. This should be called if CreateAndWaitForNetworkInterfaces() was called with a nil clusterMoRef. Returns true if a backing was resolved, so the ConfigSpec needs to be updated.

func VPCCRName added in v1.8.6

func VPCCRName(vmName, networkName, interfaceName string) string

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

Types

type Netplan

type Netplan struct {
	Version   int                        `yaml:"version,omitempty"`
	Ethernets map[string]NetplanEthernet `yaml:"ethernets,omitempty"`
}

Netplan representation described in https://via.vmw.com/cloud-init-netplan // FIXME: 404.

func NetPlanCustomization

func NetPlanCustomization(result NetworkInterfaceResults) (*Netplan, error)

type NetplanEthernet

type NetplanEthernet struct {
	Match       NetplanEthernetMatch      `yaml:"match,omitempty"`
	SetName     string                    `yaml:"set-name,omitempty"`
	Dhcp4       bool                      `yaml:"dhcp4,omitempty"`
	Dhcp6       bool                      `yaml:"dhcp6,omitempty"`
	Addresses   []string                  `yaml:"addresses,omitempty"`
	Gateway4    string                    `yaml:"gateway4,omitempty"`
	Gateway6    string                    `yaml:"gateway6,omitempty"`
	MTU         int64                     `yaml:"mtu,omitempty"`
	Nameservers NetplanEthernetNameserver `yaml:"nameservers,omitempty"`
	Routes      []NetplanEthernetRoute    `yaml:"routes,omitempty"`
}

type NetplanEthernetMatch

type NetplanEthernetMatch struct {
	MacAddress string `yaml:"macaddress,omitempty"`
}

type NetplanEthernetNameserver

type NetplanEthernetNameserver struct {
	Addresses []string `yaml:"addresses,omitempty"`
	Search    []string `yaml:"search,omitempty"`
}

type NetplanEthernetRoute

type NetplanEthernetRoute struct {
	To     string `yaml:"to"`
	Via    string `yaml:"via"`
	Metric int32  `yaml:"metric,omitempty"`
}

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 {
	IPConfigs  []NetworkInterfaceIPConfig
	MacAddress string
	ExternalID string
	NetworkID  string
	Backing    object.NetworkReference

	Device vimtypes.BaseVirtualDevice

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

type NetworkInterfaceResults

type NetworkInterfaceResults struct {
	Results []NetworkInterfaceResult
}

func CreateAndWaitForNetworkInterfaces

func CreateAndWaitForNetworkInterfaces(
	vmCtx context.VirtualMachineContextA2,
	client ctrlruntime.Client,
	vimClient *vim25.Client,
	finder *find.Finder,
	clusterMoRef *vimtypes.ManagedObjectReference,
	interfaces []vmopv1.VirtualMachineNetworkInterfaceSpec) (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.
  • Both NCP and NetOP 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 (BMV: need to double-check that field meets k8s name requirements) 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.
  • Instead of CreateOrUpdate, use CreateOrPatch to lessen the odds of blowing away any new fields.

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