Help us shape the future of Go! Take the 2026 Go Developer Survey

gitops

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 15 Imported by: 0

Documentation

Overview

Package gitops provides Flux CD graph discovery, change impact analysis, and reconciliation coordination.

Core rule: if Flux already knows it, StageFreight discovers it — never asks for it. No duplicated topology config. No declared kustomization lists. Flux is truth. StageFreight is the intelligence + evidence layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKubeconfig

func BuildKubeconfig(cfg config.ClusterConfig, rctx *runtime.RuntimeContext) error

BuildKubeconfig creates an isolated kubeconfig for the target cluster. CA is resolved from environment: <PREFIX>_CA_FILE or <PREFIX>_CA_B64. OIDC token is resolved from STAGEFREIGHT_OIDC. All ephemeral files are registered for cleanup on rctx.Resolved.

func DuplicatePaths

func DuplicatePaths(graph *FluxGraph) map[string][]KustomizationKey

DuplicatePaths returns paths owned by multiple kustomizations.

func GetChangedFiles

func GetChangedFiles(repoDir, base, head string) ([]string, error)

GetChangedFiles returns files changed between two refs.

func NormalizePath

func NormalizePath(p string) string

NormalizePath cleans a path for consistent matching.

func SortKeys

func SortKeys(keys []KustomizationKey)

SortKeys sorts kustomization keys lexically by namespace/name.

Types

type BootstrapState

type BootstrapState struct {
	Required bool
	Reason   string
}

BootstrapState indicates whether Flux bootstrapping is needed.

func DetectBootstrapRequired

func DetectBootstrapRequired(graph *FluxGraph) BootstrapState

DetectBootstrapRequired checks if Flux bootstrapping is needed. Stub for now — returns false. Hook wired for future extension.

type FluxBackend

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

FluxBackend implements runtime.LifecycleBackend for Flux CD reconciliation.

func (*FluxBackend) Capabilities

func (f *FluxBackend) Capabilities() []runtime.Capability

func (*FluxBackend) Cleanup

func (f *FluxBackend) Cleanup(rctx *runtime.RuntimeContext)

Cleanup is handled by rctx.Resolved cleanup funcs registered in Prepare.

func (*FluxBackend) Execute

Execute runs flux reconcile on the planned set. Idempotent: repeated execution converges to the same state.

func (*FluxBackend) Name

func (f *FluxBackend) Name() string

func (*FluxBackend) Plan

Plan discovers the Flux graph, computes impact, and builds the reconcile set. Deterministic: identical config + inputs → identical output.

func (*FluxBackend) Prepare

func (f *FluxBackend) Prepare(ctx context.Context, cfg *config.Config, rctx *runtime.RuntimeContext) error

Prepare builds an isolated kubeconfig for the target cluster. Skipped if no cluster config is present (local dev).

func (*FluxBackend) Validate

func (f *FluxBackend) Validate(ctx context.Context, cfg *config.Config, rctx *runtime.RuntimeContext) error

Validate checks that the flux CLI is available and cluster config is complete.

type FluxGraph

type FluxGraph struct {
	Kustomizations map[KustomizationKey]KustomizationNode
	ReverseDeps    map[KustomizationKey][]KustomizationKey
}

FluxGraph is the discovered dependency graph of Flux Kustomizations.

func DiscoverFluxGraph

func DiscoverFluxGraph(root string) (*FluxGraph, error)

DiscoverFluxGraph walks the repo and discovers all Flux Kustomization objects. Builds forward and reverse dependency graphs. No config needed — everything is derived from the actual manifests.

type FluxReconcileResult

type FluxReconcileResult struct {
	Kustomization string
	Namespace     string
	Attempted     bool
	Success       bool
	Duration      time.Duration
	Ready         bool
	Message       string
}

FluxReconcileResult reports the outcome of reconciling one kustomization. Kept for backward compatibility with existing CLI output rendering.

func Reconcile

func Reconcile(keys []KustomizationKey, dryRun bool) []FluxReconcileResult

Reconcile executes flux reconcile on the given kustomizations in order. Legacy function — new code should use FluxBackend via the runtime.

type ImpactResult

type ImpactResult struct {
	ChangedFiles         []string
	DirectlyAffected     []KustomizationKey
	TransitivelyAffected []KustomizationKey
	ReconcileSet         []KustomizationKey // topologically sorted
	UnmappedFiles        []string           // changed files not under any kustomization path
}

ImpactResult describes which kustomizations are affected by a set of changes.

func ComputeImpact

func ComputeImpact(graph *FluxGraph, files []string) ImpactResult

ComputeImpact determines which kustomizations are affected by changed files. Walks the reverse dependency graph to find transitive dependents.

type KustomizationKey

type KustomizationKey struct {
	Namespace string
	Name      string
}

KustomizationKey uniquely identifies a Flux Kustomization. Identity is (namespace, name) — never bare name alone.

func Orphans

func Orphans(graph *FluxGraph) []KustomizationKey

Orphans returns kustomizations with no dependents and no dependencies.

func TopoSort

func TopoSort(graph *FluxGraph, subset []KustomizationKey) []KustomizationKey

TopoSort produces a deterministic topological order for a subset of the graph. Dependencies come before dependents. Ties broken by namespace/name sort.

func (KustomizationKey) String

func (k KustomizationKey) String() string

type KustomizationNode

type KustomizationNode struct {
	Key       KustomizationKey
	Path      string // normalized, repo-root relative
	DependsOn []KustomizationKey
	SourceRef string
}

KustomizationNode is a discovered Flux Kustomization with its dependencies.

Jump to

Keyboard shortcuts

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