stackdrift

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 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 stackdrift periodically plans each stack's latest applied revision against live state and records whether they still match (ADR 042). It only reads: nothing here applies a plan or writes a live resource.

Index

Constants

View Source
const (
	EnvInterval   = "APP_STACK_DRIFT_INTERVAL"
	EnvSummaryMax = "APP_STACK_DRIFT_SUMMARY_MAX"

	DefaultInterval = 15 * time.Minute
)

Env names for the loop. APP_STACK_DRIFT_INTERVAL=0 turns it off.

View Source
const (
	ActionChanged      = "changed"
	ActionMissing      = "missing"
	ActionOwnerChanged = "owner_changed"
)

Item actions in a drift summary.

View Source
const DefaultTick = 30 * time.Second

DefaultTick keeps the loop cheap while off but quick to notice a setting change.

Variables

This section is empty.

Functions

func IntervalFromEnv

func IntervalFromEnv() time.Duration

IntervalFromEnv reads APP_STACK_DRIFT_INTERVAL; 0 disables the loop and an unset or invalid value falls back to the default.

func Summarize

func Summarize(p iac.Plan, limit int) []store.StackDriftItem

Summarize reduces a plan to drift items: field paths only, never the old or new values, so env, labels and commands stay hidden. At most max items.

Types

type Checker

type Checker struct {
	Store Store
	Live  OpenLive
	// ProjectName resolves a stack's project id to the name documents use.
	ProjectName func(ctx context.Context, id string) string
	Logger      *slog.Logger
	Now         func() time.Time
	// StartDelay is the wait before the first pass after boot.
	StartDelay time.Duration
	// Interval and SummaryMax read live settings each cycle; nil falls back to env.
	Interval   func(ctx context.Context) time.Duration
	SummaryMax func(ctx context.Context) int
	// Tick is how often RunLive re-reads the interval; zero means DefaultTick.
	Tick time.Duration
}

Checker records drift for every stack.

func (*Checker) CheckAll

func (c *Checker) CheckAll(ctx context.Context)

CheckAll runs one pass. A failure on one stack is logged and never stops the others or the loop.

func (*Checker) Run

func (c *Checker) Run(ctx context.Context, interval time.Duration)

Run checks every interval until ctx ends. Interval <= 0 returns at once.

func (*Checker) RunLive

func (c *Checker) RunLive(ctx context.Context)

RunLive checks on the live interval until ctx ends. It wakes on a fixed tick and re-reads the interval, so turning the setting on or off needs no restart.

type OpenLive

type OpenLive func(ctx context.Context) (iac.Doer, func(), error)

OpenLive returns a read-only client for live state and a release func the checker calls when the pass is done.

type Store

type Store interface {
	ListStacks(ctx context.Context) ([]store.StackRecord, error)
	ListStackRevisions(ctx context.Context, stackID string, limit int) ([]store.StackRevisionRecord, error)
	GetStackRevision(ctx context.Context, stackID string, number int) (store.StackRevisionRecord, error)
	ListStackLedger(ctx context.Context, stackID string) ([]store.StackLedgerEntry, error)
	GetStackResourceOwner(ctx context.Context, kind, key string) (store.StackLedgerEntry, bool, error)
	SetStackDrift(ctx context.Context, d store.StackDrift) error
}

Store is the store surface the checker uses.

Jump to

Keyboard shortcuts

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