Skip to content

feat(kubevirt): add vm_create_from_template tool - #1321

Open
codingben wants to merge 1 commit into
containers:mainfrom
codingben:CNV-83870
Open

feat(kubevirt): add vm_create_from_template tool#1321
codingben wants to merge 1 commit into
containers:mainfrom
codingben:CNV-83870

Conversation

@codingben

Copy link
Copy Markdown
Contributor

Add MCP tool to create VirtualMachines from
VirtualMachineTemplates via the virt-template
process subresource API, with eval tasks
and tests.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Heads up — this pull request changes files owned by @ksimon1 @lyarwood.

You are listed as an owner of one or more of the changed areas in .github/CODEOWNERS. GitHub cannot auto-request review from owners without write access, so this comment is the notification instead. A review when you have a moment would be appreciated 🙏

@codingben

Copy link
Copy Markdown
Contributor Author

/cc @lyarwood @ksimon1

Comment thread pkg/kubevirt/template.go
return nil, fmt.Errorf("failed to marshal ProcessOptions: %w", err)
}

result := &unstructured.Unstructured{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could perhaps use the types from virt-template-api package instead of unstructured

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do not have any kubevirt package imported in this project. Might be worth checking if virt-template package is easy to import in this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyarwood can drop your opinion about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for a follow up but I'd assume we want to stay unstructured for now.

Comment thread pkg/kubevirt/template.go Outdated
Comment thread pkg/toolsets/kubevirt/vm/template/tool.go Outdated
Comment thread pkg/toolsets/kubevirt/vm/template/tool.go Outdated
Comment thread README.md
| [Kiali](https://kiali.io) | `kiali` | 16 |
| [Kubernetes](https://kubernetes.io) | - | 32 |
| [KubeVirt](https://kubevirt.io) | `kubevirt`, `tekton` | 19 |
| [KubeVirt](https://kubevirt.io) | `kubevirt`, `tekton` | 24 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this number correct? Since you added just a single tool

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's auto-generated by make update-readme-tools and represents the amount of KubeVirt eval scenarios and not the tools.

Comment thread pkg/kubevirt/template.go
Comment thread pkg/kubevirt/gvr.go Outdated
@ksimon1

ksimon1 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

You should probably add similar test as is here: https://github.com/containers/kubernetes-mcp-server/blob/main/pkg/mcp/toolsets_test.go#L129

Comment thread pkg/kubevirt/gvr.go
Comment thread evals/tasks/kubevirt/create-template-from-vm/task.yaml

@lyarwood lyarwood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @codingben, a few pieces of feedback:

Rebase on #1308 and route through AccessControlRoundTripper

CreateVMFromTemplate in pkg/kubevirt/template.go creates its own REST client via rest.CopyConfig(restConfig), which means the request to subresources.template.kubevirt.io completely bypasses the AccessControlRoundTripper. This is the same pattern as the existing guest agent code in guestagent.go, but I think we should take the opportunity to fix this going forward.

#1308 adds AllowedAPIGroups support to the toolset API — toolsets can declare virtual API groups (like subresources.kubevirt.io) that should be allowed through the AccessControlRoundTripper even though they're not in standard API discovery. This PR would be a great second use case for that mechanism.

I'd suggest:

  1. Rebase this PR on #1308
  2. Add "subresources.template.kubevirt.io" to the kubevirt toolset's GetAllowedAPIGroups() return value
  3. Rework CreateVMFromTemplate to go through the standard Kubernetes client (which has the AccessControlRoundTripper installed) rather than building its own rest.RESTClientFor

That way the request goes through the same access control path as everything else — denied_resources, confirmation rules, and any future validators would all apply. The AllowedAPIGroups mechanism lets it past the REST mapper check, and the API server still enforces RBAC on the user's credentials.

Evals in a separate commit

I'd like to see the eval tasks (the 5 task YAMLs + verify-vm.sh helpers) in their own commit, separate from the tool implementation. This way the evals demonstrate and justify the need for the new vm_create_from_template tool before the implementation commit adds it. It also makes it easier to review the evals and tool independently.

Note that only 2 of the 5 evals (create-vm-from-template, template-required-params) actually exercise the new tool — the other 3 (list-vm-templates, inspect-vm-template, create-template-from-vm) test the agent's ability to work with template CRDs via existing generic tools, which is fine for broader coverage but worth calling out.

@codingben

Copy link
Copy Markdown
Contributor Author

@lyarwood I'd like to avoid rebasing this PR on yours, can we get the PR you opened merged faster instead? It seems not much changes, no reason to keep it open for longer.

@codingben
codingben requested a review from lyarwood August 11, 2026 18:45
@codingben

Copy link
Copy Markdown
Contributor Author

@lyarwood Your PR is closed now. How we should proceed here?

@codingben

Copy link
Copy Markdown
Contributor Author

This PR is now blocked by: #1361

@codingben

Copy link
Copy Markdown
Contributor Author

PR rebased. @lyarwood PTAL

Add MCP tool to create VirtualMachines from
VirtualMachineTemplates via the virt-template
process subresource API, with eval tasks
and tests.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Ben Oukhanov <boukhanov@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants