slurm

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 32 Imported by: 0

README

dispatch-slurm

Run go/dispatch jobs on Slurm, over SSH to a login node or from the login node itself.

Go Reference Pipeline Coverage phpboyscout Go toolkit

The Slurm adapter for go/dispatch. One module owns the meaning (Slurm states to typed causes, the job vocabulary to sbatch, per-cluster capabilities); its transports, local and ssh, are interchangeable underneath. Part of the phpboyscout Go toolkit.

Status

Implemented for Slurm 25.11 and 26.05, tested against 25.11.8 and 26.05.4 in sind. There is no release yet. The design is spec 0001, the Slurm adapter, in this project's wiki.

import _ "gitlab.com/phpboyscout/go/dispatch-slurm" // registers the adapter as "slurm"

Testing against a real Slurm

go test ./... uses recorded transcripts only. internal/sind runs go/dispatch's conformance suite, plus the read-back and landing-bound checks it skips, against a sind cluster in docker, over the SSH transport, the local transport (the test binary copied onto the controller) and a docker exec stand-in. Faults are injected on every delivery but local. It needs docker, ssh, ssh-keygen and a sind binary, and takes about 35 minutes per Slurm version:

just sind 25.11.8   # or 26.05.4

Documentation

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

Licence

MIT. See LICENSE.

Documentation

Overview

Package slurm is go/dispatch's adapter for Slurm 25.11 and 26.05. A consumer blank-imports it and names "slurm" as its adapter; slurm.New builds a Backend directly. It owns the meaning: the strictly decoded configuration and its schema, classification of Slurm's v0.0.44 JSON, the gated batch script, the command vocabulary with its identity check and deadline wrapper, and preflight. Scripts reach the cluster through the transport packages, locally on a login node or over SSH.

Spec: https://gitlab.com/phpboyscout/go/dispatch-slurm/-/wikis/specs/0001-the-slurm-adapter

Index

Constants

View Source
const (
	TransportLocal = "local"
	TransportSSH   = "ssh"
)

The transports a configuration may name (spec 0001 D3).

View Source
const (
	SourceKubernetes = "kubernetes"
	SourceSlurmNode  = "slurm-node"
	SourceCommand    = "command"
)

The cessation sources.

View Source
const (
	BootTimeKernel  = "kernel"
	BootTimeUnknown = "unknown"
)

What a node's BootTime is, as cessation.bootTime declares it: the kernel's boot, or not known to be, as under slurmd -b, where it is slurmd's start.

View Source
const (
	KubeAccessDirect = "direct"
	KubeAccessSSH    = "ssh"
	KubeAccessAuto   = "auto"
)

How the Kubernetes source reaches its API server: directly, through the SSH connection, or directly and then through SSH when the transport is ssh.

View Source
const ControlPathNone = ssh.ControlPathNone

ControlPathNone turns ControlMaster off.

View Source
const Name = "slurm"

Name is the adapter's registry name, under which init registers its factory.

View Source
const NodePodNodeName = "node-name"

NodePodNodeName maps a Slurm node to the pod of the same name, as Soperator names them; no other mapping exists yet.

Variables

View Source
var ErrExpired = fmt.Errorf("%w: the call started past its deadline", model.ErrRejected)

ErrExpired is a deadline-carrying call whose deadline had passed on the Slurm host when it was due to start, so it did nothing (spec 0001 D5, D7).

Functions

func RegisterTransport

func RegisterTransport(name string, f TransportFactory) error

RegisterTransport makes a transport available to the transport key under name. A duplicate is model.ErrAlreadyRegistered, never an overwrite.

func Schema

func Schema() []byte

Schema returns the JSON Schema document of Config, additionalProperties false at every level, for a host to mount at its adapter section with go/config-schema (spec 0001 D3).

Types

type Backend

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

Backend is the Slurm adapter: a dispatch.Backend that is also a dispatch.Holder, Requeuer, CessationSignal, OutputReader and MultiFinder.

func New

func New(ctx context.Context, cfg Config, opts ...Option) (*Backend, error)

New validates cfg, opens its transport and runs preflight, whose results fix the Backend's declarations and capabilities (spec 0001 D8).

func (*Backend) Capabilities

func (b *Backend) Capabilities(context.Context, *model.JobSpec) (map[model.Capability]model.Support, error)

Capabilities implements dispatch.Backend with spec 0001 D9's table; Hold and AccountingHistory are the probe's.

func (*Backend) Ceased

Ceased implements dispatch.CessationSignal from the sources cessation.sources names, those the Backend can reach: the Kubernetes source, the Slurm node under cessation.bootTime kernel, and the site's command (spec 0002 D6, D7); Detail names a Slurm-node source left out. last is the latest execution the record saw started, so the answer outlives slurmctld's purge of the job; one with no nodes or no start is never ceased. The object has ceased when, for every node, at least one source says so; an error from one source is not evidence, and Ceased errs only when every source errs. One call is bounded by cessation.timeout. It works on a read-only Backend.

func (*Backend) Close

func (b *Backend) Close() error

Close implements dispatch.Backend; it closes the transport.

func (*Backend) Declarations

func (b *Backend) Declarations() model.Declarations

Declarations implements dispatch.Backend; they are fixed by preflight.

func (*Backend) DispatchBackend

func (b *Backend) DispatchBackend() dispatch.Backend

DispatchBackend returns b as dispatch.Open hands it out. On a cluster whose AuthType gives no landing bound, that is b without Holder and Requeuer: it cannot bound when a hold or requeue lands, so it declares a zero CallBound, and go/dispatch spec 0003 allows a zero CallBound only without both.

func (*Backend) Find

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

Find implements dispatch.Backend (spec 0001 D5).

func (*Backend) FindMany

func (b *Backend) FindMany(ctx context.Context, jobs []model.JobID, states ...model.ObjectState) (map[model.JobID]model.Discovery, error)

FindMany implements dispatch.MultiFinder: one squeue for every job's name, keeping only objects in states when any are named.

func (*Backend) Hold

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

Hold implements dispatch.Holder: a far-future StartTime encoding the instance against the object's current submit time, behind the host-side deadline wrapper (spec 0001 D5, D7).

func (*Backend) Inspect

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

Inspect implements dispatch.Backend: squeue first, then sacct when the job is gone from slurmctld and AccountingHistory is Yes (spec 0001 D5).

func (*Backend) Open

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

Open implements dispatch.Backend: scontrol release, after the identity check and refusing a hold that is not the gate (spec 0001 D5).

func (*Backend) Output

func (b *Backend) Output(ctx context.Context, job model.JobID, submission int, s dispatch.Stream, follow bool) (io.ReadCloser, error)

Output implements dispatch.OutputReader (spec 0001 D12): the manifest Start wrote names each stream's prefix and suffix; the execution files under it are read in restart order, numerically, and with follow set the stream is followed until ctx ends or the reader is closed.

func (*Backend) Progress

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

Progress implements dispatch.ProgressReader with one squeue and one read of the current execution's beat file (spec 0001 D12).

func (*Backend) Release

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

Release implements dispatch.Holder: StartTime=now, only when the instance in force, decoded against the current submit time, is the one m names.

func (*Backend) Requeue

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

Requeue implements dispatch.Requeuer: Requeue=1, scontrol requeue and Requeue=0 in one detached script, each behind the deadline check, the last run whatever the second returned (spec 0001 D5, D7).

func (*Backend) RestoreRequeueBit

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

RestoreRequeueBit implements dispatch.Requeuer: one wrapped Requeue=0.

func (*Backend) Rules

Rules implements dispatch.Backend (spec 0001 D9, 0003 D3).

func (*Backend) Start

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

Start implements dispatch.Backend: one script creates the output directory, writes the manifest and submits gated; read-back then proves the object is what was asked for (spec 0001 D5, D6).

func (*Backend) Stop

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

Stop implements dispatch.Backend: scancel by name and id, so a reused id, which carries another name, is left alone; then squeue verifies (spec 0001 D5). There is no --state=PENDING, because Stop cannot tell a retirement from a stop without racing.

func (*Backend) StopJob

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

StopJob implements dispatch.Backend: scancel every object of the job by name, then verify in rounds until nothing is alive and every cancelled job's nodes are up, re-issuing the scancel each round, up to KillWait + SlurmdTimeout + 60 s (spec 0001 D5, 0003 D6).

func (*Backend) Warnings

func (b *Backend) Warnings() []string

Warnings are what the last Open found worth saying about the Backend's optional sources, each once: a Kubernetes source it could not reach, a rule its credential lacks (spec 0002 D5), a listed Slurm-node source that cessation.bootTime leaves out (D7).

type Cessation

