Documentation
¶
Overview ¶
Package backend abstracts where a job's container actually runs. The controller speaks only to this interface, so the same submit/run/cancel logic drives local Docker today (docker.go) and Kubernetes later (P6) without change.
Index ¶
- type ContainerBackend
- type Docker
- func (d *Docker) HasImage(ctx context.Context, ref string) (bool, error)
- func (d *Docker) Launch(ctx context.Context, spec LaunchSpec) (string, error)
- func (d *Docker) Logs(ctx context.Context, id string, tail int) (string, error)
- func (d *Docker) Ping(ctx context.Context) error
- func (d *Docker) Remove(ctx context.Context, id string) error
- func (d *Docker) Status(ctx context.Context, id string) (Status, error)
- func (d *Docker) Stop(ctx context.Context, id string, timeout time.Duration) error
- type Fake
- func (f *Fake) LastEnv(id string) map[string]string
- func (f *Fake) LastImage(id string) string
- func (f *Fake) LastWorkflowDoc(id string) []byte
- func (f *Fake) Launch(ctx context.Context, spec LaunchSpec) (string, error)
- func (f *Fake) Launched() int
- func (f *Fake) Logs(ctx context.Context, id string, tail int) (string, error)
- func (f *Fake) Remove(ctx context.Context, id string) error
- func (f *Fake) SetLogs(id, logs string)
- func (f *Fake) SetPhase(id string, phase Phase, exitCode int)
- func (f *Fake) Status(ctx context.Context, id string) (Status, error)
- func (f *Fake) Stop(ctx context.Context, id string, timeout time.Duration) error
- type Kubernetes
- func (k *Kubernetes) Launch(ctx context.Context, spec LaunchSpec) (string, error)
- func (k *Kubernetes) Logs(ctx context.Context, id string, tail int) (string, error)
- func (k *Kubernetes) Ping(ctx context.Context) error
- func (k *Kubernetes) Remove(ctx context.Context, id string) error
- func (k *Kubernetes) Status(ctx context.Context, id string) (Status, error)
- func (k *Kubernetes) Stop(ctx context.Context, id string, timeout time.Duration) error
- type KubernetesOptions
- type LaunchSpec
- type Phase
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContainerBackend ¶
type ContainerBackend interface {
// Launch starts a container and returns its backend-specific ID. The
// data volume is reused across launches of the same JobID so state
// and checkpoints survive a restart.
Launch(ctx context.Context, spec LaunchSpec) (containerID string, err error)
// Stop requests a graceful stop (SIGTERM), waiting up to timeout
// before killing. Safe to call on an already-stopped container.
Stop(ctx context.Context, containerID string, timeout time.Duration) error
// Status reports the container's current phase and control address.
Status(ctx context.Context, containerID string) (Status, error)
// Logs returns up to tail lines of the container's stdout+stderr.
Logs(ctx context.Context, containerID string, tail int) (string, error)
// Remove deletes the container (not its data volume).
Remove(ctx context.Context, containerID string) error
}
ContainerBackend launches and manages one container per job.
type Docker ¶
type Docker struct {
// contains filtered or unexported fields
}
Docker runs each job as a local Docker container using the runner image. The workflow document is copied into the container before start (so it works regardless of where the daemon runs), and /data is backed by a named volume per job so state and checkpoints survive restarts.
func NewDocker ¶
NewDocker connects to the Docker daemon from the environment. image is the runner image tag to launch (e.g. "mailer-runner:dev").
func (*Docker) HasImage ¶
HasImage reports whether the given image reference is present locally, so the CLI can fail fast with a build hint instead of a launch error.
type Fake ¶
type Fake struct {
// LaunchErr, if set, makes the next Launch fail (then clears).
LaunchErr error
// contains filtered or unexported fields
}
Fake is an in-memory ContainerBackend for controller unit tests. It records launches and lets a test drive each container's phase without Docker. Safe for concurrent use.
func (*Fake) LastWorkflowDoc ¶ added in v0.7.0
LastWorkflowDoc returns the workflow document a container was launched with (empty for SDK jobs).
type Kubernetes ¶ added in v0.7.0
type Kubernetes struct {
// contains filtered or unexported fields
}
Kubernetes runs each job as a batch/v1 Job on a cluster — the same jobs the Docker backend runs locally, so the controller, reconciler, API, and web UI are unchanged. A Job (not a Deployment) is used so a completed pod is not auto-restarted by Kubernetes: mailer's own reconciler owns restart decisions (backoffLimit is 0).
Per job: a per-job PVC (state + checkpoints, reused across restarts), a ConfigMap (the workflow), an optional Secret (env), and a ClusterIP Service so the controller can reach the agent's control surface.
func NewKubernetes ¶ added in v0.7.0
func NewKubernetes(opts KubernetesOptions) (*Kubernetes, error)
NewKubernetes connects using in-cluster config (when running in a Pod) or the kubeconfig file otherwise.
func (*Kubernetes) Launch ¶ added in v0.7.0
func (k *Kubernetes) Launch(ctx context.Context, spec LaunchSpec) (string, error)
func (*Kubernetes) Ping ¶ added in v0.7.0
func (k *Kubernetes) Ping(ctx context.Context) error
Ping verifies the API server is reachable.
func (*Kubernetes) Remove ¶ added in v0.7.0
func (k *Kubernetes) Remove(ctx context.Context, id string) error
type KubernetesOptions ¶ added in v0.7.0
type KubernetesOptions struct {
Kubeconfig string // path; empty → in-cluster, else default loading rules
Namespace string // default "default"
Image string // runner image (must be pullable by the cluster)
PVCSize string // per-job volume size, default "1Gi"
StorageClass string // optional; empty → cluster default
}
KubernetesOptions configures the backend.
type LaunchSpec ¶
type LaunchSpec struct {
JobID string // used to name the container and its data volume
Name string // human-readable workflow name
Image string // runner image, e.g. mailer-runner:dev
// WorkflowDoc is the raw workflow file content. The backend makes it
// available to the container and points WORKFLOW at it.
WorkflowDoc []byte
// Env is the resolved runtime environment (including any secrets).
// The backend passes it to the container; it is never persisted.
Env map[string]string
// ControlPort is the container port the jobagent listens on. The
// backend publishes it and reports the reachable host port in Status.
ControlPort int
// RestoreSavepoint, if set, names a savepoint the runner seeds from
// before starting (RESTORE_SAVEPOINT). Empty means a fresh start.
RestoreSavepoint string
}
LaunchSpec is everything the backend needs to start one job container.