maintenance

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInput = errors.New("invalid maintenance input")
)

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	State     State
	Active    bool
	Expired   bool
	CheckedAt time.Time
}

type DisableInput

type DisableInput struct {
	Actor string
}

func NormalizeDisableInput

func NormalizeDisableInput(input DisableInput) (DisableInput, error)

NormalizeDisableInput validates optional disable metadata even though the current state model clears the active window. This gives CLI and PostgreSQL stores one shared validation rule for future audit/history fields.

type EnableInput

type EnableInput struct {
	Mode      string
	Reason    string
	Actor     string
	CreatedAt time.Time
	ExpiresAt *time.Time
}

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore(opts ...MemoryStoreOption) *MemoryStore

NewMemoryStore returns a process-local maintenance store for standalone deployments and tests. PostgreSQL-backed deployments will replace this store in a later task so every OpenCook process observes the same write gate.

func (*MemoryStore) Check

func (s *MemoryStore) Check(ctx context.Context) (CheckResult, error)

Check evaluates whether the current maintenance state should block writes at the current clock instant. Expired windows are reported as inactive while the stored state remains readable for truthful operator diagnostics.

func (*MemoryStore) Disable

func (s *MemoryStore) Disable(ctx context.Context, input DisableInput) (State, error)

Disable clears the active maintenance state. The operation is intentionally idempotent because operators should be able to safely retry cleanup steps.

func (*MemoryStore) Enable

func (s *MemoryStore) Enable(ctx context.Context, input EnableInput) (State, error)

Enable validates and stores a normalized active maintenance state. The update is all-or-nothing so invalid enable attempts cannot erase an existing window.

func (*MemoryStore) Read

func (s *MemoryStore) Read(ctx context.Context) (State, error)

Read returns the current raw maintenance state without applying expiration. Keeping expired state visible lets status and admin output explain why writes are no longer blocked instead of silently losing operator context.

type MemoryStoreOption

type MemoryStoreOption func(*MemoryStore)

func WithClock

func WithClock(now func() time.Time) MemoryStoreOption

WithClock injects a deterministic clock for expiration tests and future admin-command tests that need stable maintenance timestamps.

type SafeState

type SafeState struct {
	Enabled         bool       `json:"enabled"`
	Mode            string     `json:"mode,omitempty"`
	Reason          string     `json:"reason,omitempty"`
	ReasonTruncated bool       `json:"reason_truncated,omitempty"`
	Actor           string     `json:"actor,omitempty"`
	ActorTruncated  bool       `json:"actor_truncated,omitempty"`
	CreatedAt       time.Time  `json:"created_at,omitempty"`
	ExpiresAt       *time.Time `json:"expires_at,omitempty"`
}

type State

type State struct {
	Enabled   bool       `json:"enabled"`
	Mode      string     `json:"mode,omitempty"`
	Reason    string     `json:"reason,omitempty"`
	Actor     string     `json:"actor,omitempty"`
	CreatedAt time.Time  `json:"created_at,omitempty"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

func CloneState

func CloneState(state State) State

CloneState returns a deep copy of maintenance state. PostgreSQL repositories use it to protect cached inactive-state values the same way MemoryStore protects values returned to callers.

func NormalizeEnableInput

func NormalizeEnableInput(input EnableInput, fallbackNow time.Time) (State, error)

NormalizeEnableInput canonicalizes operator-provided maintenance state before it is stored. The store keeps the full reason for auditability, while SafeStatus returns a bounded display copy for status surfaces.

func (State) ActiveAt

func (s State) ActiveAt(now time.Time) bool

ActiveAt reports whether the state should block mutating Chef-facing writes at the supplied time. It treats expiration as authoritative but does not mutate or clear the stored state.

func (State) ExpiredAt

func (s State) ExpiredAt(now time.Time) bool

ExpiredAt reports whether an enabled maintenance window has reached its expiration time. Disabled states are never considered expired.

func (State) SafeStatus

func (s State) SafeStatus() SafeState

SafeStatus returns a display-safe copy of maintenance state for status and admin output. It removes control-style whitespace and bounds operator text so future Chef-facing responses do not leak long notes or provider details.

type Store

type Store interface {
	Read(context.Context) (State, error)
	Enable(context.Context, EnableInput) (State, error)
	Disable(context.Context, DisableInput) (State, error)
	Check(context.Context) (CheckResult, error)
}

Jump to

Keyboard shortcuts

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