type Cessation struct {
	Command  string   `json:"command,omitempty"`
	Timeout  Duration `json:"timeout,omitzero"`
	BootTime string   `json:"bootTime,omitempty"`
	Sources  []string `json:"sources,omitzero"`
	// contains filtered or unexported fields
}

Cessation configures dispatch.CessationSignal: which sources answer, and the site command when one does (spec 0002 D6, D7). Decoding always sets it. Sources is nil for the default and empty for none, which leaves Ceased ErrUnsupported. BootTime is BootTimeKernel only where slurmd runs without -b, and the Slurm-node source runs only then.

type Config

type Config struct {
	Transport   string      `json:"transport,omitempty"`
	SSH         *SSH        `json:"ssh,omitempty"`
	Defaults    Defaults    `json:"defaults,omitzero"`
	Output      Output      `json:"output,omitzero"`
	Environment Environment `json:"environment,omitzero"`
	Singleton   bool        `json:"singleton,omitempty"`
	Cessation   *Cessation  `json:"cessation,omitempty"`
	Kubernetes  *Kubernetes `json:"kubernetes,omitempty"`
	Preflight   Preflight   `json:"preflight,omitzero"`
	Timeouts    Timeouts    `json:"timeouts,omitzero"`
}

Config is the adapter's configuration section, AdapterConfig.Settings (spec 0001 D3). The zero value of an optional field means its default.

type Defaults

type Defaults struct {
	Partition   string `json:"partition,omitempty"`
	Account     string `json:"account,omitempty"`
	QOS         string `json:"qos,omitempty"`
	Reservation string `json:"reservation,omitempty"`
	Constraint  string `json:"constraint,omitempty"`
}

Defaults are sbatch placement defaults, which slurm.Placement overrides per job.

type Duration

type Duration time.Duration

Duration is a positive time.Duration written as a Go duration string, such as "10s".

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 Environment

type Environment struct {
	Pass []string `json:"pass,omitzero"`
}

Environment lists the variables copied into the batch script at Start. Pass is nil for the default and empty to pass nothing.

type Kubernetes

type Kubernetes struct {
	Server              string `json:"server"`
	Access              string `json:"access,omitempty"`
	TokenFile           string `json:"tokenFile"`
	CAFile              string `json:"caFile"`
	Namespace           string `json:"namespace"`
	ControllerPod       string `json:"controllerPod,omitempty"`
	ControllerContainer string `json:"controllerContainer,omitempty"`
	NodePod             string `json:"nodePod,omitempty"`
}

Kubernetes is the Kubernetes evidence source's API server and credential (spec 0002 D5, D8). The token and CA are files on the caller's host, read at every Open; the token is never logged or stored.

type Option

type Option func(*options)

Option configures New.

func ReadOnly

func ReadOnly() Option

ReadOnly opens a Backend whose writing calls return dispatch.ErrReadOnly before any command, and whose preflight submits no probe.

func WithClock

func WithClock(now func() time.Time) Option

WithClock reads the caller's time from now, which Find's At and horizon, preflight's clock offset and StopJob's bound use.

func WithExecutor

func WithExecutor(e transport.Executor) Option

WithExecutor runs scripts through e instead of the configured transport. The Backend owns e from then on, and closes it.

type Output

type Output struct {
	Dir string `json:"dir,omitempty"`
}

Output says where each execution's output goes on the cluster.

type Placement

type Placement struct {
	Partition   string `json:"partition,omitempty"`
	Account     string `json:"account,omitempty"`
	QOS         string `json:"qos,omitempty"`
	Reservation string `json:"reservation,omitempty"`
	Constraint  string `json:"constraint,omitempty"`
}

Placement chooses where a job runs; each non-empty field overrides the matching defaults.* setting for that job.

func (Placement) Name

func (Placement) Name() string

Name implements dispatch.Extension.

func (Placement) Namespace

func (Placement) Namespace() string

Namespace implements dispatch.Extension.

type Preflight

type Preflight struct {
	CacheDir string   `json:"cacheDir,omitempty"`
	MaxAge   Duration `json:"maxAge,omitzero"`
}

Preflight configures the preflight cache on the caller's host. CacheDir must be a real directory of mode 0700 owned by the caller, and is created so when missing; a cache found anywhere else, or through a symlink, is not read.

type Resources

type Resources struct {
	GPUType       string `json:"gpuType,omitempty"`
	CPUsPerTask   int    `json:"cpusPerTask,omitempty"`
	MemPerNodeMiB int    `json:"memPerNodeMiB,omitempty"`
	Exclusive     bool   `json:"exclusive,omitempty"`
}

