Skip to content

Commit

Permalink
Merge pull request #707 from MnrGreg/using_cloudinit_set-name
Browse files Browse the repository at this point in the history
Set network interface name with cloud-init set-name
  • Loading branch information
k8s-ci-robot authored Dec 24, 2019
2 parents 1420004 + 1ba72c4 commit d7f1a21
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -274,6 +306,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -304,6 +337,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: true
dhcp6: true
Expand Down Expand Up @@ -335,6 +369,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -376,6 +411,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -425,6 +461,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: true
dhcp6: false
Expand All @@ -435,6 +472,7 @@ network:
id1:
match:
macaddress: "00:00:00:00:01"
set-name: "eth1"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down Expand Up @@ -475,6 +513,7 @@ network:
id0:
match:
macaddress: "00:00:00:00:00"
set-name: "eth0"
wakeonlan: true
dhcp4: false
dhcp6: false
Expand All @@ -489,6 +528,7 @@ network:
id1:
match:
macaddress: "00:00:00:00:01"
set-name: "eth1"
wakeonlan: true
dhcp4: false
dhcp6: true
Expand Down

0 comments on commit d7f1a21

Please sign in to comment.