Documentation
¶
Overview ¶
Package flux implements providers.GitOpsProvider for Flux: it reads Flux Kustomizations and their GitRepository sources from the cluster and emits engine-agnostic Changes, each diffable through whatchanged.Differ.
Index ¶
- type HelmReleaseEvent
- type KustomizationEvent
- type Provider
- func (p *Provider) Changes(ctx context.Context, w providers.TimeWindow, sel providers.Selector) ([]providers.Change, error)
- func (p *Provider) DependencyTree(ctx context.Context, w providers.Workload) (providers.DepNode, error)
- func (p *Provider) Diff(ctx context.Context, c providers.Change) (providers.Diff, error)
- func (p *Provider) ResourceStatus(ctx context.Context, w providers.Workload) (providers.ResourceStatus, error)
- func (p *Provider) WatchFailures(ctx context.Context) (<-chan providers.FailureEvent, error)
- type Reader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HelmReleaseEvent ¶ added in v0.9.0
type HelmReleaseEvent struct {
HelmRelease helmRelease
}
HelmReleaseEvent is a single watch event for a HelmRelease.
type KustomizationEvent ¶
type KustomizationEvent struct {
Kustomization kustomization
}
KustomizationEvent is a single watch event for a Kustomization.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements providers.GitOpsProvider for Flux.
func New ¶
func New(reader Reader, differ *whatchanged.Differ) *Provider
New builds a Flux provider from a Reader and a Differ.
func (*Provider) Changes ¶
func (p *Provider) Changes(ctx context.Context, w providers.TimeWindow, sel providers.Selector) ([]providers.Change, error)
Changes lists Flux Kustomizations and emits a Change per workload: its source repo + path and the currently applied revision (ToRev). FromRev is left empty, meaning "the change introduced by ToRev" — resolved at diff time. Each Change's When is set to the commit time of ToRev (falling back to the Ready-condition reconcile time) so the change can be aligned against symptom timestamps (B1).
Namespace resolution (B2): in the default Flux bootstrap every Kustomization lives in flux-system, so a caller asking for a workload's namespace (e.g. "harbor") would match nothing on the Kustomization's OWN metadata.namespace. matchesNamespace therefore accepts EITHER the object's namespace OR its spec.targetNamespace (where the applied workloads land). When the namespace filter still yields zero AND a name is given, we retry name-matched across all namespaces and flag it in the result so "no changes" can never be a silent false negative (mirrors GetResource's flux-system-then-all-namespaces fallback).
TimeWindow (G3): when w is non-zero, each diffable-Git Kustomization emits a Change per source revision that landed IN the window (git-log on the resolved source, newest-first, capped at whatchanged.MaxWindowRevisions), so "what changed over the last N hours" surfaces the whole timeline — not just the current applied revision. A zero/unset window falls back to the single-latest-revision behavior. The enumeration is bounded (cap + committer-time short-circuit) so a wide window can't explode the output.
func (*Provider) DependencyTree ¶
func (p *Provider) DependencyTree(ctx context.Context, w providers.Workload) (providers.DepNode, error)
DependencyTree walks a resource's dependsOn + sourceRef edges, returning the tree with each node's Ready state so the root failure (a not-Ready or missing node) is visible. Best-effort: child read errors don't abort the walk.
func (*Provider) Diff ¶
Diff resolves a Change's diff via the Differ. Changes from a non-Git source (OCIRepository/Bucket/ExternalArtifact) carry no Git URL — there is no Git diff to show, so return an empty diff rather than failing. ctx is threaded into the Differ so a hung clone/patch on a large monorepo is cancellable (per-investigation deadline).
func (*Provider) ResourceStatus ¶
func (p *Provider) ResourceStatus(ctx context.Context, w providers.Workload) (providers.ResourceStatus, error)
ResourceStatus returns a Flux/K8s object's Ready condition, key spec refs (sourceRef, dependsOn, url) and recent Events — the "why is it failing" lens. A missing object is reported via NotFound (often the cascade root), not an error.
func (*Provider) WatchFailures ¶
WatchFailures watches Flux Kustomizations AND HelmReleases and emits a FailureEvent whenever one is Ready=False (a failed/blocked reconcile). Both are watched because a HelmRelease can fail on its own (image pull, failed hook, exhausted install retries) without any Kustomization flipping — that class of failure was previously invisible to the autonomous gitops-watch (runlore#306). The two streams are merged onto one channel, which closes when both watches end or ctx is done.
type Reader ¶
type Reader interface {
ListKustomizations(ctx context.Context) ([]kustomization, error)
GetGitRepository(ctx context.Context, namespace, name string) (gitRepository, error)
// SourceRevision returns a source's current synced revision
// (status.artifact.revision) for a GitRepository/OCIRepository/Bucket/
// ExternalArtifact, used to find a failing Kustomization's HEAD.
SourceRevision(ctx context.Context, kind, namespace, name string) (string, error)
WatchKustomizations(ctx context.Context) (<-chan KustomizationEvent, error)
// WatchHelmReleases watches all Flux HelmReleases (runlore#306): a stuck/failed
// HelmRelease goes Ready=False without any Kustomization flipping, so it is
// invisible to WatchKustomizations.
WatchHelmReleases(ctx context.Context) (<-chan HelmReleaseEvent, error)
// GetResource fetches one object by kind/namespace/name (kinds in kindToGVR).
GetResource(ctx context.Context, kind, namespace, name string) (*unstructured.Unstructured, error)
// ListEvents returns recent Event lines for an involved object.
ListEvents(ctx context.Context, namespace, name, kind string) ([]string, error)
}
Reader is the cluster-read surface the provider depends on. The dynamic client-go implementation lives in dynamic.go; tests use a fake.
func NewDynamicReader ¶
NewDynamicReader builds a Reader backed by a client-go dynamic client.