Skip to content

Commit 35baf62

Browse files
committed
neonvm-controller: Remove support for DIMM slots (#1070)
This is part 1 of 2 for removing DIMM slots support and completing our transition to using virtio-mem instead (ref #1060). With this change, neonvm-controller will always assume that VMs are using virtio-mem. The only checks exist at the top of the reconcile functions, making sure that this is indeed the case. The fields still exist in the CRD (although the're marked as deprecated), so that rollback of this change is still sound. neonvm-runner also retains support for both memory providers, so that custom neonvm-runner images continue to work for at least one version across the change.
1 parent c67c842 commit 35baf62

28 files changed

+45
-1118
lines changed

neonvm-controller/cmd/main.go

-8
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func main() {
9797
var disableRunnerCgroup bool
9898
var defaultCpuScalingMode vmv1.CpuScalingMode
9999
var qemuDiskCacheSettings string
100-
var defaultMemoryProvider vmv1.MemoryProvider
101100
var memhpAutoMovableRatio string
102101
var failurePendingPeriod time.Duration
103102
var failingRefreshInterval time.Duration
@@ -137,7 +136,6 @@ func main() {
137136
flag.Func("default-cpu-scaling-mode", "Set default cpu scaling mode to use for new VMs", defaultCpuScalingMode.FlagFunc)
138137
flag.BoolVar(&disableRunnerCgroup, "disable-runner-cgroup", false, "Disable creation of a cgroup in neonvm-runner for fractional CPU limiting")
139138
flag.StringVar(&qemuDiskCacheSettings, "qemu-disk-cache-settings", "cache=none", "Set neonvm-runner's QEMU disk cache settings")
140-
flag.Func("default-memory-provider", "Set default memory provider to use for new VMs", defaultMemoryProvider.FlagFunc)
141139
flag.StringVar(&memhpAutoMovableRatio, "memhp-auto-movable-ratio", "301", "For virtio-mem, set VM kernel's memory_hotplug.auto_movable_ratio")
142140
flag.DurationVar(&failurePendingPeriod, "failure-pending-period", 1*time.Minute,
143141
"the period for the propagation of reconciliation failures to the observability instruments")
@@ -148,11 +146,6 @@ func main() {
148146
"Otherwise, the outdated pod might be left to terminate, while the new one is already running.")
149147
flag.Parse()
150148

151-
if defaultMemoryProvider == "" {
152-
fmt.Fprintln(os.Stderr, "missing required flag '-default-memory-provider'")
153-
os.Exit(1)
154-
}
155-
156149
logConfig := zap.NewProductionConfig()
157150
logConfig.Sampling = nil // Disabling sampling; it's enabled by default for zap's production configs.
158151
logConfig.Level.SetLevel(zap.InfoLevel)
@@ -197,7 +190,6 @@ func main() {
197190
MaxConcurrentReconciles: concurrencyLimit,
198191
SkipUpdateValidationFor: skipUpdateValidationFor,
199192
QEMUDiskCacheSettings: qemuDiskCacheSettings,
200-
DefaultMemoryProvider: defaultMemoryProvider,
201193
MemhpAutoMovableRatio: memhpAutoMovableRatio,
202194
FailurePendingPeriod: failurePendingPeriod,
203195
FailingRefreshInterval: failingRefreshInterval,

neonvm-controller/deployment.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ spec:
6060
# * cache.direct=on - use O_DIRECT (don't abuse host's page cache!)
6161
# * cache.no-flush=on - ignores disk flush operations (not needed; our disks are ephemeral)
6262
- "--qemu-disk-cache-settings=cache.writeback=on,cache.direct=on,cache.no-flush=on"
63-
- "--default-memory-provider=VirtioMem"
6463
- "--memhp-auto-movable-ratio=801" # for virtio-mem, set memory_hotplug.auto_movable_ratio=801
6564
- "--failure-pending-period=1m"
6665
- "--failing-refresh-interval=15s"

neonvm/apis/neonvm/v1/virtualmachine_types.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ type Guest struct {
221221
MemorySlotSize resource.Quantity `json:"memorySlotSize"`
222222
// +optional
223223
MemorySlots MemorySlots `json:"memorySlots"`
224+
// Deprecated: MemoryProvider is ignored and always interpreted as equal to VirtioMem.
224225
// +optional
225226
MemoryProvider *MemoryProvider `json:"memoryProvider,omitempty"`
226227
// +optional
@@ -248,18 +249,11 @@ type Guest struct {
248249

249250
const virtioMemBlockSizeBytes = 8 * 1024 * 1024 // 8 MiB
250251

251-
// ValidateForMemoryProvider returns an error iff the guest memory settings are invalid for the
252-
// MemoryProvider.
253-
//
254-
// This is used in two places. First, to validate VirtualMachine object creation. Second, to handle
255-
// the defaulting behavior for VirtualMachines that would be switching from DIMMSlots to VirtioMem
256-
// on restart. We place more restrictions on VirtioMem because we use 8MiB block sizes, so changing
257-
// to a new default can only happen if the memory slot size is a multiple of 8MiB.
258-
func (g Guest) ValidateForMemoryProvider(p MemoryProvider) error {
259-
if p == MemoryProviderVirtioMem {
260-
if g.MemorySlotSize.Value()%virtioMemBlockSizeBytes != 0 {
261-
return fmt.Errorf("memorySlotSize invalid for memoryProvider VirtioMem: must be a multiple of 8Mi")
262-
}
252+
// ValidateMemorySize returns an error iff the memory settings are invalid for use with virtio-mem
253+
// (the backing memory provider that we use)
254+
func (g Guest) ValidateMemorySize() error {
255+
if g.MemorySlotSize.Value()%virtioMemBlockSizeBytes != 0 {
256+
return fmt.Errorf("memorySlotSize invalid for use with virtio-mem: must be a multiple of 8Mi")
263257
}
264258
return nil
265259
}
@@ -584,6 +578,7 @@ type VirtualMachineStatus struct {
584578
CPUs *MilliCPU `json:"cpus,omitempty"`
585579
// +optional
586580
MemorySize *resource.Quantity `json:"memorySize,omitempty"`
581+
// Deprecated: MemoryProvider is ignored and always interpreted as equal to VirtioMem.
587582
// +optional
588583
MemoryProvider *MemoryProvider `json:"memoryProvider,omitempty"`
589584
// +optional

neonvm/apis/neonvm/v1/virtualmachine_webhook.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ func (r *VirtualMachine) ValidateCreate() (admission.Warnings, error) {
5959
r.Spec.Guest.CPUs.Max)
6060
}
6161

62-
// validate .spec.guest.memorySlotSize w.r.t. .spec.guest.memoryProvider
63-
if r.Spec.Guest.MemoryProvider != nil {
64-
if err := r.Spec.Guest.ValidateForMemoryProvider(*r.Spec.Guest.MemoryProvider); err != nil {
65-
return nil, fmt.Errorf(".spec.guest: %w", err)
66-
}
62+
// DIMMSlots memory provider is deprecated, and assumed to never be used.
63+
if r.Spec.Guest.MemoryProvider != nil && *r.Spec.Guest.MemoryProvider == MemoryProviderDIMMSlots {
64+
return nil, errors.New("DIMMSlots memory provider is deprecated and disabled")
65+
}
66+
67+
if err := r.Spec.Guest.ValidateMemorySize(); err != nil {
68+
return nil, fmt.Errorf(".spec.guest: %w", err)
6769
}
6870

6971
// validate .spec.guest.memorySlots.use and .spec.guest.memorySlots.max

neonvm/config/crd/bases/vm.neon.tech_virtualmachines.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,8 @@ spec:
25852585
kernelImage:
25862586
type: string
25872587
memoryProvider:
2588+
description: 'Deprecated: MemoryProvider is ignored and always
2589+
interpreted as equal to VirtioMem.'
25882590
enum:
25892591
- DIMMSlots
25902592
- VirtioMem
@@ -3000,6 +3002,8 @@ spec:
30003002
extraNetMask:
30013003
type: string
30023004
memoryProvider:
3005+
description: 'Deprecated: MemoryProvider is ignored and always interpreted
3006+
as equal to VirtioMem.'
30033007
enum:
30043008
- DIMMSlots
30053009
- VirtioMem

neonvm/samples/vm-example.dimmslots.yaml

-128
This file was deleted.

pkg/neonvm/controllers/config.go

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ type ReconcilerConfig struct {
3131
// used in setting up the VM disks via QEMU's `-drive` flag.
3232
QEMUDiskCacheSettings string
3333

34-
// DefaultMemoryProvider is the memory provider (dimm slots or virtio-mem) that will be used for
35-
// new VMs (or, when old ones restart) if nothing is explicitly set.
36-
DefaultMemoryProvider vmv1.MemoryProvider
37-
3834
// MemhpAutoMovableRatio specifies the value that new neonvm-runners will set as the
3935
// kernel's 'memory_hotplug.auto_movable_ratio', iff the memory provider is virtio-mem.
4036
//

pkg/neonvm/controllers/functests/vm_controller_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ var _ = Describe("VirtualMachine controller", func() {
110110
MaxConcurrentReconciles: 1,
111111
SkipUpdateValidationFor: nil,
112112
QEMUDiskCacheSettings: "cache=none",
113-
DefaultMemoryProvider: vmv1.MemoryProviderDIMMSlots,
114113
MemhpAutoMovableRatio: "301",
115114
FailurePendingPeriod: 1 * time.Minute,
116115
FailingRefreshInterval: 1 * time.Minute,

0 commit comments

Comments
 (0)