feat(kubevirt): add run policy support to VM lifecycle management#1012
feat(kubevirt): add run policy support to VM lifecycle management#1012awels wants to merge 1 commit intocontainers:mainfrom
Conversation
Adds a new run_policy parameter to the vm_lifecycle tool that allows users to control the VM's runStrategy when starting a virtual machine. The parameter supports three policies: - HighAvailability: VM runs continuously (sets runStrategy to Always) - RestartOnFailure: VM restarts on failure (sets runStrategy to RerunOnFailure) - Once: VM runs once and stops after completion (sets runStrategy to Once) The run_policy parameter is optional and defaults to HighAvailability to maintain backward compatibility with existing usage. Changes include: - Updated StartVM function to accept RunPolicy parameter - Added 19 unit tests covering all run policy combinations - Added 3 integration tests for vm_lifecycle tool - Updated tool schema with enum values and documentation - Auto-generated README.md updates Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Alexander Wels <awels@redhat.com>
|
/cc @lyarwood |
|
/lgtm |
|
/run-mcpchecker kubevirt |
| case RunPolicyOnce: | ||
| return RunStrategyOnce | ||
| } | ||
| return RunStrategyAlways |
There was a problem hiding this comment.
This silent default to Always has a broader impact: RestartVM (line 200) hardcodes RunStrategyAlways when restarting. After this PR, if a user starts a VM with run_policy=Once then restarts it, the strategy silently reverts to Always. Should RestartVM accept and forward the run_policy parameter, or at minimum preserve the VM's current runStrategy?
|
|
||
| // Parse optional run_policy parameter (defaults to HighAvailability) | ||
| runPolicyStr := api.OptionalString(params, "run_policy", string(kubevirt.RunPolicyHighAvailability)) | ||
| runPolicy := kubevirt.RunPolicy(runPolicyStr) |
There was a problem hiding this comment.
The run_policy value is cast directly to RunPolicy without server-side validation. getRunStrategyFromRunPolicy silently defaults invalid values to Always, which masks errors. Consider adding explicit validation:
if !kubevirt.IsValidRunPolicy(runPolicy) {
return api.NewToolCallResult("", fmt.Errorf("invalid run_policy %q: must be one of HighAvailability, RestartOnFailure, Once", runPolicyStr)), nil
}| } | ||
|
|
||
| // Parse optional run_policy parameter (defaults to HighAvailability) | ||
| runPolicyStr := api.OptionalString(params, "run_policy", string(kubevirt.RunPolicyHighAvailability)) |
There was a problem hiding this comment.
nit: run_policy is parsed for all actions but only used by start. Consider moving this inside the ActionStart case to avoid confusion.
Adds a new run_policy parameter to the vm_lifecycle tool that allows users to control the VM's runStrategy when starting a virtual machine.
The parameter supports three policies:
The run_policy parameter is optional and defaults to HighAvailability to maintain backward compatibility with existing usage.
Changes include: