Repository navigation
fix(kubevirt): drop deprecated spec.running when setting runStrategy - #1518
Conversation
|
Follow-up on "I have not reproduced it end to end": I have now confirmed the admission rejection on a KubeVirt v1.9.0 cluster with a server-side dry run of a VM that sets both fields: spec:
running: false
runStrategy: HaltedThis is the message from vms-admitter.go#L235. So a VM created with |
ksimon1
left a comment
There was a problem hiding this comment.
The change looks good. Below are some small findings. Please also add Assisted by: note to the commit message
There was a problem hiding this comment.
Please adjust this function instead of adding a new one (createTestVMWithRunning).
| } | ||
| } | ||
|
|
||
| t.Run("Start VM with running: false", func(t *testing.T) { |
There was a problem hiding this comment.
Nit: I would use similar pattern for these tests as e.g. in TestStopVM(t *testing.T) function, then we could get rid of some code duplication.
|
Thanks for the review! Updated: |
382478a to
4fd2f67
Compare
|
/lgtm |
ychampion
left a comment
There was a problem hiding this comment.
Reviewed at 4fd2f67345cef952e7358c3a490abe9675c8600c.
The legacy fallback matches KubeVirt's running semantics, and removing running in the same update avoids persisting the mutually exclusive fields together. Matching legacy states correctly remain no-ops.
I ran the helper package with -race and the complete TestKubevirt MCP suite with -race. An additional six-case public-MCP probe used a disposable Kubernetes 1.37 API server with a CEL rule enforcing the documented field exclusion. The pre-change helper fails all six cases with that validation error; this revision passes all six. Start/stop no-ops retain their resource versions, changed objects contain only the expected strategy, and unrelated template fields/annotations survive.
No KubeVirt controller or admission webhook was installed for this probe, so it verifies MCP responses and persisted update payloads, rather than VM reconciliation or restart timing. LGTM for this focused compatibility fix.
vm_lifecycle start/stop/restart only looked at spec.runStrategy. A VirtualMachine that still uses the deprecated spec.running field (KubeVirt v1.9 accepts it with a deprecation warning) ended up with both fields set after the update, which the KubeVirt VM admitter rejects with "Running and RunStrategy are mutually exclusive". start on a VM with running: true also reported "started" although it was already running. GetVMRunStrategy now maps spec.running to Always/Halted when runStrategy is absent, the same way KubeVirt's VirtualMachine.RunStrategy() does, and SetVMRunStrategy removes spec.running before writing spec.runStrategy. Assisted-by: Claude <[email protected]> Signed-off-by: YoungjuKim <[email protected]>
4fd2f67 to
554a31c
Compare
|
/run-mcpchecker kubevirt |
lyarwood
left a comment
There was a problem hiding this comment.
/run-mcpchecker kubevirt
vm_lifecycle(start,stop,restart) reads and writes onlyspec.runStrategy(
pkg/kubevirt/vm.go). KubeVirt still accepts VirtualMachines that use thedeprecated
spec.runningfield. KubeVirt v1.9 admits them and only adds thewarning
spec.running is deprecated, please use spec.runStrategy instead.For such a VM:
stop/restart/start(withrunning: false) writespec.runStrategywhile
spec.runningis still set. The KubeVirt VM admitter then rejects theupdate, because
validateRunStrategyrefuses a spec that has both fields:Running and RunStrategy are mutually exclusive. Note that Running is deprecated, please use RunStrategy instead(vms-admitter.go).
No mutating webhook removes
spec.runningfirst.starton a VM withrunning: truesees norunStrategy, so it updates the VMand returns "VirtualMachine started successfully" although the VM was already running.
The fix follows KubeVirt's own interpretation in
VirtualMachine.RunStrategy():GetVMRunStrategymapsspec.running: true/falsetoAlways/Haltedwhenspec.runStrategyis absent.SetVMRunStrategyremovesspec.runningbefore it writesspec.runStrategy.This migrates the VM to the non-deprecated field instead of failing.
VMs that already use
runStrategybehave the same as before, and the existingTestStartVM,TestStopVMandTestRestartVMcases are unchanged.Testing
I added
TestLifecycleWithDeprecatedRunning(pkg/kubevirt/vm_test.go), which usesthe fake dynamic client:
mainit fails in all four subtests:spec.running is still set×3, and
wasStarted = true, want false for a VM that is already running.pkg/kubevirtvm_test.gopasses:TestStartVM,TestStopVM,TestRestartVM,TestPauseVM,TestUnpauseVM,and the new test.
Caveat: I could not fetch the module set pinned in
go.modon this machine. So I ranvm.goandvm_test.goin a scratch module againstk8s.io/apimachineryandk8s.io/client-gov0.36.0 instead of v0.37.0. The helpers used here(
unstructured.Nested*,RemoveNestedField,dynamic/fake) are the same in both.CI will run the real module set.
The admission rejection itself comes from reading the KubeVirt v1.9.0 source
linked above. I have not reproduced it end to end with the MCP server against a
cluster. A cluster running KubeVirt v1.9.0 still has a VM that uses
spec.running,so the case does happen in practice.
This change was drafted with AI assistance and reviewed by me.
🤖 Generated with Claude Code