Skip to content

Commit d6a28d7

Browse files
lyarwoodmanusa
andauthored
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

13 files changed

+2229
-5
lines changed

internal/tools/update-readme/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/core"
1818
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/helm"
1919
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kiali"
20+
_ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/kubevirt"
2021
)
2122

2223
type OpenShift struct{}

pkg/kubernetes-mcp-server/cmd/root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestToolsets(t *testing.T) {
137137
rootCmd := NewMCPServer(ioStreams)
138138
rootCmd.SetArgs([]string{"--help"})
139139
o, err := captureOutput(rootCmd.Execute) // --help doesn't use logger/klog, cobra prints directly to stdout
140-
if !strings.Contains(o, "Comma-separated list of MCP toolsets to use (available toolsets: config, core, helm, kiali).") {
140+
if !strings.Contains(o, "Comma-separated list of MCP toolsets to use (available toolsets: config, core, helm, kiali, kubevirt).") {
141141
t.Fatalf("Expected all available toolsets, got %s %v", o, err)
142142
}
143143
})

0 commit comments

Comments
 (0)