Commit d6a28d7
feat(kubevirt): Add basic VM creation toolset (#386)
* feat(kubernetes): Add testing support for fake dynamic clients
Add framework support for using k8s.io/client-go/dynamic/fake in tests.
This enables unit tests to inject fake Kubernetes clients without
requiring a real cluster or envtest setup.
Changes:
1. Add NewAccessControlClientsetForTesting() constructor
- Accepts pre-built fake clients (dynamic, discovery, REST mapper)
- Returns AccessControlClientset for use in tests
- Located in pkg/kubernetes/accesscontrol_clientset.go
2. Add NewForTesting() constructor for Kubernetes
- Creates Kubernetes instance with fake AccessControlClientset
- Minimal Manager setup suitable for testing
- Located in pkg/kubernetes/kubernetes.go
3. Add Config() method to AccessControlClientset
- Exposes rest.Config for use by other components
- Fixes NewKiali() to use Config() instead of direct field access
4. Create pkg/kubernetes/testing package with helpers
- NewFakeKubernetesClient() factory function
- Accepts runtime.Scheme, GVR to ListKind mapping, and initial objects
- Returns fully configured Kubernetes instance with fake clients
- Includes FakeRESTMapper implementing meta.ResettableRESTMapper
- Includes minimal fakeDiscoveryClient for cached discovery
These changes enable toolset tests (like kubevirt VM creation) to use
fake clients for unit testing without external dependencies.
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* feat(kubevirt): Add VM management toolset with initial create tool
Introduces a new KubeVirt toolset providing virtual machine management
capabilities through MCP tools.
Features:
- Smart workload resolution: Matches user input against cluster
DataSources or built-in OS mappings (fedora, ubuntu, centos, rhel,
debian, opensuse)
- Automatic instance type selection based on size/performance hints
- Preference auto-selection matching workload names
- Supports both DataSource-backed VMs and containerdisk VMs
- Configurable runStrategy (Halted by default, Always with autostart
flag)
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* fix(kubevirt): Support both cluster-scoped and namespaced instancetypes/preferences
Previously, the VM template hardcoded instancetype and preference kinds to
always use VirtualMachineClusterInstancetype and VirtualMachineClusterPreference.
This prevented using namespaced VirtualMachineInstancetype and VirtualMachinePreference
resources.
This enables VMs to reference both cluster-wide and namespace-specific
instance types and preferences correctly.
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* feat(kubevirt): Add configurable storage size parameter for VMs
Previously, the VM storage size was hardcoded to 30Gi in the template,
making it impossible to create VMs with different disk sizes without
manually editing the generated YAML.
Storage parameter only applies when using DataSources. Container disk
VMs don't create persistent volumes, so the parameter is ignored in
those cases (as noted in the parameter description).
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* feat(kubevirt): Add debug logging for resource discovery failures
Previously, errors encountered while listing DataSources, Preferences,
and Instancetypes were silently ignored, making it difficult to debug
issues when resources weren't being discovered properly.
This provides better observability for debugging while maintaining the
existing resilient behavior (failures don't block VM creation, they just
limit available resources for auto-selection).
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* docs(kubevirt): Add comprehensive godoc comments to public API
Previously, public functions in pkg/kubevirt/resources.go lacked detailed
documentation explaining their parameters, return values, and behavior.
This made the code harder to understand and maintain.
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* test(kubevirt): Refactor vm/create tests to use public API only
Move tests to create_test package and access functionality only through
the Tools() function, ensuring tests are decoupled from internal
implementation details.
Assisted-By: Claude <[email protected]>
Signed-off-by: Lee Yarwood <[email protected]>
* test(kubevirt): moved tests to MCP layer
Signed-off-by: Marc Nuri <[email protected]>
---------
Signed-off-by: Lee Yarwood <[email protected]>
Signed-off-by: Marc Nuri <[email protected]>
Co-authored-by: Marc Nuri <[email protected]>1 parent 9e3645d commit d6a28d7
File tree
13 files changed
+2229
-5
lines changed- internal/tools/update-readme
- pkg
- kubernetes-mcp-server/cmd
- kubevirt
- testing
- mcp
- testdata
- toolsets/kubevirt
- vm/create
13 files changed
+2229
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
0 commit comments