Skip to content

Commit

Permalink
feat: implement setting mtu for virtio network device
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasl0st committed Dec 17, 2023
1 parent a1666e4 commit 7b6b2e7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/proxmoxmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ type NetworkDevice struct {
// +kubebuilder:validation:Enum=e1000;virtio;rtl8139;vmxnet3
// +kubebuilder:default=virtio
Model *string `json:"model,omitempty"`

// MTU is the network device Maximum Transmission Unit.
// Only works with virtio Model.
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1500
MTU *uint16 `json:"mtu,omitempty"`
}

// AdditionalNetworkDevice the definition of a Proxmox network device.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ spec:
- rtl8139
- vmxnet3
type: string
mtu:
default: 1500
description: MTU is the network device Maximum Transmission
Unit. Only works with virtio Model.
minimum: 1
type: integer
name:
description: Name is the network device name. must be unique
within the virtual machine and different from the primary
Expand Down Expand Up @@ -245,6 +251,12 @@ spec:
- rtl8139
- vmxnet3
type: string
mtu:
default: 1500
description: MTU is the network device Maximum Transmission
Unit. Only works with virtio Model.
minimum: 1
type: integer
required:
- bridge
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ spec:
- rtl8139
- vmxnet3
type: string
mtu:
default: 1500
description: MTU is the network device Maximum Transmission
Unit. Only works with virtio Model.
minimum: 1
type: integer
name:
description: Name is the network device name. must
be unique within the virtual machine and different
Expand Down Expand Up @@ -265,6 +271,12 @@ spec:
- rtl8139
- vmxnet3
type: string
mtu:
default: 1500
description: MTU is the network device Maximum Transmission
Unit. Only works with virtio Model.
minimum: 1
type: integer
required:
- bridge
type: object
Expand Down
4 changes: 2 additions & 2 deletions internal/service/vmservice/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func shouldUpdateNetworkDevices(machineScope *scope.MachineScope) bool {

// formatNetworkDevice formats a network device config
// example 'virtio,bridge=vmbr0'.
func formatNetworkDevice(model, bridge string) string {
return fmt.Sprintf("%s,bridge=%s", model, bridge)
func formatNetworkDevice(model, bridge string, mtu uint16) string {
return fmt.Sprintf("%s,bridge=%s,mtu=%d", model, bridge, mtu)
}

// extractMACAddress returns the macaddress out of net device input e.g. virtio=A6:23:64:4D:84:CB,bridge=vmbr1.
Expand Down
10 changes: 7 additions & 3 deletions internal/service/vmservice/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,20 @@ func reconcileVirtualMachineConfig(ctx context.Context, machineScope *scope.Mach
if machineScope.ProxmoxMachine.Spec.Network != nil && shouldUpdateNetworkDevices(machineScope) {
// adding the default network device.
vmOptions = append(vmOptions, proxmox.VirtualMachineOption{
Name: infrav1alpha1.DefaultNetworkDevice,
Value: formatNetworkDevice(*machineScope.ProxmoxMachine.Spec.Network.Default.Model, machineScope.ProxmoxMachine.Spec.Network.Default.Bridge),
Name: infrav1alpha1.DefaultNetworkDevice,
Value: formatNetworkDevice(
*machineScope.ProxmoxMachine.Spec.Network.Default.Model,
machineScope.ProxmoxMachine.Spec.Network.Default.Bridge,
*machineScope.ProxmoxMachine.Spec.Network.Default.MTU,
),
})

// handing additional network devices.
devices := machineScope.ProxmoxMachine.Spec.Network.AdditionalDevices
for _, v := range devices {
vmOptions = append(vmOptions, proxmox.VirtualMachineOption{
Name: v.Name,
Value: formatNetworkDevice(*v.Model, v.Bridge),
Value: formatNetworkDevice(*v.Model, v.Bridge, *v.MTU),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/vmservice/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func TestReconcileVirtualMachineConfig_ApplyConfig(t *testing.T) {
proxmox.VirtualMachineOption{Name: optionSockets, Value: machineScope.ProxmoxMachine.Spec.NumSockets},
proxmox.VirtualMachineOption{Name: optionCores, Value: machineScope.ProxmoxMachine.Spec.NumCores},
proxmox.VirtualMachineOption{Name: optionMemory, Value: machineScope.ProxmoxMachine.Spec.MemoryMiB},
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0")},
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1")},
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", 1500)},
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", 1500)},
}

proxmoxClient.EXPECT().ConfigureVM(context.TODO(), vm, expectedOptions...).Return(task, nil).Once()
Expand Down

0 comments on commit 7b6b2e7

Please sign in to comment.