nomad

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package nomad is a HashiCorp Nomad-backed provider.Provider.

Each ctrlplane Instance maps to one Nomad Job named cp-<instanceID> containing a single TaskGroup with one Task per ServiceSpec. Init services use the prestart lifecycle hook; Sidecars use poststart with sidecar=true; Main services have no lifecycle stanza and run for the group's lifetime. TaskGroup network mode "bridge" gives siblings DNS resolution by service name within the group.

Index

Constants

This section is empty.

Variables

View Source
var ErrLogsNotImplemented = errors.New("nomad: logs not implemented")

ErrLogsNotImplemented is returned by Logs until per-task log streaming is wired (Nomad's logs API is per-allocation + per-task; doable but deferred).

Functions

This section is empty.

Types

type Config

type Config struct {
	// Address is the Nomad API endpoint.
	Address string `default:"http://localhost:4646" env:"CP_NOMAD_ADDRESS" json:"address,omitempty"`

	// Token is the Nomad ACL token for authentication.
	Token string `env:"CP_NOMAD_TOKEN" json:"-"`

	// Region is the Nomad region to target.
	Region string `default:"global" env:"CP_NOMAD_REGION" json:"region"`

	// Namespace is the Nomad namespace for job submissions.
	Namespace string `default:"default" env:"CP_NOMAD_NAMESPACE" json:"namespace"`

	// Datacenter is the Nomad datacenter to schedule into. Empty
	// allows Nomad to pick from all known datacenters.
	Datacenter string `env:"CP_NOMAD_DATACENTER" json:"datacenter,omitempty"`
}

Config holds configuration for the Nomad provider.

type Option

type Option func(*Provider) error

Option configures a Nomad provider.

func WithAddress

func WithAddress(addr string) Option

WithAddress sets the Nomad API endpoint.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig applies all non-zero fields from a Config struct. This is useful when loading configuration from files or environment variables.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace sets the Nomad namespace for job submissions.

func WithRegion

func WithRegion(region string) Option

WithRegion sets the Nomad region to target.

func WithToken

func WithToken(token string) Option

WithToken sets the Nomad ACL token for authentication.

type Provider

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

Provider is a HashiCorp Nomad infrastructure provider.

func New

func New(opts ...Option) (*Provider, error)

New creates a new Nomad provider with the given options. Without any options, sane defaults are used (address: localhost:4646, region: global, namespace: default).

func (*Provider) Capabilities

func (p *Provider) Capabilities() []provider.Capability

Capabilities returns the set of features this provider supports.

func (*Provider) Deploy

Deploy applies per-service image / env updates by patching the Job spec and re-submitting. Nomad's update stanza handles the rolling rollout; ctrlplane just provides the new desired state.

Phase 3 implementation: fetch the current Job, walk req.Services patching matching tasks (image via task.Config.image; env via task.Env merge), then re-submit. Services not in req.Services keep their current image.

func (*Provider) Deprovision

func (p *Provider) Deprovision(ctx context.Context, instanceID id.ID) error

Deprovision deregisters the Nomad Job (the `purge=true` query parameter wipes it from history so re-provisions don't trip the "job exists" guard).

func (*Provider) Exec

Exec is not yet implemented — Nomad supports `nomad alloc exec` via WebSocket; pluggable transport for ExecResult round-trips lands when the exec UI feature is added.

func (*Provider) HealthCheck added in v1.5.1

func (p *Provider) HealthCheck(ctx context.Context) (*provider.HealthStatus, error)

HealthCheck pings the Nomad agent's /v1/agent/health endpoint and reports reachability. Treats any non-2xx as unhealthy.

func (*Provider) Info

func (p *Provider) Info() provider.ProviderInfo

Info returns metadata about this provider.

func (*Provider) Logs

Logs streams logs for one task in the instance's allocation. Phase 3 leaves this stubbed — Nomad's per-task logs API needs an allocation-ID + task-name + frame demuxer; deferred.

func (*Provider) Provision

Provision submits a Nomad Job built from the request's Services. One Job per Instance with a single TaskGroup containing every service as a Task; Init/Sidecar lifecycle hooks order the rollout.

func (*Provider) Resources

func (p *Provider) Resources(ctx context.Context, instanceID id.ID) (*provider.ResourceUsage, error)

Resources returns a one-shot point-in-time sample of the instance's allocation resource usage via Nomad's HTTP API. See stats.go.

func (*Provider) Restart

func (p *Provider) Restart(ctx context.Context, instanceID id.ID) error

Restart triggers a rolling restart by issuing a job-restart RPC. Nomad recreates allocations one at a time honouring the group's update stanza.

func (*Provider) Rollback

func (p *Provider) Rollback(_ context.Context, _ id.ID, _ id.ID) error

Rollback is intentionally a no-op — the deploy.Service builds a new DeployRequest from the prior Release's snapshot and routes it through Deploy. Nomad doesn't need a separate rollback path.

func (*Provider) Scale

func (p *Provider) Scale(ctx context.Context, instanceID id.ID, spec provider.ResourceSpec) error

Scale adjusts the TaskGroup count for an instance.

func (*Provider) Start

func (p *Provider) Start(ctx context.Context, instanceID id.ID) error

Start re-submits the Job to Nomad. Use after Stop to re-schedule. Nomad doesn't have a "start a stopped job" verb — re-submit with the same spec is the canonical pattern.

func (*Provider) Status

func (p *Provider) Status(ctx context.Context, instanceID id.ID) (*provider.InstanceStatus, error)

Status fetches the Job's allocations and aggregates state across every running allocation. Worst-of state wins; per-task state is reported in the Services map keyed by service name.

func (*Provider) Stop

func (p *Provider) Stop(ctx context.Context, instanceID id.ID) error

Stop halts the Job (Nomad keeps the spec for resurrection via Start). Equivalent to `nomad job stop` without `-purge`.

Jump to

Keyboard shortcuts

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