provider

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package provider is the interface every remote provider implements (spec 8.1).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NameFor

func NameFor(p Provider, secret []byte, prefix, install, pool, size, job string, expiry time.Time, limit int) string

NameFor is the resource name of a job on p: p's own rule when it has one, else the shared <prefix>-<install16>-<pool>-<size>-<job8>-<E> of ResourceNameMax.

func OwnerMatches

func OwnerMatches(secret []byte, name, tag string) bool

OwnerMatches compares in constant time.

func OwnerMatchesPrefix

func OwnerMatchesPrefix(secret []byte, name, tag string) bool

OwnerMatchesPrefix compares tag, in constant time, with the leading characters of the owner tag of name: a resource whose name carries a short tag (Sprites: 8 hex) verifies with it.

func OwnerTag

func OwnerTag(secret []byte, name string) string

OwnerTag is HMAC(install_secret, name): sweep tears down only resources whose tag verifies.

func Register

func Register(typ string, f Factory)

Register adds a provider type; called from provider packages' init.

func RegisterPlugin

func RegisterPlugin(f Factory)

RegisterPlugin installs the factory every plugin section uses (called from the plugin package's init); a plugin type is a config section with a plugin table, not a registered type.

func ResourceName

func ResourceName(prefix, install, pool, size, job string, expiry time.Time) string

ResourceName is <prefix>-<install16>-<pool>-<size>-<job8>-<E unix> (spec 8.7). Only the pool may contain '-', so the name parses from both ends; the pool is truncated to fit.

func ResourceNameMax

func ResourceNameMax(prefix, install, pool, size, job string, expiry time.Time, limit int) string

ResourceNameMax is ResourceName for a provider with a shorter limit (a plugin's max_name, at least 60): only the pool is cut, never below one character, so job8 and E always survive.

func Unmade

func Unmade(err error) error

Unmade marks err as NothingCreated; errors.As still finds the class inside.

func UploadRef

func UploadRef(job string) string

UploadRef is the ref an upload transport's bundle carries, which the host's agent fetches: refs/bitc/upload/<job>. It is shared by the core transport stage and the providers that upload.

Types

type AgentBuild

type AgentBuild struct {
	Commit, Ref, Image, SHA256 string
}

AgentBuild is a pinned agent build: the pod fetches Ref (the hidden ref holding Commit, set by the transport), builds in Image and runs the result only if its sha256 is SHA256.

type ArtifactSpec

type ArtifactSpec struct {
	MaxCompressed int64
	Offset        int64
}

type Boundary

type Boundary uint8

Boundary is how late a failed job may still move on to the next provider (spec 8.2).

const (
	UntilResource Boundary = iota // fall back only before a resource exists
	UntilAttach                   // also after a resource exists, until job input reaches it
)

func ParseBoundary

func ParseBoundary(s string) (Boundary, bool)

ParseBoundary reads "resource" or "attach".

func (Boundary) String

func (b Boundary) String() string

String is the host-file spelling: "resource" or "attach".

type Caps

type Caps struct {
	LiveLogs, Artifacts, Spend, SelfDelete bool
	// Fixed: fixed capacity (slots on a host the owner already has, providers delta C.3). The
	// credential is the provider's own, daily_usd is needed only when it is priced, and the
	// daily comparison is skipped while it is not.
	Fixed         bool
	FallbackUntil Boundary // the latest boundary this provider supports
	// SendEnv is the provider's default caller-env level (the host key send_env overrides it).
	SendEnv EnvLevel
	// MultiJob: a resource serves more than one job, so forced names never reach it (S.4).
	MultiJob bool
}

type Cleaner added in v0.1.1

type Cleaner interface {
	List(ctx context.Context, prefixes []string) ([]Resource, error)
	Owner(ctx context.Context, id string) (string, error)
	Teardown(ctx context.Context, id string) error
}

Cleaner is everything a sweep does with a provider's resources: list them, check an owner tag, delete one. A Provider is one; a cleanup-only handle (Factory.NewCleaner) is only this, so code holding it cannot create, exec or attach.

type DoctorLine

type DoctorLine struct{ Level, Check, Detail string }

DoctorLine is one line of a provider's own `doctor --remote` checks.

type Doctorer

type Doctorer interface {
	DoctorLines(ctx context.Context) []DoctorLine
}

Doctorer is implemented by a provider that adds its own `doctor --remote` checks.

type EnvLevel

type EnvLevel uint8

EnvLevel is how much of the caller's forwarded env may reach a provider (providers delta S.2). The order is EnvNone < EnvForwarded < EnvForced.

const (
	EnvNone      EnvLevel = iota // no caller env crosses
	EnvForwarded                 // plain names cross; forced names never do
	EnvForced                    // forced names may cross too
)

func ParseEnvLevel

func ParseEnvLevel(s string) (EnvLevel, bool)

ParseEnvLevel reads "none", "forwarded" or "forced".

func (EnvLevel) String

func (l EnvLevel) String() string

String is the host-file spelling: "none", "forwarded" or "forced".

type ErrAttached

type ErrAttached struct {
	ID  string
	Err error
	// Ambiguous marks a plugin launch with no definite outcome, or one after which the job's
	// resource was found (providers delta A.5.4, A.5.5). ID is then the resource id found, else
	// the name core assigned, and the adapter has already torn down by name. Walk writes one
	// breaker failure for it; Unconfirmed says the teardown was not confirmed, so the job's
	// reservation stays as an orphan until the sweep or E.
	Ambiguous, Unconfirmed bool
}

ErrAttached: Launch failed after job input reached the resource; the job never falls back.

func (*ErrAttached) Error

func (e *ErrAttached) Error() string

func (*ErrAttached) Unwrap

func (e *ErrAttached) Unwrap() error

type ErrConfig

type ErrConfig struct{ Why string }

ErrConfig is a configuration error found only when a provider starts, such as a plugin's configure answering `config` or a max_name below 60: the call ends with 78 (providers delta A.4.5, A.8). Why carries the host-file text after "<file>: ".

func (*ErrConfig) Error

func (e *ErrConfig) Error() string

type ErrIneligible

type ErrIneligible struct{ Why string }

ErrIneligible: argv, size or request too large; try the next provider (spec 8.1 table).

func (*ErrIneligible) Error

func (e *ErrIneligible) Error() string

type ErrPreAttach

type ErrPreAttach struct {
	ID  string
	Err error
}

ErrPreAttach: Launch made a resource but failed before any job input reached it (spec 8.2). Err is ErrTransient, ErrUnavailable, ErrIneligible or ErrSetup.

func (*ErrPreAttach) Error

func (e *ErrPreAttach) Error() string

func (*ErrPreAttach) Unwrap

func (e *ErrPreAttach) Unwrap() error

type ErrSetup

type ErrSetup struct{ Step, Class, Line string }

ErrSetup is a setup failure the agent reported before BEGIN (spec 8.4, the __BITC_SETUP_FAILED__ marker). Watch returns it once a resource exists, so it is never a fallback. Class "repo" (the repo's own step, root step or service exited non-zero by itself, or a tool's sha256 mismatched) exits 69; "infra", "" or anything unparsable is 75 (spec 8.2, 15.9).

func (*ErrSetup) Error

func (e *ErrSetup) Error() string

func (*ErrSetup) Repo

func (e *ErrSetup) Repo() bool

Repo reports the repo's own failure: retrying cannot help.

type ErrTransient

type ErrTransient struct{ Why string }

ErrTransient: capacity, 429/5xx, network, cap, max_live.

func (*ErrTransient) Error

func (e *ErrTransient) Error() string

type ErrUnavailable

type ErrUnavailable struct {
	Why   string
	Local bool
}

ErrUnavailable: auth, no balance, account disabled. Local marks a cause on this host (missing credentials, an unusable accounting dir): it never pauses the provider (spec 8.3 breaker).

func (*ErrUnavailable) Error

func (e *ErrUnavailable) Error() string

type Factory

type Factory struct {
	Endpoints func(raw map[string]any) ([]string, error)
	New       func(core *config.Provider, eff *config.Effective) (Provider, error)
	// NewCleaner builds the cleanup-only handle of a type whose jobs are refused
	// (config.Provider.CleanupOnly): sweep and doctor --remote use it instead of New.
	NewCleaner func(core *config.Provider, eff *config.Effective) (Cleaner, error)
	SelfDelete func(ctx context.Context, env SelfDeleteEnv) error
	TestOnly   bool // accepted only with a [test] table (the fake)
	// FallbackCap is the latest boundary the type declares for these provider-specific keys
	// (Caps.FallbackUntil); nil means UntilResource. A built-in's host default is this value.
	FallbackCap func(raw map[string]any) Boundary
	// DefaultResource: the host default is UntilResource whatever FallbackCap says (a plugin).
	DefaultResource bool
	// SendEnv is the type's default caller-env level for these provider-specific keys; nil means
	// EnvForwarded (a plugin). MultiJob reports whether its resources serve more than one job.
	SendEnv  func(raw map[string]any) EnvLevel
	MultiJob func(raw map[string]any) bool
	// Validate checks the provider-specific keys against the decoded core section (its name
	// prefix and credential too) and returns the host-file problems, each as the text after
	// `providers.<type>.`; nil means none.
	Validate func(core *config.Provider) []string
	// Fixed: a fixed-capacity type (providers delta C.3); MaxLiveDefault is its max_live default.
	Fixed          bool
	MaxLiveDefault func(raw map[string]any) int
}

Factory registers a provider type (spec 8.5).

func Get

func Get(typ string) (Factory, bool)

func Lookup

func Lookup(typ string, core *config.Provider) (Factory, bool)

Lookup finds the factory for a configured provider section: the plugin factory for a section with a plugin table, else the built-in registered under typ.

type ForeignOrg

type ForeignOrg interface {
	error
	ForeignOrg() (name, org string)
}

ForeignOrg is implemented by the error of a listing that failed because a resource belongs to another organization: the sweep, doctor and status name it, and never touch it.

type Handle

type Handle struct {
	ID, Name   string
	ResultsURL string // base URL of the results server, ".../v1/"
	// Created is when the resource began to bill, when that is before Launch returned (Sprites:
	// the create's 201, ahead of provisioning); zero means Launch's return.
	Created time.Time
}

type Info

type Info struct {
	Type      string
	Caps      Caps
	Endpoints []string // every host the provider talks to (API and results)
	// Arch lists the linux architectures the provider can run ("amd64", "arm64"); empty means
	// amd64 only (spec 8.1, providers delta C.4).
	Arch []string
	// MaxName is the longest resource name the provider accepts, at most 63 (0 means 63). A
	// plugin declares it in configure (providers delta A.4.5).
	MaxName int
}

type JobSpec

type JobSpec struct {
	Job, Pool    string
	Argv         []string // argv[0] reduced to its basename
	Cwd          string   // relative to the work tree
	Env          []string // remote env, KEY=VALUE
	CloneURL     string
	Ref          string
	Sha          string
	SizeKey      string
	Timeout      time.Duration
	Created      time.Time
	Deadline     time.Time // D = create + start_timeout + timeout
	Expiry       time.Time // E = D + 15m
	Artifacts    []config.Artifact
	Packages     []string
	Tools        []config.Tool // only the entries for Arch
	Arch         string        // the linux architecture the job runs on (set by preflight)
	Setup        []config.Step
	Services     []config.Service
	RootSteps    bool
	RepoID       string
	DeploySecret string
	// DeployKeyFile is the path of the repo's read-only deploy key on the host ([[repos]]
	// deploy_key_file) for a provider that delivers the key itself (Sprites); the bytes are read
	// by that provider's Launch and never held in the job object.
	DeployKeyFile  string
	Bearer, MacKey [32]byte // B and K (spec 8.4)
	Nonce          [32]byte // M
	Install        string   // install16
	Name           string   // resource name, set by the provider's naming rule
	MaxName        int      // the longest name Name may have (Info.MaxName; 0 means 63)
	DeployKey      string   // the deploy key bytes for a plugin's launch secrets; never in the job object
	Owner          string   // OwnerTag(install secret, Name)
	AgentURL       string
	AgentSHA256    string
	AgentBuild     *AgentBuild // agent source "build": the pod builds the agent (spec 8.4 step 1); AgentURL is then empty
	Unprivileged   bool        // test runs only ([test] set): the agent runs as a plain process
	TestRoot       string      // test runs only: the fake pod's private dir
}

JobSpec is one remote job (spec 8.1).

type Namer

type Namer interface {
	ResourceName(secret []byte, prefix, install, pool, size, job string, expiry time.Time, limit int) string
}

Namer is implemented by a provider whose resource names follow their own rule (Sprites carries the owner tag in the name, sprites-provider.md 2.1). limit is Info.MaxName.

type NothingCreated

type NothingCreated interface{ NothingCreated() bool }

NothingCreated is implemented by a Launch error that proves no resource was made (an unreachable host, a refusal before anything ran): the core then skips its name lookup and its create retry, and the walk moves on at once (providers delta C.5.1, C.6).

type Phase

type Phase string
const (
	Booting Phase = "booting"
	Begun   Phase = "begun"
	Ended   Phase = "ended"
	Lost    Phase = "lost"
)

type Provider

type Provider interface {
	Info() Info
	Preflight(ctx context.Context, j *JobSpec) error
	Estimate(ctx context.Context, j *JobSpec) (config.Micros, error)
	Launch(ctx context.Context, j *JobSpec) (Handle, error)
	Watch(ctx context.Context, h Handle, out Sink) (Result, error)
	Output(ctx context.Context, h Handle, s Stream, off int64, w io.Writer) error
	Fetch(ctx context.Context, h Handle, a ArtifactSpec, w io.Writer) error
	Owner(ctx context.Context, id string) (string, error)
	Teardown(ctx context.Context, id string) error
	List(ctx context.Context, prefixes []string) ([]Resource, error)
	Spend(ctx context.Context) (config.Micros, error)
}

type Resource

type Resource struct {
	ID, Name, Install, Pool, Job, SizeKey string
	USDPerHour                            config.Micros
	Created, Expires                      time.Time
	State                                 string // starting | running | exited | gone
}

type Result

type Result struct {
	Exit  int
	Began bool
	Why   string
}

type Runtime

type Runtime struct {
	Red    *redact.Set
	Stderr io.Writer
	Debug  bool
}

Runtime is what a Starter needs from the host: the redactor every secret joins before it is written to the child, the stderr for debug lines, and whether BITC_LOG=debug is set.

type SecretUser added in v0.1.3

type SecretUser interface {
	UseInstallSecret([]byte)
}

SecretUser is implemented by a provider or cleanup handle that verifies owner tags with the install secret: the sweep hands it the secret it has already read, so a network-filesystem home (where the provider's own account-dir lookup is refused) still verifies.

type SelfDeleteEnv

type SelfDeleteEnv struct {
	ResourceID string
	ScopedKey  string // the pod-scoped key the provider injects; never logged
	APIBase    string
}

SelfDeleteEnv is what the agent's self-delete hook gets (from PID 1's env at boot).

type Sink

type Sink interface {
	Phase(p Phase, why string)
	Setup(line string)      // a pre-BEGIN log line (printed as "pod: <line>")
	Out(s Stream, b []byte) // live command output (Caps.LiveLogs)
}

Sink receives what Watch observes.

type SlotHold

type SlotHold struct {
	Slots   []int
	Name    string
	Install string
	Until   time.Time // the lease's end
}

SlotHold is one held slot group.

type SlotReporter

type SlotReporter interface {
	SlotStatus(ctx context.Context) (SlotStatus, error)
}

SlotReporter is implemented by a fixed-capacity provider; `status` adds a slots section.

type SlotStatus

type SlotStatus struct {
	Total int
	Held  []SlotHold
}

SlotStatus is a fixed-capacity provider's slots as `status` shows them: how many it owns and which groups are held now (by any controller; Install tells whose).

type Starter

type Starter interface {
	Start(ctx context.Context, rt Runtime) error
}

Starter is implemented by a provider that must be started before use (a plugin process: hello, configure). Walk, doctor and sweep call Start once, right after the constructor.

type Stream

type Stream int
const (
	Stdout Stream = iota
	Stderr
	ResultFile // result.json on the results server
	StateFile  // state.json
)

type SweepPolicy

type SweepPolicy struct {
	Noun          string        // "sprite": the word in `swept sprite <name> (...)`
	GoneAfter     time.Duration // an own resource with no reservation older than this is deleted; 0 = never
	TimerRequired bool          // doctor --remote fails when no sweep ran in the last 30 minutes
	TimerAdvice   string        // else, a doctor check of this name warns when none did (the provider self-deletes)
}

SweepPolicy is a provider's sweep behaviour beyond "own, past E, owner tag verifies".

type SweepRules

type SweepRules interface {
	SweepRules() SweepPolicy
}

SweepRules is implemented by a provider whose resources are one per job and die with it (a Sprite): the sweep then names them with Noun, also deletes an own resource that no live reservation on this host accounts for once it is older than GoneAfter ("job process gone"), and the sweep timer is mandatory (doctor --remote fails when no sweep ran in the last TimerEvery x 2).

Directories

Path Synopsis
Package fake is a test-only provider that runs the job as a local process.
Package fake is a test-only provider that runs the job as a local process.
Package plugin is the adapter that runs an external provider executable (spec 8.5, providers delta A) behind the Provider interface: one pinned process per bitc process and type, NDJSON on its stdin and stdout, secrets on fd 3.
Package plugin is the adapter that runs an external provider executable (spec 8.5, providers delta A) behind the Provider interface: one pinned process per bitc process and type, NDJSON on its stdin and stdout, secrets on fd 3.
pin
Package pin checks and opens a pinned provider plugin (providers delta A.2): an absolute path and a sha256, a regular ELF file owned by the user or root, no group or world write on it or any parent, no setuid or setgid bit, no file capabilities.
Package pin checks and opens a pinned provider plugin (providers delta A.2): an absolute path and a sha256, a regular ELF file owned by the user or root, no group or world write on it or any parent, no setuid or setgid bit, no file capabilities.
stubplugin command
Command stubplugin is a minimal provider plugin for bitc's own tests (providers delta P.1): a protocol-1 peer with fault modes, driven by the `fault` key of its [providers.<t>] section (or STUB_HELLO_FAULT for faults before configure).
Command stubplugin is a minimal provider plugin for bitc's own tests (providers delta P.1): a protocol-1 peer with fault modes, driven by the `fault` key of its [providers.<t>] section (or STUB_HELLO_FAULT for faults before configure).
Package runpod is the RunPod provider (spec 8.7): CPU pods over REST v2.
Package runpod is the RunPod provider (spec 8.7): CPU pods over REST v2.
runpodfake
Package runpodfake is a fake RunPod REST v2 API for tests (spec 11): every created pod is a local `bitc __agent` process in its own process group, its stdout is the container log, and a second loopback server proxies /<pod>-<port>/v1/<file> to the agent's results server.
Package runpodfake is a fake RunPod REST v2 API for tests (spec 11): every created pod is a local `bitc __agent` process in its own process group, its stdout is the container log, and a second loopback server proxies /<pod>-<port>/v1/<file> to the agent's results server.
Package sprites is the Fly Sprites client (sprites-provider.md): the REST calls a fresh-Sprite-per-job provider needs, the WebSocket exec channel, the error classes of 1.2 and the pre-attach / attached classification of 1.3.
Package sprites is the Fly Sprites client (sprites-provider.md): the REST calls a fresh-Sprite-per-job provider needs, the WebSocket exec channel, the error classes of 1.2 and the pre-attach / attached classification of 1.3.
liveprobe
Package liveprobe is the Sprites probe kit: a scripted, capped runner that answers the open items of docs/design/sprites-provider.md section 9 against the live Sprites API.
Package liveprobe is the Sprites probe kit: a scripted, capped runner that answers the open items of docs/design/sprites-provider.md section 9 against the live Sprites API.
spritesfake
Package spritesfake is a strict fake of the Fly Sprites API for tests (sprites-provider.md 8.1): an httptest REST server plus a WSS exec endpoint.
Package spritesfake is a strict fake of the Fly Sprites API for tests (sprites-provider.md 8.1): an httptest REST server plus a WSS exec endpoint.
ssh
Package ssh is the fixed-capacity provider (providers delta C): jobs run on one host the owner already has, reached over the system OpenSSH client, with a number of slots instead of a price.
Package ssh is the fixed-capacity provider (providers delta C): jobs run on one host the owner already has, reached over the system OpenSSH client, with a number of slots instead of a price.
sshfake
Package sshfake is the ssh provider's test double (providers delta C.11): a fake host gate.
Package sshfake is the ssh provider's test double (providers delta C.11): a fake host gate.
sshfake/gate command
Command sshfakegate is the fake ssh host gate the conformance suite runs in place of ssh (providers delta C.11): `sshfakegate --root DIR -- <gate command line>`.
Command sshfakegate is the fake ssh host gate the conformance suite runs in place of ssh (providers delta C.11): `sshfakegate --root DIR -- <gate command line>`.

Jump to

Keyboard shortcuts

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