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

Abierto
#1,663 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
54/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, kubernetes
Área
api, backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
2.3k
Forks
493
Merge medio
2 d 8 h
PR fusionados (30 d)
75

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de containers/kubernetes-mcp-server

Todos los issues de containers/kubernetes-mcp-server

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.