state

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package state manages deployment state for quad-ops, tracking current and previous commit hashes per repository to enable rollback, and content hashes per unit for change detection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffUnits added in v0.31.1

func DiffUnits(oldUnits, newUnits map[string]struct{}) []string

DiffUnits returns unit names present in oldUnits but not in newUnits.

Types

type RepoState

type RepoState struct {
	Current  string `json:"current"`
	Previous string `json:"previous,omitempty"`
}

RepoState tracks the deployed commit hashes for a single repository.

type State

type State struct {
	Repositories map[string]RepoState `json:"repositories"`
	ManagedUnits map[string][]string  `json:"managed_units,omitempty"`
	UnitStates   map[string]UnitState `json:"unit_states,omitempty"`
	ImageDigests map[string]string    `json:"image_digests,omitempty"`
}

State holds the deployment state for all repositories.

func Load

func Load(path string) (*State, error)

Load reads the state file from disk. Returns an empty state if the file does not exist.

func (*State) ChangedUnits added in v0.30.8

func (s *State) ChangedUnits(newStates map[string]UnitState) []string

ChangedUnits compares new unit states against stored states and returns unit names that previously existed with different content or bind mount hashes. New units (not previously tracked) are excluded — they only need start, not restart.

func (*State) CollectAllManagedUnits added in v0.31.1

func (s *State) CollectAllManagedUnits() map[string]struct{}

CollectAllManagedUnits returns a set of all unit filenames across all repositories.

func (*State) GetImageDigest added in v0.32.0

func (s *State) GetImageDigest(image string) string

GetImageDigest returns the stored remote digest for an image.

func (*State) GetManagedUnits added in v0.30.1

func (s *State) GetManagedUnits(repoName string) []string

GetManagedUnits returns the quadlet unit filenames managed for a repository.

func (*State) GetPrevious

func (s *State) GetPrevious(repoName string) string

GetPrevious returns the previous commit hash for the named repository. Returns empty string if no previous state exists.

func (*State) GetUnitState added in v0.30.8

func (s *State) GetUnitState(unitName string) (UnitState, bool)

GetUnitState returns the stored content hashes for a unit. The second return value is false if no state exists for the unit.

func (*State) PruneRemovedRepos added in v0.31.1

func (s *State) PruneRemovedRepos(configuredRepos map[string]struct{})

PruneRemovedRepos clears managed units for repositories no longer present in the provided set of configured repository names.

func (*State) RemoveUnitState added in v0.30.8

func (s *State) RemoveUnitState(unitName string)

RemoveUnitState removes stored content hashes for a unit.

func (*State) Save

func (s *State) Save(path string) error

Save writes the state to disk, creating parent directories as needed.

func (*State) SetCommit

func (s *State) SetCommit(repoName, commitHash string)

SetCommit records a new deployment for the named repository, shifting the current commit to previous.

func (*State) SetImageDigest added in v0.32.0

func (s *State) SetImageDigest(image, digest string)

SetImageDigest records the remote digest for an image after a successful pull.

func (*State) SetManagedUnits added in v0.30.1

func (s *State) SetManagedUnits(repoName string, units []string)

SetManagedUnits records the quadlet unit filenames managed for a repository.

func (*State) SetUnitState added in v0.30.8

func (s *State) SetUnitState(unitName string, us UnitState)

SetUnitState records content hashes for a unit.

type UnitState added in v0.30.8

type UnitState struct {
	ContentHash     string            `json:"content_hash"`
	BindMountHashes map[string]string `json:"bind_mount_hashes,omitempty"`
}

UnitState tracks content hashes for change detection of a single unit.

Jump to

Keyboard shortcuts

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