updates

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 19 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 updates finds images whose tag points to a newer digest in the registry (#53, ADR-0030). Only the registry digest is stored; whether an update is available is decided when reading, against the local image at that moment, so a pull clears it at once.

Index

Constants

View Source
const (
	KindContainer = "container"
	KindStack     = "stack"

	StatusUpdated = "updated"
	StatusFailed  = "failed"
	StatusSkipped = "skipped"
)

Auto-update kinds and statuses, as stored in the log.

View Source
const AutoUser = "nerdui (auto-update)"

AutoUser is the job user of automatic updates.

View Source
const DefaultInterval = 6 * time.Hour

DefaultInterval applied until an administrator chose another; the interval of nerdui 0.2.0-alpha.1 is read once to create the image update schedule (#82).

View Source
const DefaultMaxBatch = 5

DefaultMaxBatch applies until an administrator chooses another.

View Source
const Label = "nerdui.auto-update"

Label opts a container, or a compose service, in to automatic updates (#54, ADR-0032): nerdui.auto-update=true. Nothing is updated without it.

Variables

View Source
var Delays = []time.Duration{0, time.Hour, 6 * time.Hour, 24 * time.Hour, 72 * time.Hour, 168 * time.Hour}

Delays are the allowed minimum ages of a new image before it is applied (#56).

View Source
var (
	// ErrBusy is returned while a check of the environment runs.
	ErrBusy = errors.New("a check is already running")
)
View Source
var ErrInvalidAutoSettings = errors.New("invalid automatic update settings")

ErrInvalidAutoSettings is returned for settings outside Delays and MaxBatches.

View Source
var ErrNothingPending = errors.New("no automatic updates wait for approval")

ErrNothingPending is returned when approving without waiting updates.

View Source
var ErrUpdating = errors.New("automatic updates are already running")

ErrUpdating is returned while automatic updates of the environment run.

View Source
var Intervals = []time.Duration{0, time.Hour, 6 * time.Hour, 12 * time.Hour, 24 * time.Hour}

Intervals are the allowed check intervals; 0 turns scheduled checks off.

View Source
var MaxBatches = []int{0, 1, 3, 5, 10, 20}

MaxBatches are the allowed thresholds above which updates wait for approval; 0 never asks.

Functions

func AutoEnabled added in v0.2.0

func AutoEnabled(labels map[string]string) bool

AutoEnabled reports whether labels opt in to automatic updates.

Types

type AutoSettings added in v0.2.0

type AutoSettings struct {
	// DelaySeconds is how long a new registry digest must have been seen before it is applied.
	DelaySeconds int64 `json:"delaySeconds"`
	// MaxBatch: when more updates than this are due at once, they wait for approval (0: never).
	MaxBatch int `json:"maxBatch"`
}

AutoSettings guard automatic updates of an environment (#56, ADR-0033). Keep in sync with api/openapi.yaml.

type AutoStore added in v0.2.0

type AutoStore interface {
	ListImageUpdates(ctx context.Context, environment string) ([]db.ImageUpdate, error)
	AddAutoUpdate(ctx context.Context, arg db.AddAutoUpdateParams) error
	LastAutoUpdate(ctx context.Context, arg db.LastAutoUpdateParams) (db.AutoUpdate, error)
	ListAutoUpdates(ctx context.Context, arg db.ListAutoUpdatesParams) ([]db.AutoUpdate, error)
	PruneAutoUpdates(ctx context.Context, arg db.PruneAutoUpdatesParams) error
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, arg db.SetSettingParams) error
}

AutoStore is the database used by the updater; *db.Queries of the write connection implements it.

type Checker

type Checker struct {
	Environments *environment.Registry
	Store        Store
	Logger       *slog.Logger
	Now          func() time.Time
	// AfterCheck runs after each successful scheduled check, e.g. Updater.Run (#54).
	AfterCheck func(ctx context.Context, env *environment.Environment) error
	// NextCheck is when the scheduler checks an environment next (#82); nil when no schedule is
	// enabled.
	NextCheck func(ctx context.Context, env string) *time.Time
	// Notify, when set, receives an event when a check finds new images for tags in use (#96).
	Notify func(notify.Event)
	// contains filtered or unexported fields
}

Checker checks the images used by containers on a schedule and on request.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, env *environment.Environment, ref string) (Report, error)

Check resolves in the registry the references used by containers of every namespace, or only ref when given (used or not).

func (*Checker) CheckAndUpdate added in v0.2.0

func (c *Checker) CheckAndUpdate(ctx context.Context, env *environment.Environment) error

CheckAndUpdate checks an environment and then runs AfterCheck (automatic updates): the scheduled image update check (#82).

func (*Checker) Interval

func (c *Checker) Interval(ctx context.Context, env string) (time.Duration, error)

Interval returns the environment's check interval.

func (*Checker) Overview

func (c *Checker) Overview(ctx context.Context, env *environment.Environment, ns string) (Overview, error)

Overview reports the stored checks of the references present in a namespace: those used by containers, and any other image of the namespace that was checked.

type Entry added in v0.2.0

type Entry struct {
	ID         int64     `json:"id"`
	Namespace  string    `json:"namespace"`
	Kind       string    `json:"kind"`
	Name       string    `json:"name"`
	Refs       []string  `json:"refs"`
	Status     string    `json:"status"`
	Message    string    `json:"message,omitempty"`
	JobID      string    `json:"jobId,omitempty"`
	StartedAt  time.Time `json:"startedAt"`
	FinishedAt time.Time `json:"finishedAt"`
}

Entry is a row of the auto-update log. Keep in sync with api/openapi.yaml.

type JobRunner added in v0.2.0

type JobRunner interface {
	Start(spec jobs.Spec, fn jobs.Func) (jobs.Job, error)
}

JobRunner starts jobs; *jobs.Manager implements it.

type Overview

type Overview struct {
	LastCheck *time.Time `json:"lastCheck,omitempty"`
	NextCheck *time.Time `json:"nextCheck,omitempty"`
	Running   bool       `json:"running"`
	Images    []Status   `json:"images"`
}

Overview is the state of an environment's update checks for one namespace.

type Pending added in v0.2.0

type Pending struct {
	Since   time.Time `json:"since"`
	Targets []Target  `json:"targets"`
}

Pending are updates waiting for approval because there were more than MaxBatch.

type Report

type Report struct {
	Checked int `json:"checked"`
	Updates int `json:"updates"`
	Failed  int `json:"failed"`
}

Report summarizes a check.

type StackDefinitions added in v0.2.0

type StackDefinitions interface {
	Definitions(ctx context.Context) ([]stacks.Definition, error)
}

StackDefinitions finds the compose files of stacks; *stacks.Service implements it.

type Status

type Status struct {
	Ref          string    `json:"ref"`
	LocalDigest  string    `json:"localDigest"`
	RemoteDigest string    `json:"remoteDigest,omitempty"`
	CheckedAt    time.Time `json:"checkedAt"`
	Error        string    `json:"error,omitempty"`
	// UpdateAvailable: the registry's digest differs from the local one.
	UpdateAvailable bool `json:"updateAvailable"`
	// Containers counts the namespace's containers created from the reference.
	Containers int `json:"containers"`
}

Status is the update state of one image reference in a namespace.

type Store

type Store interface {
	ListImageUpdates(ctx context.Context, environment string) ([]db.ImageUpdate, error)
	SetImageUpdate(ctx context.Context, arg db.SetImageUpdateParams) error
	LastImageUpdateCheck(ctx context.Context, environment string) (int64, error)
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, arg db.SetSettingParams) error
}

Store is the database used by the checker; *db.Queries of the write connection implements it.

type Target added in v0.2.0

type Target struct {
	Kind      string `json:"kind"`
	Namespace string `json:"namespace"`
	// Name is the container name or the stack (compose project) name.
	Name string `json:"name"`
	// ContainerID is set for containers.
	ContainerID string `json:"-"`
	// Services are the stack's services to update.
	Services []string `json:"services,omitempty"`
	// Refs and Digests are the image references and the registry digests they update to.
	Refs    []string `json:"refs"`
	Digests []string `json:"-"`
}

Target is one update: a standalone container, or the opted-in services of a stack.

type Updater added in v0.2.0

type Updater struct {
	Store  AutoStore
	Jobs   JobRunner
	Stacks StackDefinitions // nil: stack services are skipped
	Now    func() time.Time
	// Notify, when set, receives events about updates done, failed and waiting (#86).
	Notify func(notify.Event)
	// Base is the context of approved updates, canceled on shutdown; nil: never canceled.
	Base context.Context //nolint:containedctx // background work outlives the approving request
	// contains filtered or unexported fields
}

Updater pulls and recreates opted-in containers and stack services whose images have updates, after each scheduled check. Every update runs as a job and is written to the log.

func (*Updater) Approve added in v0.2.0

func (u *Updater) Approve(ctx context.Context, env *environment.Environment) (int, error)

Approve applies the updates waiting for approval, re-planned now so that updates done or withdrawn meanwhile are left out; it returns once they have started.

func (*Updater) Log added in v0.2.0

func (u *Updater) Log(ctx context.Context, env, namespace string, limit int) ([]Entry, error)

Log returns the newest entries of an environment's auto-update log, of one namespace or all.

func (*Updater) PendingFor added in v0.2.0

func (u *Updater) PendingFor(env string) (Pending, bool)

PendingFor returns the updates of an environment waiting for approval, if any.

func (*Updater) Plan added in v0.2.0

func (u *Updater) Plan(ctx context.Context, env *environment.Environment, delay time.Duration) ([]Target, error)

Plan lists the updates due in an environment: opted-in containers whose image reference has a newer registry digest than the local image, grouped by stack for compose services.

A registry digest first seen less than delay ago is not due yet (#56).

func (*Updater) Run added in v0.2.0

func (u *Updater) Run(ctx context.Context, env *environment.Environment) error

Run applies the planned updates of an environment one at a time and logs each. When more are due than the environment's MaxBatch, nothing is applied and they wait for Approve (#56).

func (*Updater) SetSettings added in v0.2.0

func (u *Updater) SetSettings(ctx context.Context, env string, s AutoSettings) error

SetSettings stores the environment's automatic update settings.

func (*Updater) Settings added in v0.2.0

func (u *Updater) Settings(ctx context.Context, env string) (AutoSettings, error)

Settings returns the environment's automatic update settings.

Jump to

Keyboard shortcuts

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