Resources asks Slurm for what JobSpec has no field for: a GPU type, CPUs per task, memory per node and exclusive nodes.

func (Resources) Name

func (Resources) Name() string

Name implements dispatch.Extension.

func (Resources) Namespace

func (Resources) Namespace() string

Namespace implements dispatch.Extension.

type SSH

type SSH struct {
	Host           string   `json:"host"`
	User           string   `json:"user,omitempty"`
	Port           int      `json:"port,omitempty"`
	IdentityFile   string   `json:"identityFile,omitempty"`
	ProxyJump      string   `json:"proxyJump,omitempty"`
	KnownHostsFile string   `json:"knownHostsFile,omitempty"`
	ConfigFile     string   `json:"configFile,omitempty"`
	ConnectTimeout Duration `json:"connectTimeout,omitzero"`
	ControlPath    string   `json:"controlPath,omitempty"`
	ControlPersist Duration `json:"controlPersist,omitzero"`
}

SSH is the closed set of ssh options the adapter can express; it is only valid with transport ssh.

type Timeouts

type Timeouts struct {
	Command    Duration `json:"command,omitzero"`
	Sacct      Duration `json:"sacct,omitzero"`
	Kubernetes Duration `json:"kubernetes,omitzero"`
}

Timeouts bounds commands that carry no bound of their own. Sacct bounds each sacct call on the Slurm host: a hung slurmdbd keeps its port open and sacct then waits indefinitely (spec 0002 D2). Kubernetes bounds each read of the Kubernetes source (D5).

type TransportFactory

type TransportFactory func(ctx context.Context, cfg Config) (transport.Executor, error)

TransportFactory builds the Executor for a configuration whose transport names it.

Directories

Path Synopsis
internal
cmd/keysetgen command
Command keysetgen derives the data_parser v0.0.44 key set of a squeue or `scontrol show job` response from the Slurm source, and writes it as Go.
Command keysetgen derives the data_parser v0.0.44 key set of a squeue or `scontrol show job` response from the Slurm source, and writes it as Go.
hook
Package hook carries seams the module's own test harnesses need and the public API does not offer.
Package hook carries seams the module's own test harnesses need and the public API does not offer.
privatedir
Package privatedir creates and checks directories only their owner may reach.
Package privatedir creates and checks directories only their owner may reach.
sind
Package sind stands up a sind Slurm cluster in docker and injects the faults go/dispatch's conformance suite asks for, so the adapter can be checked against a real slurmctld (spec 0001, Testing).
Package sind stands up a sind Slurm cluster in docker and injects the faults go/dispatch's conformance suite asks for, so the adapter can be checked against a real slurmctld (spec 0001, Testing).
Package kube is the Slurm adapter's read-only client of the Kubernetes API: a pod, the slurmctld log, and whether the adapter's credential may read each (spec 0002 D5).
Package kube is the Slurm adapter's read-only client of the Kubernetes API: a pod, the slurmctld log, and whether the adapter's credential may read each (spec 0002 D5).
Package slurmtest replays recorded transcripts in place of a Slurm host, for the adapter's own tests and for consumers' tests: an Executor that answers each script with its recorded Result, and fixtures that render Slurm's v0.0.44 job JSON from captures.
Package slurmtest replays recorded transcripts in place of a Slurm host, for the adapter's own tests and for consumers' tests: an Executor that answers each script with its recorded Result, and fixtures that render Slurm's v0.0.44 job JSON from captures.
Package transport is the seam between the Slurm adapter's meaning and the delivery of its scripts to the Slurm host: the Executor contract, Script and Result, and the output framing every transport shares.
Package transport is the seam between the Slurm adapter's meaning and the delivery of its scripts to the Slurm host: the Executor contract, Script and Result, and the output framing every transport shares.
local
Package local runs the Slurm adapter's scripts on this host, for a supervisor that runs on a login node.
Package local runs the Slurm adapter's scripts on this host, for a supervisor that runs on a login node.
ssh
Package ssh runs the Slurm adapter's scripts on a login node through the OpenSSH client binary, which brings the user's agent, keys, ssh_config, ControlMaster and site two-factor setups unchanged.
Package ssh runs the Slurm adapter's scripts on a login node through the OpenSSH client binary, which brings the user's agent, keys, ssh_config, ControlMaster and site two-factor setups unchanged.

Jump to

Keyboard shortcuts

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