Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a unified workload management system that provides a consistent interface for managing MCP server workloads across both CLI (Docker/Podman) and Kubernetes environments. This follows the same architectural pattern established by
groups.Managerand enables platform-agnostic workload operations throughout ToolHive.Motivation
Following the successful unification of group management, we now extend this pattern to workload management. This enables:
Implementation
Unified Manager Interface
The
workloads.Managerinterface provides a comprehensive set of operations for managing workloads:Lifecycle Operations:
RunWorkload/RunWorkloadDetached- Start workloads in foreground or backgroundStopWorkloads- Stop running workloadsDeleteWorkloads- Remove workloadsRestartWorkloads- Restart workloadsUpdateWorkload- Update workload configurationQuery Operations:
GetWorkload- Retrieve workload details and statusListWorkloads- List all workloads with optional filteringListWorkloadsInGroup- List workloads in a specific groupDoesWorkloadExist- Check workload existenceUtility Operations:
GetLogs/GetProxyLogs- Retrieve workload logsMoveToGroup- Move workloads between groupsPlatform-Specific Implementations
CLI Manager (
cliManager)Kubernetes Manager (
k8sManager)Automatic Runtime Detection
The
NewManager()factory function automatically detects the runtime environment:k8sManagerwhenTOOLHIVE_RUNTIME=kubernetesor running in a podcliManagerfor Docker/Podman environmentsKey Features
Group Integration
ListWorkloadsInGroupenables group-based discoveryMoveToGroupallows reorganizing workloadsgroups.ManagerUnified Backend Discovery
BackendDiscovererimplementation works across platformsComprehensive Testing
Files Added
pkg/workloads/cli_manager.go- CLI implementation (1205 lines)pkg/workloads/cli_manager_test.go- CLI tests (1616 lines)pkg/workloads/k8s_manager.go- Kubernetes implementation (351 lines)pkg/workloads/k8s_manager_test.go- Kubernetes tests (777 lines)Files Modified
pkg/workloads/manager.go- Simplified to factory functions and interface definitionpkg/workloads/manager_test.go- Reduced to factory function testspkg/vmcp/aggregator/discoverer.go- Updated to use unified managercmd/vmcp/app/commands.go- Updated to use unified discovererBenefits
Testing
Related
groups.Managerunificationpkg/vmcp/aggregator/discoverer.go)Example Usage
// Automatically selects the right implementation based on runtime
manager, err := workloads.NewManager(ctx)
if err != nil {
return err
}
// Works the same way in CLI and Kubernetes
workloads, err := manager.ListWorkloadsInGroup(ctx, "engineering-team")
if err != nil {
return err
}
// Discover backends from workloads (used by vmcp)
discoverer := aggregator.NewBackendDiscoverer(manager, groupsManager, authConfig)
backends, err := discoverer.Discover(ctx, "engineering-team")