vm_create on an existing VM name overwrites the VM and answers "VirtualMachine created successfully"

未关闭
#1,663 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, kubernetes
领域
api, backend

调研方向

Start with pkg/toolsets/kubevirt/vm/create/tool.go, especially the apply call near line 209 and the success response near line 220; the issue also describes a patch with a test, but does not name its test file. Reproduce the overwrite using the three-step scenario in the issue and compare the existing VM’s uid, run strategy, memory, and disks before and after. Done means vm_create handles an existing name as described in the expected behavior and its test covers the result.

由索引模型根据 Issue 内容生成。

描述

Version: v0.1.2 (66553fed). Still present on main (ec37a146, 2026-11-12): pkg/toolsets/kubevirt/vm/create/tool.go is unchanged; reproduced live on main 13bfb96f.

What happens

vm_create renders a VirtualMachine and applies it with Force: true (tool.go:209). Given the name of a VM that already exists, the apply rewrites it:

  • the run strategy changes (a running VM with runStrategy: Always becomes Halted unless autostart is set);
  • the disks and volumes are replaced (KubeVirt's lists are atomic, so the old disk is gone);
  • the memory changes;
  • the uid is unchanged.

The tool still answers # VirtualMachine created successfully (tool.go:220). A POST of the same object would return 409 AlreadyExists.

Reproduction (kind, Kubernetes v1.37.0, KubeVirt v1.9.0 CRDs; the identity can get and patch VirtualMachines in demo)

  1. Create VM v1 in demo with runStrategy: Always, 1Gi of memory and a disk rootdisk from fedora.
  2. Call vm_create with {"namespace": "demo", "name": "v1", "workload": "ubuntu"}.
  3. The answer is "VirtualMachine created successfully". kubectl -n demo get vm v1 -o yaml shows the same uid, runStrategy: Halted, different memory (2Gi in our run), and the disk replaced by v1-rootdisk with the ubuntu image.

Expected: vm_create refuses an existing name (or at least does not report "created"), and changes to an existing VM go through vm_lifecycle or resources_create_or_update.

The annotations (destructiveHint and idempotentHint both true) and the patch-only RBAC metadata suggest the upsert itself may be intended. If so, the result text should say the VM was updated, not created.

Possible fix: read the VM first. If it exists, return an error that names it with its uid and run strategy (this needs get added to the declared RBAC). We have a patch with a test (fix(kubevirt): refuse vm_create over an existing VirtualMachine) and can open a PR. It is a check-then-apply, so a VM created by someone else between the two requests can still be overwritten. Closing that window needs a create instead of an apply, which changes the declared verbs, so we left that for your call.

Found while reviewing the MCP server with AI assistance.

主要语言
Go
星标
2.3k
派生
493
平均合并
2 天 8 小时
30 天内合并 PR
75

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

containers/kubernetes-mcp-server 的其他 Issue

查看 containers/kubernetes-mcp-server 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。