Documentation
¶
Overview ¶
Package kubeflow is the Kubeflow Trainer adapter for go/dispatch: it submits and supervises TrainJobs and derives typed failure causes from the TrainJob, its JobSet, its pods and, where installed, Kueue.
It implements spec 0001, the Kubeflow adapter (https://gitlab.com/phpboyscout/go/dispatch-kubeflow/-/wikis/specs/0001-the-kubeflow-adapter). Importing the package registers the RuntimeRef extension and the Factory under "kubeflow"; ParseSettings and Schema are the adapter's configuration section.
Index ¶
- Constants
- Variables
- func Factory(ctx context.Context, cfg dispatch.AdapterConfig) (dispatch.Backend, error)
- func Schema() []byte
- type Backend
- func (b *Backend) Capabilities(ctx context.Context, spec *model.JobSpec) (map[model.Capability]model.Support, error)
- func (b *Backend) Ceased(ctx context.Context, ref model.ObjectRef, last model.ExecutionObs) (model.CessationEvidence, error)
- func (b *Backend) Close() error
- func (b *Backend) Declarations() model.Declarations
- func (b *Backend) Find(ctx context.Context, job model.JobID) (model.Discovery, error)
- func (b *Backend) Hold(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error
- func (b *Backend) IdentityWeakened(ctx context.Context, spec model.JobSpec) (string, error)
- func (b *Backend) Inspect(ctx context.Context, ref model.ObjectRef) (model.ObjectObs, error)
- func (b *Backend) Open(ctx context.Context, ref model.ObjectRef) error
- func (b *Backend) Output(ctx context.Context, id model.JobID, submission int, s dispatch.Stream, ...) (io.ReadCloser, error)
- func (b *Backend) Progress(ctx context.Context, ref model.ObjectRef) (model.Progress, error)
- func (b *Backend) Release(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error
- func (b *Backend) Rules(_ context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.RuleSupport, error)
- func (b *Backend) Start(ctx context.Context, req model.StartRequest) (model.ObjectRef, error)
- func (b *Backend) Stop(ctx context.Context, ref model.ObjectRef, _ string) error
- func (b *Backend) StopJob(ctx context.Context, job model.JobID, _ string) (model.StopReport, error)
- func (b *Backend) Watch(ctx context.Context, job model.JobID) (<-chan model.ObjectObs, error)
- type Cluster
- type Credential
- type Duration
- type Kueue
- type Launch
- type ObjectKey
- type Publish
- type RuntimeRef
- type Settings
- type Timeouts
Constants ¶
const ( PublishViaImageVolume = "imageVolume" PublishViaInitContainer = "initContainer" )
The ways cmd/publish reaches the trainer container (spec 0001 D15).
const ( KindClusterTrainingRuntime = "ClusterTrainingRuntime" KindTrainingRuntime = "TrainingRuntime" )
The runtime kinds a RuntimeRef may name.
const AdmissionController = "dispatch.phpboyscout.uk/admission"
AdmissionController is the controllerName dispatch's AdmissionCheck names (spec 0001 D8).
const ExtensionNamespace = "kubeflow"
ExtensionNamespace is the namespace of this adapter's JobSpec extensions.
const LaunchInitContainer = "dispatch-launch"
LaunchInitContainer is the init container a runtime must define for go/launch under the init container route (spec 0001 D15).
const LaunchMountPath = "/opt/launch"
LaunchMountPath is where go/launch is mounted on the trainer container, so a job's command is /opt/launch/launch (spec 0001 D15).
const Name = "kubeflow"
Name is the adapter's registry name.
const PublishMountPath = "/opt/dispatch"
PublishMountPath is where cmd/publish is mounted on the trainer container under either route, so a job's command names one path (spec 0001 D15).
Variables ¶
var ErrPodsRemain = fmt.Errorf("%w: pods of the object remain", model.ErrUnreachable)
ErrPodsRemain is an admission not yet possible because pods of the object's last execution may still run, Terminating ones included (spec 0001 D7). Nothing was written and the hold stays in force; it is a failed call to retry, not a refusal.
var ErrStaleHold = fmt.Errorf("%w: the hold instance named is not the one in force", model.ErrRejected)
ErrStaleHold is a hold-family call refused because the instance in force is not the one it expects: under spec 0004 D6 the call is stale (spec 0001 D9).
Functions ¶
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is the Kubeflow adapter: go/dispatch's Backend over one namespace, with Holder, Watcher, CessationSignal, OutputReader and IdentityWeakener (spec 0001).
func (*Backend) Capabilities ¶
func (b *Backend) Capabilities(ctx context.Context, spec *model.JobSpec) (map[model.Capability]model.Support, error)
Capabilities answers spec 0001 D11's table. With a spec it reads the runtime the spec's kubeflow.RuntimeRef names and refuses, with ErrUnsupported, one that breaks D4's rules.
func (*Backend) Ceased ¶
func (b *Backend) Ceased(ctx context.Context, ref model.ObjectRef, last model.ExecutionObs) (model.CessationEvidence, error)
Ceased answers from Node state (spec 0001 D14) about last, the object's latest execution the record saw started: its processes are gone when every Node it ran on is deleted or tainted node.kubernetes.io/out-of-service. An execution with no nodes or no start is never ceased (spec 0003 D12, E). Without permission to get Nodes it is ErrUnsupported; a failed read is an error, never evidence.
func (*Backend) Declarations ¶
func (b *Backend) Declarations() model.Declarations
Declarations are fixed at Open (spec 0003 D13). PolledLoss is empty because the adapter implements Watcher (spec 0001 D14).
func (*Backend) Find ¶
Find returns every object of the job: its TrainJobs, and JobSets, pods and runtime snapshots that outlived theirs, each of those flagged Foreign (spec 0001 D6).
func (*Backend) Hold ¶
Hold places hold instance m.Instance: Workload spec.active false in Kueue mode, TrainJob spec.suspend true in plain mode, with the instance, who, since, until and reason as annotations on the held object, in one update preconditioned on the read it was decided on (spec 0001 D9).
func (*Backend) IdentityWeakened ¶
IdentityWeakened says why a spec's execution identity is weakened: its runtime lets a failed rank rerun under the same identity, accepted only under the site's allowRankRestart (spec 0001 D4).
func (*Backend) Inspect ¶
Inspect reads one object as Find would; a name that is gone or now held by another UID is ErrNotFound (spec 0001 D6).
func (*Backend) Open ¶
Open lifts the start gate (spec 0001 D4). In Kueue mode it removes dispatch's gate from the admission-gated-by list, deleting the annotation when ours was the last; in plain mode it unsuspends, marks the object opened and raises A, unless a hold is in place, when it writes only the mark. An ended object is a fence, ErrRejected; one past its gate is success.
func (*Backend) Output ¶
func (b *Backend) Output(ctx context.Context, id model.JobID, submission int, s dispatch.Stream, follow bool) (io.ReadCloser, error)
Output serves rank 0's log of submission N's current execution through pods/log, following it when asked (spec 0001 D14). Kubernetes interleaves stdout and stderr in one log, so Stdout returns it and Stderr is ErrUnsupported. Earlier executions' logs went with their pods.
func (*Backend) Progress ¶ added in v0.2.0
Progress implements dispatch.ProgressReader from the last LAUNCH-BEAT line of rank 0's log in the current execution (spec 0001 D14). The first read of an object scans its whole log, later ones beatWindow, so a supervisor restarted while a launcher is hung still finds the last beat.
func (*Backend) Release ¶
Release lifts hold instance m.Instance and no other. In plain mode it also unsuspends and raises A when the object was opened and no pod of it remains (spec 0001 D7, D9).
func (*Backend) Rules ¶
func (b *Backend) Rules(_ context.Context, _ model.JobSpec, policy model.RecoveryPolicy) ([]model.RuleSupport, error)
Rules answers each rule's Perform: Resubmit, Hold and Escalate can be carried out, Requeue and Restart cannot (spec 0001 D11, 0003 D3). Hold follows the probed Hold capability.
func (*Backend) Start ¶
Start creates submission N's TrainJob with its start gate closed, on a snapshot of its runtime, reads it back, and in Kueue mode waits for its Workload (spec 0001 D3, D4).
func (*Backend) Stop ¶
Stop deletes this one object instance, preconditioned on its UID. An object already gone, or a name now held by another instance, is success: the instance the ref names is gone (spec 0001 D10).
It propagates in the background: on Trainer v2.3.0 a foreground-deleted TrainJob is wedged once its snapshot is collected (kubeflow/trainer#4203), and a suspended one has its JobSet recreated while it waits (spec 0001 D10).
func (*Backend) StopJob ¶
StopJob deletes every object Find returns, each under its own UID precondition, and repeats until nothing of the job remains or timeouts.stopJob passes. Each object is judged by where its remaining pods are, because its pods can outlive a deleted TrainJob (spec 0001 D10).
func (*Backend) Watch ¶
Watch streams the job's observations (spec 0001 D14): the current one of every object on subscribe, then one whenever a change alters an object's classification. It watches the namespace's TrainJobs, JobSets and, in Kueue mode, Workloads, and the job's pods, and folds a deleted pod's last state into the observation of the execution it ended. A watch that expires or disconnects closes the stream; the collector resubscribes.
type Cluster ¶
type Cluster struct {
Kubeconfig *string `json:"kubeconfig,omitempty"`
Context *string `json:"context,omitempty"`
InCluster bool `json:"inCluster,omitempty"`
}
Cluster says how the adapter reaches the apiserver: a kubeconfig, whose empty path follows client-go's loading rules, or the pod's own service account.
type Credential ¶
type Credential struct {
SecretName string `json:"secretName"`
MountPath string `json:"mountPath"`
}
Credential is a Secret mounted read-only on the trainer container (spec 0001 D12).
type Duration ¶
Duration is a positive time.Duration written as a Go duration string, such as "5m".
func (Duration) MarshalText ¶
MarshalText writes the duration as a Go duration string.
func (*Duration) UnmarshalText ¶
UnmarshalText reads a Go duration string, refusing zero and negative values.
type Kueue ¶
type Kueue struct {
LocalQueue string `json:"localQueue"`
PriorityClass string `json:"priorityClass,omitempty"`
AdmissionCheck string `json:"admissionCheck,omitempty"`
AdmissionLease *ObjectKey `json:"admissionLease,omitempty"`
}
Kueue turns on Kueue mode; without it the adapter runs in plain mode.
type Launch ¶ added in v0.2.0
type Launch struct {
Image string `json:"image"`
}
Launch says which go/launch image reaches the trainer container. It takes publish's route, since a cluster mounts image volumes or does not (spec 0001 D15).
type Publish ¶
type Publish struct {
Image string `json:"image"`
Via string `json:"via,omitempty"`
InitContainer string `json:"initContainer,omitempty"`
}
Publish says how cmd/publish reaches the trainer container (spec 0001 D15).
type RuntimeRef ¶
RuntimeRef is the required JobSpec extension naming the Trainer runtime a job runs on (spec 0001 D3).
The Go field is Runtime, not the spec's Name, because Extension already claims the method Name; the JSON form is the spec's {"kind","name"}.
func (RuntimeRef) Namespace ¶
func (RuntimeRef) Namespace() string
Namespace implements model.Extension.
func (RuntimeRef) Validate ¶
func (r RuntimeRef) Validate() error
Validate refuses a kind other than the two runtime kinds, and a name that is not a Kubernetes object name.
type Settings ¶
type Settings struct {
Cluster Cluster `json:"cluster,omitzero"`
Namespace string `json:"namespace"`
Runtimes []RuntimeRef `json:"runtimes,omitempty"`
Kueue *Kueue `json:"kueue,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
GPUResource string `json:"gpuResource,omitempty"`
Credentials []Credential `json:"credentials,omitempty"`
NodeLossWindow Duration `json:"nodeLossWindow,omitzero"`
NodeLossTaints []string `json:"nodeLossTaints,omitempty"`
AllowRankRestart bool `json:"allowRankRestart,omitempty"`
Timeouts Timeouts `json:"timeouts,omitzero"`
ProbeRuntime *RuntimeRef `json:"probeRuntime,omitempty"`
Publish *Publish `json:"publish,omitempty"`
Launch *Launch `json:"launch,omitempty"`
}
Settings is the adapter's section of AdapterConfig.Settings (spec 0001 D2), with every default applied by ParseSettings.
func ParseSettings ¶
func ParseSettings(raw json.RawMessage) (Settings, error)
ParseSettings decodes an AdapterConfig.Settings section, refusing unknown keys at every level, applies the defaults and validates the result. Every refusal is ErrInvalid.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
dispatch-admission
command
Command dispatch-admission is the readmission gate's controller (spec 0001 D8), deployed in the cluster beside the ClusterQueue configuration that names its AdmissionCheck.
|
Command dispatch-admission is the readmission gate's controller (spec 0001 D8), deployed in the cluster beside the ClusterQueue configuration that names its AdmissionCheck. |
|
internal
|
|
|
admission
Package admission is the readmission gate's controller (spec 0001 D8): it serves Kueue AdmissionChecks whose controllerName is dispatch's, raising A in a dispatch TrainJob before approving each of its admissions, and approving every other Workload at once.
|
Package admission is the readmission gate's controller (spec 0001 D8): it serves Kueue AdmissionChecks whose controllerName is dispatch's, raising A in a dispatch TrainJob before approving each of its admissions, and approving every other Workload at once. |
|
classify
Package classify maps one consistent read of a TrainJob, its JobSet, its Workload and its pods, with the pod evidence the Watcher captured, to an ObjectObs (spec 0001 D5).
|
Package classify maps one consistent read of a TrainJob, its JobSet, its Workload and its pods, with the pod evidence the Watcher captured, to an ObjectObs (spec 0001 D5). |
|
edit
Package edit changes an object's raw fields in place, so an update writes back every field the adapter does not model unchanged.
|
Package edit changes an object's raw fields in place, so an update writes back every field the adapter does not model unchanged. |
|
kindtest
Package kindtest runs the adapter against a real kind cluster (Kubernetes 1.37, Trainer v2.3.0, JobSet v0.12.0, Kueue v0.20.1, cmd/dispatch-admission deployed in it): go/dispatch's conformance suite in both modes, and the cluster cases of spec 0001's Testing section.
|
Package kindtest runs the adapter against a real kind cluster (Kubernetes 1.37, Trainer v2.3.0, JobSet v0.12.0, Kueue v0.20.1, cmd/dispatch-admission deployed in it): go/dispatch's conformance suite in both modes, and the cluster cases of spec 0001's Testing section. |
|
kname
Package kname checks the Kubernetes name forms the adapter writes, so a bad name is refused before the apiserver sees it.
|
Package kname checks the Kubernetes name forms the adapter writes, so a bad name is refused before the apiserver sees it. |
|
kube
Package kube is the adapter's narrow Kubernetes client (spec 0001 D1, D6, D9, D10): client-go's rest, dynamic and clientcmd, carrying raw objects that the caller decodes with internal/objects.
|
Package kube is the adapter's narrow Kubernetes client (spec 0001 D1, D6, D9, D10): client-go's rest, dynamic and clientcmd, carrying raw objects that the caller decodes with internal/objects. |
|
kube/kubetest
Package kubetest is an in-memory apiserver served over httptest, for tests of the adapter's client and everything above it.
|
Package kubetest is an in-memory apiserver served over httptest, for tests of the adapter's client and everything above it. |
|
objects
Package objects holds the adapter's own decode types for the Kubernetes objects it reads and writes (spec 0001 D1): the fields spec 0001 D3 to D10 use and nothing more.
|
Package objects holds the adapter's own decode types for the Kubernetes objects it reads and writes (spec 0001 D1): the fields spec 0001 D3 to D10 use and nothing more. |
|
podset
Package podset reads the pods of a TrainJob the way spec 0001 D7 requires: in one consistent read of the namespace's pods, Terminating ones included, selected by dispatch's job-id and submission labels and separately by JobSet's jobset-name label, so a rewritten runtime patch cannot hide them.
|
Package podset reads the pods of a TrainJob the way spec 0001 D7 requires: in one consistent read of the namespace's pods, Terminating ones included, selected by dispatch's job-id and submission labels and separately by JobSet's jobset-name label, so a rewritten runtime patch cannot hide them. |
|
render
Package render checks a runtime against spec 0001 D4, turns a submission into the TrainJob and runtime snapshot D3 and D4 describe, and holds the prologue D7 runs in the trainer container.
|
Package render checks a runtime against spec 0001 D4, turns a submission into the TrainJob and runtime snapshot D3 and D4 describe, and holds the prologue D7 runs in the trainer container. |