Skip to content

Commit a85cec7

Browse files
authored
Unified Workload Discovery for vmcp (#2487)
* unify workload management across CLI and Kubernetes * removed unnecessary files * unified workload with separate workloads for cli and k8s * refactor the constructor and fix tests * adds more tests * fixed thv listing * checks the kubernetes client runtime instead of the environment * fix e2e tests * improves test coverage * refactor the k8s manager into separate package * removed logs fns * use pkg/k8s package for client and namespace * moved discoverer creation to factory inside pkg * refactor the workload manager * removed changes regarding the workload manager refactor * use default workload manager as the cli implmentation for workload discoverer
1 parent ad29660 commit a85cec7

File tree

12 files changed

+1042
-573
lines changed

12 files changed

+1042
-573
lines changed

cmd/vmcp/app/commands.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/stacklok/toolhive/pkg/vmcp/discovery"
2121
vmcprouter "github.com/stacklok/toolhive/pkg/vmcp/router"
2222
vmcpserver "github.com/stacklok/toolhive/pkg/vmcp/server"
23-
"github.com/stacklok/toolhive/pkg/workloads"
2423
)
2524

2625
var rootCmd = &cobra.Command{
@@ -227,32 +226,22 @@ func discoverBackends(ctx context.Context, cfg *config.Config) ([]vmcp.Backend,
227226
}
228227

229228
// Initialize managers for backend discovery
230-
logger.Info("Initializing workload and group managers")
231-
workloadsManager, err := workloads.NewManager(ctx)
229+
logger.Info("Initializing group manager")
230+
groupsManager, err := groups.NewManager()
232231
if err != nil {
233-
logger.Warnf("Failed to create workloads manager (expected in Kubernetes): %v", err)
234-
logger.Warnf("Backend discovery will be skipped - continuing with empty backend list")
235-
return []vmcp.Backend{}, backendClient, nil
232+
return nil, nil, fmt.Errorf("failed to create groups manager: %w", err)
236233
}
237234

238-
groupsManager, err := groups.NewManager()
235+
// Create backend discoverer based on runtime environment
236+
discoverer, err := aggregator.NewBackendDiscoverer(ctx, groupsManager, cfg.OutgoingAuth)
239237
if err != nil {
240-
logger.Warnf("Failed to create groups manager (expected in Kubernetes): %v", err)
241-
logger.Warnf("Backend discovery will be skipped - continuing with empty backend list")
242-
return []vmcp.Backend{}, backendClient, nil
238+
return nil, nil, fmt.Errorf("failed to create backend discoverer: %w", err)
243239
}
244240

245-
// Create backend discoverer and discover backends
246-
discoverer := aggregator.NewCLIBackendDiscoverer(workloadsManager, groupsManager, cfg.OutgoingAuth)
247-
248241
logger.Infof("Discovering backends in group: %s", cfg.Group)
249242
backends, err := discoverer.Discover(ctx, cfg.Group)
250243
if err != nil {
251-
// Handle discovery errors gracefully - this is expected in Kubernetes
252-
logger.Warnf("CLI backend discovery failed (likely running in Kubernetes): %v", err)
253-
logger.Warnf("Kubernetes backend discovery is not yet implemented - continuing with empty backend list")
254-
logger.Warnf("The vmcp server will start but won't proxy any backends until this feature is implemented")
255-
return []vmcp.Backend{}, backendClient, nil
244+
return nil, nil, fmt.Errorf("failed to discover backends: %w", err)
256245
}
257246

258247
if len(backends) == 0 {

pkg/vmcp/aggregator/cli_discoverer.go

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)