diff --git a/api/v1alpha1/proxmoxmachine_types.go b/api/v1alpha1/proxmoxmachine_types.go index c843dd3a..1bcf35bb 100644 --- a/api/v1alpha1/proxmoxmachine_types.go +++ b/api/v1alpha1/proxmoxmachine_types.go @@ -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. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index a51b4668..3dd9b3e7 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -98,6 +98,11 @@ func (in *NetworkDevice) DeepCopyInto(out *NetworkDevice) { *out = new(string) **out = **in } + if in.MTU != nil { + in, out := &in.MTU, &out.MTU + *out = new(uint16) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDevice. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml index 14dc44cd..7ef73613 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml @@ -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 @@ -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 diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml index 180655aa..a3de843f 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml @@ -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 @@ -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 diff --git a/internal/service/vmservice/utils.go b/internal/service/vmservice/utils.go index f0935f01..90bd0bbd 100644 --- a/internal/service/vmservice/utils.go +++ b/internal/service/vmservice/utils.go @@ -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. diff --git a/internal/service/vmservice/vm.go b/internal/service/vmservice/vm.go index 978c301d..75a0da15 100644 --- a/internal/service/vmservice/vm.go +++ b/internal/service/vmservice/vm.go @@ -191,8 +191,12 @@ 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. @@ -200,7 +204,7 @@ func reconcileVirtualMachineConfig(ctx context.Context, machineScope *scope.Mach 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), }) } } diff --git a/internal/service/vmservice/vm_test.go b/internal/service/vmservice/vm_test.go index 3965c295..ca58b035 100644 --- a/internal/service/vmservice/vm_test.go +++ b/internal/service/vmservice/vm_test.go @@ -160,11 +160,11 @@ func TestReconcileVirtualMachineConfig_ApplyConfig(t *testing.T) { machineScope.ProxmoxMachine.Spec.NumCores = 4 machineScope.ProxmoxMachine.Spec.MemoryMiB = 16 * 1024 machineScope.ProxmoxMachine.Spec.Network = &infrav1alpha1.NetworkSpec{ - Default: &infrav1alpha1.NetworkDevice{Bridge: "vmbr0", Model: ptr.To("virtio")}, + Default: &infrav1alpha1.NetworkDevice{Bridge: "vmbr0", Model: ptr.To("virtio"), MTU: ptr.To(uint16(1500))}, AdditionalDevices: []infrav1alpha1.AdditionalNetworkDevice{ { Name: "net1", - NetworkDevice: infrav1alpha1.NetworkDevice{Bridge: "vmbr1", Model: ptr.To("virtio")}, + NetworkDevice: infrav1alpha1.NetworkDevice{Bridge: "vmbr1", Model: ptr.To("virtio"), MTU: ptr.To(uint16(1500))}, }, }, } @@ -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()