kubeflow

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 31 Imported by: 0

README

dispatch-kubeflow

Run go/dispatch jobs on Kubeflow Trainer.

Go Reference Pipeline Coverage phpboyscout Go toolkit

The Kubeflow adapter for go/dispatch: TrainJob submission and supervision, deriving typed failure causes from the TrainJob, its JobSet and, where installed, Kueue. Part of the phpboyscout Go toolkit.

Status

The adapter and cmd/dispatch-admission are implemented against spec 0001, the Kubeflow adapter (APPROVED). The module has no release yet. It is tested against Kubernetes 1.37, Kubeflow Trainer v2.3.0, JobSet v0.12.0 and Kueue v0.20.1 on kind v0.33.0 (its default node image), with just test-kind. Decisions are written as specs in this project's wiki.

Documentation

The adapter is documented with the rest of its family on go/dispatch's site, at dispatch.go.phpboyscout.uk/kubeflow: a tutorial, how-to guides, explanation and reference. The Go API is on pkg.go.dev.

Licence

MIT. See LICENSE.

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

View Source
const (
	PublishViaImageVolume   = "imageVolume"
	PublishViaInitContainer = "initContainer"
)

The ways cmd/publish reaches the trainer container (spec 0001 D15).

View Source
const (
	KindClusterTrainingRuntime = "ClusterTrainingRuntime"
	KindTrainingRuntime        = "TrainingRuntime"
)

The runtime kinds a RuntimeRef may name.

View Source
const AdmissionController = "dispatch.phpboyscout.uk/admission"

AdmissionController is the controllerName dispatch's AdmissionCheck names (spec 0001 D8).

View Source
const ExtensionNamespace = "kubeflow"

ExtensionNamespace is the namespace of this adapter's JobSpec extensions.

View Source
const LaunchInitContainer = "dispatch-launch"

LaunchInitContainer is the init container a runtime must define for go/launch under the init container route (spec 0001 D15).

View Source
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).

View Source
const Name = "kubeflow"

Name is the adapter's registry name.

View Source
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

View Source
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.

View Source
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

func Factory

Factory opens the adapter for cfg and runs its preflight (spec 0001 D4).

func Schema

func Schema() []byte

Schema returns the JSON Schema of Settings, additionalProperties false at every level, for a host to mount at its adapter section (spec 0001 D2).

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

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) Close

func (b *Backend) Close() error

Close ends the Backend; later calls fail.

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

func (b *Backend) Find(ctx context.Context, job model.JobID) (model.Discovery, error)

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

func (b *Backend) Hold(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error

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

func (b *Backend) IdentityWeakened(ctx context.Context, spec model.JobSpec) (string, error)

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

func (b *Backend) Inspect(ctx context.Context, ref model.ObjectRef) (model.ObjectObs, error)

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

func (b *Backend) Open(ctx context.Context, ref model.ObjectRef) error

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

func (b *Backend) Progress(ctx context.Context, ref model.ObjectRef) (model.Progress, error)

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

func (b *Backend) Release(ctx context.Context, ref model.ObjectRef, m model.HoldMeta) error

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

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

func (b *Backend) Start(ctx context.Context, req model.StartRequest) (model.ObjectRef, error)

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

func (b *Backend) Stop(ctx context.Context, ref model.ObjectRef, _ string) error

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

func (b *Backend) StopJob(ctx context.Context, job model.JobID, _ string) (model.StopReport, error)

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

func (b *Backend) Watch(ctx context.Context, job model.JobID) (<-chan model.ObjectObs, error)

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

type Duration time.Duration

Duration is a positive time.Duration written as a Go duration string, such as "5m".

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText writes the duration as a Go duration string.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

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 ObjectKey

type ObjectKey struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
}

ObjectKey names a namespaced object.

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

type RuntimeRef struct {
	Kind    string `json:"kind"`
	Runtime string `json:"name"`
}

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) Name

func (RuntimeRef) Name() string

Name implements model.Extension.

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.

func (Settings) CallBound

func (s Settings) CallBound() time.Duration

CallBound is Declarations.CallBound: the apiserver's request timeout plus a margin, because a request already sent can commit until then (spec 0001 D9).

func (Settings) KueueMode

func (s Settings) KueueMode() bool

KueueMode reports whether the settings select Kueue mode.

type Timeouts

type Timeouts struct {
	Request          Duration `json:"request,omitzero"`
	APIServerRequest Duration `json:"apiserverRequest,omitzero"`
	Workload         Duration `json:"workload,omitzero"`
	StopJob          Duration `json:"stopJob,omitzero"`
}

Timeouts bound the adapter's waits (spec 0001 D2).

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.

Jump to

Keyboard shortcuts

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