syncwindow

package
v0.126.0 Latest Latest
Warning

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

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

Documentation

Overview

Package syncwindow implements sync windows: operator-defined, timezone-aware allow and deny windows that decide whether a deployment may change a stack at a given time.

A window is active from each occurrence of its cron schedule for its duration. Only windows whose selectors match a deployment target are considered:

  • an active matching deny window blocks the deployment,
  • matching allow windows that are all inactive block the deployment,
  • otherwise the deployment is allowed.

Deny windows win over allow windows. Manual (API/MCP) deployments bypass a block only if every blocking window has manual_sync enabled, and reconciliation of an already deployed revision is never blocked.

Index

Constants

View Source
const MinDuration = time.Minute

MinDuration is the shortest allowed window duration.

Variables

View Source
var (
	// ErrInvalidConfig is returned for any invalid window definition.
	ErrInvalidConfig = errors.New("invalid sync window configuration")
	// ErrBothConfigSet is returned when both SYNC_WINDOWS and SYNC_WINDOWS_FILE are set.
	ErrBothConfigSet = errors.New("both SYNC_WINDOWS and SYNC_WINDOWS_FILE are set, please use one or the other")
)

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Allowed bool `json:"allowed"`
	// ManualOverride is true when a manual deployment is allowed only
	// because every blocking window has manual_sync enabled.
	ManualOverride bool `json:"manual_override"`
	// Windows lists the names of the windows that block (or, with
	// ManualOverride, would block) the deployment.
	Windows []string `json:"windows"`
	// NextOpen is the earliest time the target may deploy again. It is zero
	// when unknown or when the deployment is allowed.
	NextOpen time.Time `json:"next_open,omitzero"`
}

Decision is the result of evaluating a target against the policy.

func (Decision) Message

func (d Decision) Message() string

Message returns a short human-readable description of a blocking decision.

type Kind

type Kind string

Kind is the type of window.

const (
	// KindAllow permits deployments while active and blocks them otherwise.
	KindAllow Kind = "allow"
	// KindDeny blocks deployments while active.
	KindDeny Kind = "deny"
)

type Origin

type Origin string

Origin identifies what started a deployment, which decides how windows apply to it.

const (
	// OriginAutomatic covers webhooks, polls and the local repository watcher.
	OriginAutomatic Origin = "automatic"
	// OriginManual covers deployments requested through the REST API or MCP.
	OriginManual Origin = "manual"
	// OriginReconciliation covers restoring the already deployed revision
	// after drift, for example when a container died. It is never blocked;
	// a reconciliation that would deploy another revision must be evaluated
	// as OriginAutomatic instead.
	OriginReconciliation Origin = "reconciliation"
)

type Policy

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

Policy is a validated, immutable set of windows. A nil Policy allows everything.

func New

func New(windows []Window) (*Policy, error)

New validates windows and returns a policy for them.

func Parse

func Parse(data string) (*Policy, error)

Parse parses and validates a YAML (or JSON) list of windows. Empty input returns an empty policy.

func (*Policy) Empty

func (p *Policy) Empty() bool

Empty reports whether the policy has no windows.

func (*Policy) Evaluate

func (p *Policy) Evaluate(now time.Time, target Target, origin Origin) Decision

Evaluate decides whether a deployment of target started by origin may change the target at now.

func (*Policy) Report

func (p *Policy) Report(now time.Time, target *Target, origin Origin) Report

Report returns the state of every window at now and, if target is not nil, the decision for deploying target with origin at now.

func (*Policy) Statuses

func (p *Policy) Statuses(now time.Time) []Status

Statuses returns the state of every window at now.

func (*Policy) Windows

func (p *Policy) Windows() []Window

Windows returns copies of the policy's windows in definition order.

type Report

type Report struct {
	Time    time.Time `json:"time"`
	Windows []Status  `json:"windows"`
	// Decision is the decision for the requested target, if any.
	Decision *Decision `json:"decision,omitempty"`
}

Report is the state of a policy at a point in time.

type Status

type Status struct {
	Name         string     `json:"name"`
	Kind         Kind       `json:"kind"`
	Schedule     string     `json:"schedule"`
	Duration     string     `json:"duration"`
	Timezone     string     `json:"timezone"`
	Repositories []string   `json:"repositories"`
	Deployments  []string   `json:"deployments"`
	Contexts     []string   `json:"contexts"`
	ManualSync   bool       `json:"manual_sync"`
	Active       bool       `json:"active"`
	ActiveSince  *time.Time `json:"active_since,omitempty"`
	ActiveUntil  *time.Time `json:"active_until,omitempty"`
	NextStart    *time.Time `json:"next_start,omitempty"`
}

Status describes a window at a point in time.

type Target

type Target struct {
	Repository string // Repository is the repository/artifact name the stack is deployed from, e.g. "github.com/acme/app".
	// ConfigRepository is the repository containing the deploy config, if it
	// differs from Repository (deploy configs with repository_url). Repository
	// selectors match if either name matches.
	ConfigRepository string
	Deployment       string // Deployment is the deployment (stack/project) name.
	Context          string // Context is the Docker context name. Empty means "default".
}

Target identifies the stack a deployment would change.

type Window

type Window struct {
	Name         string        // Name identifies the window in logs, metrics and the API. Defaults to "<kind>-<index>".
	Kind         Kind          // Kind is either allow or deny.
	Schedule     string        // Schedule is the 5-field cron expression or descriptor at which the window opens.
	Duration     time.Duration // Duration is how long the window stays active after each occurrence.
	Timezone     string        // Timezone is the IANA timezone the schedule is evaluated in. Empty means the doco-cd timezone (TZ).
	Repositories []string      // Repositories are glob patterns matched against the repository/artifact name. Empty matches all.
	Deployments  []string      // Deployments are glob patterns matched against the deployment (stack/project) name. Empty matches all.
	Contexts     []string      // Contexts are glob patterns matched against the Docker context name ("default" for the default context). Empty matches all.
	ManualSync   bool          // ManualSync lets manual (API/MCP) deployments bypass this window.
	// contains filtered or unexported fields
}

Window is a single sync window definition.

func (*Window) Active

func (w *Window) Active(now time.Time) bool

Active reports whether the window is active at now.

func (*Window) Location

func (w *Window) Location() *time.Location

Location returns the timezone the window's schedule is evaluated in.

Jump to

Keyboard shortcuts

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