Skip to content

Commit 246f804

Browse files
drew-vileswikkyk
authored andcommitted
fix: updating the queue to be pointers
1 parent 6450517 commit 246f804

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

internal/service/vmservice/utils.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,22 @@ func shouldUpdateNetworkDevices(machineScope *scope.MachineScope) bool {
195195
return true
196196
}
197197
}
198-
queues := extractNetworkQueue(net)
199-
if queues != ptr.Deref(v.Queues, 0) {
200-
return true
201-
}
202198

199+
if v.Queues != nil {
200+
queues := extractNetworkQueue(net)
201+
202+
if queues != *v.Queues {
203+
return true
204+
}
205+
}
203206
}
204207

205208
return false
206209
}
207210

208211
// formatNetworkDevice formats a network device config
209212
// example 'virtio,bridge=vmbr0,tag=100,queues=4'.
210-
func formatNetworkDevice(model, bridge string, mtu *int32, vlan *int32, queues int32) string {
213+
func formatNetworkDevice(model, bridge string, mtu *int32, vlan *int32, queues *int32) string {
211214
var components = []string{model, fmt.Sprintf("bridge=%s", bridge)}
212215

213216
if mtu != nil {
@@ -218,8 +221,8 @@ func formatNetworkDevice(model, bridge string, mtu *int32, vlan *int32, queues i
218221
components = append(components, fmt.Sprintf("tag=%d", *vlan))
219222
}
220223

221-
if queues != 0 {
222-
components = append(components, fmt.Sprintf("queues=%d", queues))
224+
if queues != nil {
225+
components = append(components, fmt.Sprintf("queues=%d", *queues))
223226
}
224227

225228
return strings.Join(components, ",")

internal/service/vmservice/vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func reconcileVirtualMachineConfig(ctx context.Context, machineScope *scope.Mach
327327
for _, v := range devices {
328328
vmOptions = append(vmOptions, proxmox.VirtualMachineOption{
329329
Name: string(v.Name),
330-
Value: formatNetworkDevice(ptr.Deref(v.Model, "virtio"), ptr.Deref(v.Bridge, ""), v.MTU, v.VLAN, ptr.Deref(v.Queues, 0)),
330+
Value: formatNetworkDevice(ptr.Deref(v.Model, "virtio"), ptr.Deref(v.Bridge, ""), v.MTU, v.VLAN, v.Queues),
331331
})
332332
}
333333
}

internal/service/vmservice/vm_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ func TestReconcileVirtualMachineConfig_ApplyConfig(t *testing.T) {
449449
proxmox.VirtualMachineOption{Name: optionCores, Value: *machineScope.ProxmoxMachine.Spec.NumCores},
450450
proxmox.VirtualMachineOption{Name: optionMemory, Value: *machineScope.ProxmoxMachine.Spec.MemoryMiB},
451451
proxmox.VirtualMachineOption{Name: optionDescription, Value: machineScope.ProxmoxMachine.Spec.Description},
452-
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", ptr.To[int32](1500), nil, 0)},
453-
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", ptr.To[int32](1500), nil, 0)},
452+
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", ptr.To[int32](1500), nil, nil)},
453+
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", ptr.To[int32](1500), nil, nil)},
454454
}
455455

456456
proxmoxClient.EXPECT().ConfigureVM(context.Background(), vm, expectedOptions...).Return(task, nil).Once()
@@ -624,8 +624,8 @@ func TestReconcileVirtualMachineConfigVLAN(t *testing.T) {
624624
proxmox.VirtualMachineOption{Name: optionSockets, Value: *machineScope.ProxmoxMachine.Spec.NumSockets},
625625
proxmox.VirtualMachineOption{Name: optionCores, Value: *machineScope.ProxmoxMachine.Spec.NumCores},
626626
proxmox.VirtualMachineOption{Name: optionMemory, Value: *machineScope.ProxmoxMachine.Spec.MemoryMiB},
627-
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", nil, ptr.To(int32(100)), 0)},
628-
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", nil, ptr.To(int32(100)), 0)},
627+
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", nil, ptr.To(int32(100)), nil)},
628+
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", nil, ptr.To(int32(100)), nil)},
629629
}
630630

631631
proxmoxClient.EXPECT().ConfigureVM(context.TODO(), vm, expectedOptions...).Return(task, nil).Once()
@@ -655,8 +655,8 @@ func TestReconcileVirtualMachineConfigQueue(t *testing.T) {
655655
proxmox.VirtualMachineOption{Name: optionSockets, Value: *machineScope.ProxmoxMachine.Spec.NumSockets},
656656
proxmox.VirtualMachineOption{Name: optionCores, Value: *machineScope.ProxmoxMachine.Spec.NumCores},
657657
proxmox.VirtualMachineOption{Name: optionMemory, Value: *machineScope.ProxmoxMachine.Spec.MemoryMiB},
658-
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", nil, ptr.To(int32(100)), 4)},
659-
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", nil, ptr.To(int32(100)), 4)},
658+
proxmox.VirtualMachineOption{Name: "net0", Value: formatNetworkDevice("virtio", "vmbr0", nil, ptr.To(int32(100)), ptr.To(int32(4)))},
659+
proxmox.VirtualMachineOption{Name: "net1", Value: formatNetworkDevice("virtio", "vmbr1", nil, ptr.To(int32(100)), ptr.To(int32(4)))},
660660
}
661661

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

0 commit comments

Comments
 (0)