Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyVolumeLabels(volumes []string, info *RuntimeInfo) []string
- func AuthForSource(auth *config.SourceAuth, url string, resolver CredentialResolver) (transport.AuthMethod, error)
- func GetContainerHostPort(ctx context.Context, cli dockerclient.DockerClient, containerID string, ...) (int, error)
- func ImageReferenceMatches(current, requested string) bool
- func ReplicaContainerName(stack, name string, replicaID, totalReplicas int) string
- func WithConfigsRevision(labels map[string]string, revision string) map[string]string
- type BuildOptions
- type BuildResult
- type Builder
- type ConfigFile
- type CredentialResolver
- type DependencyGraph
- type DetectOptions
- type DockerClientGetter
- type LoggerSetter
- type MCPServerReplica
- type MCPServerResult
- type NetworkOptions
- type Orchestrator
- func (o *Orchestrator) Close() error
- func (o *Orchestrator) DockerClient() dockerclient.DockerClient
- func (o *Orchestrator) Down(ctx context.Context, stack string) error
- func (o *Orchestrator) PrepareMCPServer(ctx context.Context, stackName string, server *config.MCPServer, noCache bool) (string, error)
- func (o *Orchestrator) Runtime() WorkloadRuntime
- func (o *Orchestrator) RuntimeInfo() *RuntimeInfo
- func (o *Orchestrator) SetCredentialResolver(r CredentialResolver)
- func (o *Orchestrator) SetLogger(logger *slog.Logger)
- func (o *Orchestrator) SetRuntimeInfo(info *RuntimeInfo)
- func (o *Orchestrator) Status(ctx context.Context, stack string) ([]WorkloadStatus, error)
- func (o *Orchestrator) Up(ctx context.Context, stack *config.Stack, opts UpOptions) (*UpResult, error)
- type RuntimeInfo
- type RuntimeType
- type UpOptions
- type UpResult
- type WorkloadConfig
- type WorkloadFilter
- type WorkloadID
- type WorkloadRuntime
- type WorkloadState
- type WorkloadStatus
- type WorkloadType
Constants ¶
const ( LabelManaged = "gridctl.managed" LabelStack = "gridctl.stack" LabelMCPServer = "gridctl.mcp-server" LabelResource = "gridctl.resource" LabelAgent = "gridctl.agent" )
Label constants for identifying gridctl-managed resources.
const LabelConfigsRevision = "gridctl.configs-revision"
LabelConfigsRevision is the container label holding the configs content digest. It is absent when the server has no configs.
Variables ¶
var ( ErrWorkloadNotFound = errors.New("workload not found") ErrNetworkNotFound = errors.New("network not found") ErrNotSupported = errors.New("operation not supported by this runtime") ErrInvalidConfig = errors.New("invalid workload configuration") )
Sentinel errors for runtime operations.
var GetContainerHostPortFunc func(ctx context.Context, cli dockerclient.DockerClient, containerID string, containerPort int) (int, error)
GetContainerHostPort is a backward-compatible helper. This is set by the docker package at init time.
var NewFunc func() (*Orchestrator, error)
NewFunc is the type for a factory function that creates an Orchestrator. This is set by the docker package at init time to avoid import cycles.
var NewWithInfoFunc func(info *RuntimeInfo) (*Orchestrator, error)
NewWithInfoFunc is the type for a factory function that creates an Orchestrator with runtime info (for explicit runtime selection or auto-detection).
Functions ¶
func ApplyVolumeLabels ¶
func ApplyVolumeLabels(volumes []string, info *RuntimeInfo) []string
ApplyVolumeLabels appends :Z to volume mounts when Podman + SELinux.
func AuthForSource ¶
func AuthForSource(auth *config.SourceAuth, url string, resolver CredentialResolver) (transport.AuthMethod, error)
AuthForSource turns a declarative SourceAuth block into a ready-to-use transport.AuthMethod. CredentialRef is resolved via the supplied resolver (typically vault-backed); raw tokens are produced only in memory and never persisted. A nil block, or Method == "" or "none", yields (nil, nil) — the public-repo path. The resolver may be nil only when no CredentialRef is present; otherwise we fail fast rather than silently fall through to an unauthenticated clone that 401s with a confusing error.
func GetContainerHostPort ¶
func GetContainerHostPort(ctx context.Context, cli dockerclient.DockerClient, containerID string, containerPort int) (int, error)
GetContainerHostPort returns the host port for a container.
func ImageReferenceMatches ¶
ImageReferenceMatches reports whether two image names are the same reference. Engines may expand Docker Hub names and default tags during creation. Different registries, tags, and digests do not match. An identical non-empty string matches even when it is not a reference. Two empty names do not match.
func ReplicaContainerName ¶
ReplicaContainerName returns the container name for a specific replica. For single-replica servers (totalReplicas <= 1) it returns the same name containerName produces, so backward-compatible stacks see zero diff. For totalReplicas > 1 it appends a "-replica-<id>" suffix so distinct replicas of the same logical server never collide in the runtime.
func WithConfigsRevision ¶
WithConfigsRevision copies labels and sets the configs revision. An empty revision leaves the map unchanged. A nil map with a revision becomes a one-entry map. The input map is not mutated.
Types ¶
type BuildOptions ¶
type BuildOptions struct {
Stack string // Stack name used in image identity
ServerName string // Logical server name used in image identity
SourceType string // "git" or "local"
URL string // Git URL
Ref string // Git ref/branch
Path string // Local path
ProjectPath string // Python project subdirectory below a local root
Runtime string // Generated source runtime
Package string // Public package name
Python string // Python minor version
Extras []string // Python package extras
With []string // Additional Python dependencies
Packages []string // Debian runtime packages
Dockerfile string // Dockerfile path within context
BuildArgs map[string]string // Build arguments
Command []string // Runtime command included in build identity
Platform string // Target OCI platform
NoCache bool // Force rebuild
Auth transport.AuthMethod // Resolved git auth (nil = unauthenticated)
Logger *slog.Logger // Logger for build operations (optional)
}
BuildOptions for the Builder interface.
type BuildResult ¶
BuildResult from a build operation.
type Builder ¶
type Builder interface {
Build(ctx context.Context, opts BuildOptions) (*BuildResult, error)
}
Builder handles image/artifact building. This is kept separate from WorkloadRuntime as image building is a distinct concern.
type ConfigFile ¶
type ConfigFile = config.ConfigFile
ConfigFile is one file materialized into a container at create time.
type CredentialResolver ¶
CredentialResolver expands a credential reference (e.g. "${vault:GIT_TOKEN}") to its raw token. Set via SetCredentialResolver. Without one, MCP source blocks that carry a CredentialRef fail fast at build time so the user sees "missing vault secret" rather than a confusing 401 from the git server.
type DependencyGraph ¶
type DependencyGraph struct {
// contains filtered or unexported fields
}
DependencyGraph represents a directed acyclic graph of dependencies. It provides topological sorting to determine correct startup order.
func NewDependencyGraph ¶
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph creates an empty dependency graph.
func (*DependencyGraph) AddEdge ¶
func (g *DependencyGraph) AddEdge(from, to string)
AddEdge adds a dependency edge: from depends on to. This means 'to' must be started before 'from'.
func (*DependencyGraph) AddNode ¶
func (g *DependencyGraph) AddNode(name string)
AddNode adds a node to the graph.
func (*DependencyGraph) GetDependencies ¶
func (g *DependencyGraph) GetDependencies(name string) []string
GetDependencies returns the direct dependencies of a node.
func (*DependencyGraph) HasNode ¶
func (g *DependencyGraph) HasNode(name string) bool
HasNode returns true if the node exists in the graph.
func (*DependencyGraph) Sort ¶
func (g *DependencyGraph) Sort() ([]string, error)
Sort returns nodes in topological order (dependencies first). Nodes without dependencies come first, dependent nodes come later. Uses Kahn's algorithm: O(V + E) time complexity.
type DetectOptions ¶
type DetectOptions struct {
Explicit string // Value from --runtime flag or GRIDCTL_RUNTIME env var
}
DetectOptions configures runtime detection.
type DockerClientGetter ¶
type DockerClientGetter interface {
Client() dockerclient.DockerClient
}
DockerClientGetter is an interface for types that can return a Docker client.
type LoggerSetter ¶
LoggerSetter is an interface for types that accept a logger.
type MCPServerReplica ¶
type MCPServerReplica struct {
ReplicaID int // zero-indexed within the server
WorkloadID WorkloadID // runtime ID for container replicas
Endpoint string // host:port or URL
HostPort int // host port if applicable
}
MCPServerReplica is one replica's runtime handle. For non-container replicas (external, local process, SSH, OpenAPI) only ReplicaID is meaningful — WorkloadID, Endpoint, and HostPort are empty/zero.
type MCPServerResult ¶
type MCPServerResult struct {
Name string // Logical name
Image string // Desired image resolved before reconciliation
WorkloadID WorkloadID // Runtime ID (empty for external/local/SSH/OpenAPI). Mirrors Replicas[0].WorkloadID.
Endpoint string // How to reach it (URL or host:port). Mirrors Replicas[0].Endpoint.
HostPort int // Host port if applicable. Mirrors Replicas[0].HostPort.
// Replicas carries per-replica runtime handles. Always non-empty after Up()
// returns: a server with no replicas field (or Replicas=1) gets a single entry
// whose top-level fields match the mirrored fields above.
Replicas []MCPServerReplica
// Server type flags (exactly one should be true for non-container servers)
External bool // URL-based external server
LocalProcess bool // Local stdio process
SSH bool // SSH-based remote process
OpenAPI bool // OpenAPI-based adapter server
A2A bool // Outbound A2A source
// For non-container servers
URL string // External server URL
Command []string // Local process or SSH command
SSHHost string
SSHUser string
SSHPort int
SSHIdentityFile string
// For OpenAPI servers
OpenAPIConfig *config.OpenAPIConfig // OpenAPI configuration for gateway to use
A2AConfig *config.A2AConfig
}
MCPServerResult is the runtime-agnostic result for an MCP server.
type NetworkOptions ¶
type NetworkOptions struct {
Driver string // Network driver (e.g., "bridge")
Stack string // For labeling/cleanup purposes
}
NetworkOptions for network creation.
type Orchestrator ¶
type Orchestrator struct {
// contains filtered or unexported fields
}
Orchestrator manages the lifecycle of gridctl workloads. It uses a WorkloadRuntime to start/stop workloads and a Builder for image builds.
func New ¶
func New() (*Orchestrator, error)
New creates a new Orchestrator with a DockerRuntime. This is the backward-compatible constructor that delegates to the registered factory.
func NewOrchestrator ¶
func NewOrchestrator(runtime WorkloadRuntime, builder Builder) *Orchestrator
NewOrchestrator creates an Orchestrator with the given runtime and builder.
func NewWithInfo ¶
func NewWithInfo(info *RuntimeInfo) (*Orchestrator, error)
NewWithInfo creates a new Orchestrator using explicit RuntimeInfo.
func (*Orchestrator) DockerClient ¶
func (o *Orchestrator) DockerClient() dockerclient.DockerClient
DockerClient returns the Docker client for use by other components. This is needed for MCP gateway stdio transport and container logs.
func (*Orchestrator) Down ¶
func (o *Orchestrator) Down(ctx context.Context, stack string) error
Down stops and removes all managed workloads and networks for a stack.
func (*Orchestrator) PrepareMCPServer ¶
func (o *Orchestrator) PrepareMCPServer(ctx context.Context, stackName string, server *config.MCPServer, noCache bool) (string, error)
PrepareMCPServer resolves or builds the desired image for one logical MCP server. Callers must pass the returned image through every replica path rather than deriving a source tag independently.
func (*Orchestrator) Runtime ¶
func (o *Orchestrator) Runtime() WorkloadRuntime
Runtime returns the underlying WorkloadRuntime for advanced use cases.
func (*Orchestrator) RuntimeInfo ¶
func (o *Orchestrator) RuntimeInfo() *RuntimeInfo
RuntimeInfo returns the detected runtime info, or nil if not set.
func (*Orchestrator) SetCredentialResolver ¶
func (o *Orchestrator) SetCredentialResolver(r CredentialResolver)
SetCredentialResolver registers a resolver used to expand a CredentialRef like "${vault:GIT_TOKEN}" into a raw token at clone time. Without a resolver, MCP servers whose source carries a CredentialRef fail fast.
func (*Orchestrator) SetLogger ¶
func (o *Orchestrator) SetLogger(logger *slog.Logger)
SetLogger sets the logger for orchestration operations. If the underlying runtime supports SetLogger, the logger is propagated.
func (*Orchestrator) SetRuntimeInfo ¶
func (o *Orchestrator) SetRuntimeInfo(info *RuntimeInfo)
SetRuntimeInfo stores runtime detection info for runtime-aware behavior.
func (*Orchestrator) Status ¶
func (o *Orchestrator) Status(ctx context.Context, stack string) ([]WorkloadStatus, error)
Status returns information about managed workloads.
type RuntimeInfo ¶
type RuntimeInfo struct {
Type RuntimeType
SocketPath string
HostAlias string // "host.docker.internal" or "host.containers.internal"
Version string // Runtime version for feature gating
SELinux bool // Whether SELinux is enforcing
HasNetavark bool // Whether netavark is available (rootless inter-container networking)
HasAardvarkDNS bool // Whether aardvark-dns is available (inter-container DNS resolution)
}
RuntimeInfo holds detected runtime configuration.
func DetectRuntime ¶
func DetectRuntime(opts DetectOptions) (*RuntimeInfo, error)
DetectRuntime probes for an available container runtime. Priority: explicit selection > DOCKER_HOST > Docker socket > Podman sockets.
func (*RuntimeInfo) CLIName ¶
func (info *RuntimeInfo) CLIName() string
CLIName returns the CLI binary name for user-facing messages.
func (*RuntimeInfo) DisplayName ¶
func (info *RuntimeInfo) DisplayName() string
DisplayName returns a human-readable name for the runtime.
func (*RuntimeInfo) DockerHost ¶
func (info *RuntimeInfo) DockerHost() string
DockerHost returns the DOCKER_HOST value for connecting to this runtime.
func (*RuntimeInfo) HostAliasHostname ¶
func (info *RuntimeInfo) HostAliasHostname() string
HostAliasHostname returns just the hostname part of the host alias.
func (*RuntimeInfo) IsRootless ¶
func (info *RuntimeInfo) IsRootless() bool
IsRootless returns true if this appears to be a rootless Podman socket.
func (*RuntimeInfo) IsSupportedPodmanVersion ¶
func (info *RuntimeInfo) IsSupportedPodmanVersion() bool
IsSupportedPodmanVersion returns true if the Podman version supports netavark (4.0+).
type RuntimeType ¶
type RuntimeType string
RuntimeType identifies the container runtime.
const ( RuntimeDocker RuntimeType = "docker" RuntimePodman RuntimeType = "podman" )
type UpOptions ¶
type UpOptions struct {
NoCache bool // Force rebuild of source-based images
BasePort int // Base port for host port allocation (default: 9000)
}
UpOptions contains options for the Up operation.
type UpResult ¶
type UpResult struct {
MCPServers []MCPServerResult
}
UpResult contains the result of starting a stack.
type WorkloadConfig ¶
type WorkloadConfig struct {
Execution *execution.ExecutionContract
// Identity
Name string // Logical name (e.g., "postgres", "weather-server")
Stack string // Stack this workload belongs to
Type WorkloadType // Type of workload
// Image/artifact
Image string // Container image or artifact reference
// Execution
Command []string // Override entrypoint/command
Env map[string]string // Environment variables
// Networking
NetworkName string // Network to join
ExposedPort int // Port the workload exposes (0 if none)
HostPort int // Desired host port (0 for auto-assign)
// Storage
Volumes []string // Volume mounts (format: "host:container" or "host:container:mode")
Configs []ConfigFile // Files copied into the container after create and before start
// Transport-specific
Transport string // "http", "stdio", "sse"
// Labels for identification and filtering
Labels map[string]string
}
WorkloadConfig is the runtime-agnostic configuration for starting a workload.
type WorkloadFilter ¶
type WorkloadFilter struct {
Stack string // Filter by stack name
Labels map[string]string // Additional label filters
}
WorkloadFilter for querying workloads.
type WorkloadID ¶
type WorkloadID string
WorkloadID uniquely identifies a workload across runtimes. For Docker this is a container ID, for K8s a pod UID, for processes a PID.
type WorkloadRuntime ¶
type WorkloadRuntime interface {
// Start starts a workload and returns its status.
Start(ctx context.Context, cfg WorkloadConfig) (*WorkloadStatus, error)
// Stop stops a running workload by its ID.
Stop(ctx context.Context, id WorkloadID) error
// Remove removes a stopped workload.
Remove(ctx context.Context, id WorkloadID) error
// Status returns the current status of a workload.
Status(ctx context.Context, id WorkloadID) (*WorkloadStatus, error)
// Exists checks if a workload exists by name.
Exists(ctx context.Context, name string) (exists bool, id WorkloadID, err error)
// List returns all workloads matching the filter.
List(ctx context.Context, filter WorkloadFilter) ([]WorkloadStatus, error)
// GetHostPort returns the host port for a workload's exposed port.
GetHostPort(ctx context.Context, id WorkloadID, exposedPort int) (int, error)
// EnsureNetwork creates the network if it doesn't exist.
EnsureNetwork(ctx context.Context, name string, opts NetworkOptions) error
// ListNetworks returns all managed networks for a stack.
ListNetworks(ctx context.Context, stack string) ([]string, error)
// RemoveNetwork removes a network by name.
RemoveNetwork(ctx context.Context, name string) error
// EnsureImage ensures the image is available locally.
EnsureImage(ctx context.Context, imageName string) error
// Ping checks if the runtime is accessible.
Ping(ctx context.Context) error
// Close releases runtime resources.
Close() error
}
WorkloadRuntime is the interface for managing workload lifecycles. Implementations include Docker, Kubernetes, local processes, etc.
type WorkloadState ¶
type WorkloadState string
WorkloadState represents the current state of a workload.
const ( WorkloadStateRunning WorkloadState = "running" WorkloadStateStopped WorkloadState = "stopped" WorkloadStateFailed WorkloadState = "failed" WorkloadStateCreating WorkloadState = "creating" WorkloadStateUnknown WorkloadState = "unknown" )
type WorkloadStatus ¶
type WorkloadStatus struct {
Execution *execution.Report `json:"execution,omitempty"`
// Identity
ID WorkloadID // Runtime-assigned unique identifier
Name string // Logical name from config
Stack string // Stack name
Type WorkloadType // Type of workload
// State
State WorkloadState // Running, Stopped, Failed, etc.
Message string // Human-readable status message (e.g., "Up 5 minutes")
// Networking
Endpoint string // How to reach this workload (e.g., "localhost:9000")
HostPort int // Actual host port (if port-mapped)
// Metadata
Image string // Image/artifact that's running
Labels map[string]string // All labels
}
WorkloadStatus is the runtime-agnostic status of a running workload.
type WorkloadType ¶
type WorkloadType string
WorkloadType identifies the kind of workload.
const ( WorkloadTypeMCPServer WorkloadType = "mcp-server" WorkloadTypeAgent WorkloadType = "agent" WorkloadTypeResource WorkloadType = "resource" )