preflight

package
v0.2.0-beta.16 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package preflight runs deterministic pre-deploy checks (DNS, ports, disk, memory, image and git reachability, env, mounts, GPU) and reports pass, warn or fail with a reason and fix hint for each. It only reads: nothing here writes a resource or influences the reconciler.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGitAuth          = errors.New("repository requires credentials")
	ErrGitBranchMissing = errors.New("branch not found")
	ErrGitUnverifiable  = errors.New("url scheme cannot be checked")
)

Git check errors a check maps to a status.

View Source
var (
	ErrImageNotFound     = errors.New("image not found")
	ErrImageUnauthorized = errors.New("image requires credentials")
	ErrImageRateLimited  = errors.New("registry rate limited")
)

Image lookup errors a check maps to a status.

Functions

This section is empty.

Types

type Check

type Check struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Status Status `json:"status"`
	Reason string `json:"reason"`
	Fix    string `json:"fix,omitempty"`
}

Check is one preflight result.

type Env

type Env struct {
	PublicIP       func(ctx context.Context) (string, error)
	LookupHost     func(ctx context.Context, host string) ([]string, error)
	HostPortHolder func(ctx context.Context, nodeID string, port int) (holder string, inUse bool, err error)
	FreeDisk       func(ctx context.Context, nodeID string) (int64, error)
	Memory         func(ctx context.Context, nodeID string) (total, available int64, err error)
	Image          ImageInspector
	Git            GitChecker
	GPUFit         func(ctx context.Context, nodeID string) error
	Limits         Limits
}

Env holds the probes a Run uses. A nil probe skips its check, so a deployment without (say) GPU support simply omits it.

type GitChecker

type GitChecker interface {
	Check(ctx context.Context, repoURL, branch string) error
}

GitChecker verifies a repository is reachable and has a branch.

type ImageInfo

type ImageInfo struct {
	SizeBytes int64
}

ImageInfo is what a manifest lookup learned about an image.

type ImageInspector

type ImageInspector interface {
	Inspect(ctx context.Context, ref string) (ImageInfo, error)
}

ImageInspector resolves an image reference against its registry.

type Limits

type Limits struct {
	Timeout        time.Duration
	MinMemoryBytes int64
	DiskFactor     float64
	MinFreeDisk    int64
	ImageCacheTTL  time.Duration
}

Limits are the tunable thresholds, all overridable by environment.

func LimitsFromEnv

func LimitsFromEnv() Limits

LimitsFromEnv reads the thresholds, falling back to defaults.

type RegistryInspector

type RegistryInspector struct {
	Client *http.Client
	TTL    time.Duration
	// contains filtered or unexported fields
}

RegistryInspector reads manifests over the registry v2 API with anonymous bearer tokens, caching results for TTL.

func (*RegistryInspector) Inspect

func (r *RegistryInspector) Inspect(ctx context.Context, ref string) (ImageInfo, error)

Inspect implements ImageInspector.

type Report

type Report struct {
	Status Status  `json:"status"`
	Checks []Check `json:"checks"`
}

Report is every check's result plus the worst status among them.

func Run

func Run(ctx context.Context, req Request, env Env) Report

Run executes every applicable check in parallel, each bounded by env.Limits.Timeout, and returns results in a stable order.

type Request

type Request struct {
	Name     string
	NodeID   string
	Image    string
	Port     int
	HostPort int
	Domains  []string
	// IsLocalNode is the caller-resolved placement fact (NodeID == "" or
	// the control plane's own node id): this package has no node store of
	// its own, so it can't resolve NodeID itself, only react to it.
	IsLocalNode bool
	MemoryBytes int64
	RequiredEnv []string
	EnvKeys     []string
	BindMounts  []string
	VolumePaths []string
	GPU         bool
	GitURL      string
	GitBranch   string
}

Request describes the app being checked. Zero fields skip the checks that depend on them.

type SmartHTTPChecker

type SmartHTTPChecker struct {
	Client *http.Client
}

SmartHTTPChecker lists refs over git's smart HTTP protocol, so no git binary is spawned. Only http(s) URLs can be checked.

func (*SmartHTTPChecker) Check

func (c *SmartHTTPChecker) Check(ctx context.Context, repoURL, branch string) error

Check implements GitChecker.

type Status

type Status string

Status is one check's outcome.

const (
	StatusPass Status = "pass"
	StatusWarn Status = "warn"
	StatusFail Status = "fail"
)

Check outcomes. Fail blocks a healthy deploy, warn is worth a look.

Jump to

Keyboard shortcuts

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