diff --git a/api/v1alpha2/types.go b/api/v1alpha2/types.go index 283cc10eee..6de50a7f21 100644 --- a/api/v1alpha2/types.go +++ b/api/v1alpha2/types.go @@ -94,6 +94,11 @@ type NetworkDeviceSpec struct { // will be connected. NetworkName string `json:"networkName"` + // DeviceName may be used to explicitly assign a name to the network device + // as it exists in the guest operating system. + // +optional + DeviceName string `json:"deviceName,omitempty"` + // DHCP4 is a flag that indicates whether or not to use DHCP for IPv4 // on this device. // If true then IPAddrs should not contain any IPv4 addresses. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml index 9966235ec2..54e3c8a5e9 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml @@ -62,6 +62,11 @@ spec: description: NetworkDeviceSpec defines the network configuration for a virtual machine's network device. properties: + deviceName: + description: DeviceName may be used to explicitly assign a + name to the network device as it exists in the guest operating + system. + type: string dhcp4: description: DHCP4 is a flag that indicates whether or not to use DHCP for IPv4 on this device. If true then IPAddrs diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml index 8d189a9760..a6b2a69d19 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml @@ -177,6 +177,11 @@ spec: description: NetworkDeviceSpec defines the network configuration for a virtual machine's network device. properties: + deviceName: + description: DeviceName may be used to explicitly + assign a name to the network device as it exists + in the guest operating system. + type: string dhcp4: description: DHCP4 is a flag that indicates whether or not to use DHCP for IPv4 on this device. If true diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index a490a70bfe..18f3de97e6 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -328,6 +328,21 @@ network: The above network configuratoin from a machine definition includes two network devices, both using DHCP. This likely causes two default routes to be defined on the guest, meaning it's not possible to determine the default IPv4 address that should be used by Kubernetes. +#### Specifying the ethernet interface device names + +A bug with Cloud-Init Networking Config Version 2 prevents the use of Predicatable Device Names in CentOS and Photon [`583`](https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/issues/583). For this reason CAPV sets devices name to eth*. Should one wish to use alternate interface device names, use the deviceName parameter. For example: + +```yaml +network: + devices: + - networkName: "sddc-cgw-network-5" + deviceName: "ens192" + dhcp4: true + - networkName: "sddc-cgw-network-6" + deviceName: "ens193" + dhcp4: true +``` + ##### Preferring an IP address Another reason a machine with two networks can lead to failure is because the order in which IP addresses are returned externally from a VM is not guaranteed to be the same order as they are when inspected inside the guest. The solution for this is to define a preferred CIDR -- the network segment that contains the IP that the `kubeadm` bootstrap process selected for the API server. For example: diff --git a/pkg/util/constants.go b/pkg/util/constants.go index 173ba9eb12..06f34cd071 100644 --- a/pkg/util/constants.go +++ b/pkg/util/constants.go @@ -26,6 +26,11 @@ network: id{{ $i }}: match: macaddress: "{{ $net.MACAddr }}" + {{- if $net.DeviceName }} + set-name: "{{ $net.DeviceName }}" + {{- else }} + set-name: "eth{{ $i }}" + {{- end }} wakeonlan: true dhcp4: {{ $net.DHCP4 }} dhcp6: {{ $net.DHCP6 }} diff --git a/pkg/util/machines_test.go b/pkg/util/machines_test.go index 340af94488..f21c571d16 100644 --- a/pkg/util/machines_test.go +++ b/pkg/util/machines_test.go @@ -245,6 +245,38 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" + wakeonlan: true + dhcp4: true + dhcp6: false +`, + }, + { + name: "dhcp4+deviceName", + machine: &v1alpha2.VSphereMachine{ + Spec: v1alpha2.VSphereMachineSpec{ + Network: v1alpha2.NetworkSpec{ + Devices: []v1alpha2.NetworkDeviceSpec{ + { + NetworkName: "network1", + MACAddr: "00:00:00:00:00", + DHCP4: true, + DeviceName: "ens192", + }, + }, + }, + }, + }, + expected: ` +instance-id: "test-vm" +local-hostname: "test-vm" +network: + version: 2 + ethernets: + id0: + match: + macaddress: "00:00:00:00:00" + set-name: "ens192" wakeonlan: true dhcp4: true dhcp6: false @@ -274,6 +306,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: false dhcp6: true @@ -304,6 +337,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: true dhcp6: true @@ -335,6 +369,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: false dhcp6: true @@ -376,6 +411,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: false dhcp6: true @@ -425,6 +461,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: true dhcp6: false @@ -435,6 +472,7 @@ network: id1: match: macaddress: "00:00:00:00:01" + set-name: "eth1" wakeonlan: true dhcp4: false dhcp6: true @@ -475,6 +513,7 @@ network: id0: match: macaddress: "00:00:00:00:00" + set-name: "eth0" wakeonlan: true dhcp4: false dhcp6: false @@ -489,6 +528,7 @@ network: id1: match: macaddress: "00:00:00:00:01" + set-name: "eth1" wakeonlan: true dhcp4: false dhcp6: true