workloads

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package workloads contains high-level logic for managing the lifecycle of ToolHive-managed containers.

Index

Constants

View Source
const (
	// AsyncOperationTimeout is the timeout for async workload operations
	AsyncOperationTimeout = 5 * time.Minute
)

Variables

View Source
var ErrWorkloadNotRunning = fmt.Errorf("workload not running")

ErrWorkloadNotRunning is returned when a container cannot be found by name.

Functions

func FilterByGroup added in v0.2.2

func FilterByGroup(workloadList []core.Workload, groupName string) ([]core.Workload, error)

FilterByGroup filters workloads to only include those in the specified group

func FilterByGroups added in v0.2.4

func FilterByGroups(workloadList []core.Workload, groupNames []string) ([]core.Workload, error)

FilterByGroups filters workloads to only include those in the specified groups

Types

type DefaultManager added in v0.6.6

type DefaultManager struct {
	// contains filtered or unexported fields
}

DefaultManager is the default implementation of the Manager interface.

func NewManager

func NewManager(ctx context.Context) (*DefaultManager, error)

NewManager creates a new container manager instance.

func (*DefaultManager) DeleteWorkloads added in v0.6.6

func (d *DefaultManager) DeleteWorkloads(_ context.Context, names []string) (*errgroup.Group, error)

DeleteWorkloads deletes the specified workloads by name.

func (*DefaultManager) DoesWorkloadExist added in v0.6.6

func (d *DefaultManager) DoesWorkloadExist(ctx context.Context, workloadName string) (bool, error)

DoesWorkloadExist checks if a workload with the given name exists.

func (*DefaultManager) GetLogs added in v0.6.6

func (d *DefaultManager) GetLogs(ctx context.Context, workloadName string, follow bool) (string, error)

GetLogs retrieves the logs of a container.

func (*DefaultManager) GetProxyLogs added in v0.6.6

func (*DefaultManager) GetProxyLogs(_ context.Context, workloadName string) (string, error)

GetProxyLogs retrieves proxy logs from the filesystem

func (*DefaultManager) GetWorkload added in v0.6.6

func (d *DefaultManager) GetWorkload(ctx context.Context, workloadName string) (core.Workload, error)

GetWorkload retrieves details of the named workload including its status.

func (*DefaultManager) GetWorkloadAsVMCPBackend added in v0.6.6

func (d *DefaultManager) GetWorkloadAsVMCPBackend(ctx context.Context, workloadName string) (*vmcp.Backend, error)

GetWorkloadAsVMCPBackend retrieves a workload and converts it to a vmcp.Backend. This method eliminates indirection by directly returning the vmcp.Backend type needed by vmcp workload discovery, avoiding the need for callers to convert from core.Workload to vmcp.Backend. Returns nil if the workload exists but is not accessible (e.g., no URL).

func (*DefaultManager) ListWorkloads added in v0.6.6

func (d *DefaultManager) ListWorkloads(ctx context.Context, listAll bool, labelFilters ...string) ([]core.Workload, error)

ListWorkloads retrieves the states of all workloads.

func (*DefaultManager) ListWorkloadsInGroup added in v0.6.6

func (d *DefaultManager) ListWorkloadsInGroup(ctx context.Context, groupName string) ([]string, error)

ListWorkloadsInGroup returns all workload names that belong to the specified group

func (*DefaultManager) MoveToGroup added in v0.6.6

func (*DefaultManager) MoveToGroup(ctx context.Context, workloadNames []string, groupFrom string, groupTo string) error

MoveToGroup moves the specified workloads from one group to another by updating their runconfig.

func (*DefaultManager) RestartWorkloads added in v0.6.6

func (d *DefaultManager) RestartWorkloads(_ context.Context, names []string, foreground bool) (*errgroup.Group, error)

RestartWorkloads restarts the specified workloads by name.

func (*DefaultManager) RunWorkload added in v0.6.6

func (d *DefaultManager) RunWorkload(ctx context.Context, runConfig *runner.RunConfig) error

RunWorkload runs a workload in the foreground with automatic restart on container exit.

func (*DefaultManager) RunWorkloadDetached added in v0.6.6

func (d *DefaultManager) RunWorkloadDetached(ctx context.Context, runConfig *runner.RunConfig) error

RunWorkloadDetached runs a workload in the background.

func (*DefaultManager) StopWorkloads added in v0.6.6

func (d *DefaultManager) StopWorkloads(_ context.Context, names []string) (*errgroup.Group, error)

StopWorkloads stops the specified workloads by name.

func (*DefaultManager) UpdateWorkload added in v0.6.6

func (d *DefaultManager) UpdateWorkload(_ context.Context, workloadName string, newConfig *runner.RunConfig) (*errgroup.Group, error)

UpdateWorkload updates a workload by stopping, deleting, and recreating it

type Manager

type Manager interface {
	// GetWorkload retrieves details of the named workload including its status.
	GetWorkload(ctx context.Context, workloadName string) (core.Workload, error)
	// ListWorkloads retrieves the states of all workloads.
	// The `listAll` parameter determines whether to include workloads that are not running.
	// The optional `labelFilters` parameter allows filtering workloads by labels (format: key=value).
	ListWorkloads(ctx context.Context, listAll bool, labelFilters ...string) ([]core.Workload, error)
	// DeleteWorkloads deletes the specified workloads by name.
	// It is implemented as an asynchronous operation which returns an errgroup.Group
	DeleteWorkloads(ctx context.Context, names []string) (*errgroup.Group, error)
	// StopWorkloads stops the specified workloads by name.
	// It is implemented as an asynchronous operation which returns an errgroup.Group
	StopWorkloads(ctx context.Context, names []string) (*errgroup.Group, error)
	// RunWorkload runs a container in the foreground.
	RunWorkload(ctx context.Context, runConfig *runner.RunConfig) error
	// RunWorkloadDetached runs a container in the background.
	RunWorkloadDetached(ctx context.Context, runConfig *runner.RunConfig) error
	// RestartWorkloads restarts the specified workloads by name.
	// It is implemented as an asynchronous operation which returns an errgroup.Group
	RestartWorkloads(ctx context.Context, names []string, foreground bool) (*errgroup.Group, error)
	// UpdateWorkload updates a workload by stopping, deleting, and recreating it.
	// It is implemented as an asynchronous operation which returns an errgroup.Group
	UpdateWorkload(ctx context.Context, workloadName string, newConfig *runner.RunConfig) (*errgroup.Group, error)
	// GetLogs retrieves the logs of a container.
	GetLogs(ctx context.Context, containerName string, follow bool) (string, error)
	// GetProxyLogs retrieves the proxy logs from the filesystem.
	GetProxyLogs(ctx context.Context, workloadName string) (string, error)
	// MoveToGroup moves the specified workloads from one group to another by updating their runconfig.
	MoveToGroup(ctx context.Context, workloadNames []string, groupFrom string, groupTo string) error
	// ListWorkloadsInGroup returns all workload names that belong to the specified group, including stopped workloads.
	ListWorkloadsInGroup(ctx context.Context, groupName string) ([]string, error)
	// DoesWorkloadExist checks if a workload with the given name exists.
	DoesWorkloadExist(ctx context.Context, workloadName string) (bool, error)
}

Manager is responsible for managing the state of ToolHive-managed containers. NOTE: This interface may be split up in future PRs, in particular, operations which are only relevant to the CLI/API use case will be split out.

func NewManagerFromRuntime added in v0.1.0

func NewManagerFromRuntime(runtime rt.Runtime) (Manager, error)

NewManagerFromRuntime creates a new container manager instance from an existing runtime.

func NewManagerFromRuntimeWithProvider added in v0.2.16

func NewManagerFromRuntimeWithProvider(runtime rt.Runtime, configProvider config.Provider) (Manager, error)

NewManagerFromRuntimeWithProvider creates a new container manager instance from an existing runtime with a custom config provider.

func NewManagerWithProvider added in v0.2.16

func NewManagerWithProvider(ctx context.Context, configProvider config.Provider) (Manager, error)

NewManagerWithProvider creates a new container manager instance with a custom config provider.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package statuses provides an interface and implementation for managing workload statuses.
Package statuses provides an interface and implementation for managing workload statuses.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package types contains types and validation functions for workloads in ToolHive.
Package types contains types and validation functions for workloads in ToolHive.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL