crossplanedrift

package
v0.7.25 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package crossplanedrift computes a leaf-field comparison between a Crossplane managed resource's desired configuration (spec.forProvider) and the provider-observed external state (status.atProvider).

status.atProvider is commonly a superset of spec.forProvider: it carries provider-observed values including API-defaulted fields, and Crossplane may late-initialize desired fields back into spec.forProvider. Observe-only imports also populate status.atProvider before a resource is fully managed. Because of this, the comparison is deliberately one-directional and conservative: it only walks the leaf paths configured in spec.forProvider and looks up the matching path in status.atProvider, rather than performing a symmetric recursive equality check that would flag every provider-defaulted field as spurious drift.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Label

func Label(syncedStatus string, managementPolicies []interface{}) (label string, annotation string)

Label picks the operator-facing wording for a non-empty drift result: an Observe-only managed resource reads as an expected "Observed difference" (Crossplane isn't reconciling it), a Synced=False resource reads as the stronger "Drift" signal (a reconcile failure, not just a provider-side observation lag), and anything else (typically Synced=True) reads as the unsurprising "Observed difference" case where the provider may still reconcile it. annotation is an optional parenthetical with more detail, empty when the plain label needs no elaboration.

Types

type Class

type Class int

Class classifies a single configured leaf path.

const (
	// InSync means the configured and observed values are equal after normalization.
	InSync Class = iota
	// Drift means the configured and observed values differ after normalization.
	Drift
	// NotObserved means the configured path has no corresponding entry in status.atProvider.
	NotObserved
)

type Entry

type Entry struct {
	Path     string
	Desired  interface{}
	Observed interface{}
	Class    Class
	Redacted bool
}

Entry is a single compared leaf path from spec.forProvider.

type Result

type Result struct {
	// Eligible is true when both forProvider and atProvider are non-empty maps, i.e. this
	// object looks like a Crossplane managed resource with at least one observation.
	Eligible bool
	// TotalConfigured is the number of leaf paths found under spec.forProvider.
	TotalConfigured  int
	InSyncCount      int
	NotObservedCount int
	// DriftEntries holds only the entries classified as Drift, sorted by path, redacted, and
	// bounded to maxDriftEntries (with Truncated/MoreCount reporting what was cut).
	DriftEntries []Entry
	Truncated    bool
	MoreCount    int
	// ObservedOnlyCount is the number of leaf paths present under status.atProvider that have
	// no corresponding leaf path under spec.forProvider (provider-defaulted/computed fields).
	ObservedOnlyCount int
}

Result is the outcome of comparing spec.forProvider against status.atProvider.

func Diff

func Diff(forProvider, atProvider map[string]interface{}) Result

Diff compares spec.forProvider against status.atProvider and returns the classified leaf paths. forProvider/atProvider are expected to be the raw unstructured map values (as decoded by k8s.io/apimachinery/pkg/apis/meta/v1/unstructured), or nil if absent.

func (Result) RedactedPaths

func (r Result) RedactedPaths() []string

RedactedPaths returns the sorted paths of DriftEntries whose values were redacted, i.e. the drifted fields UnifiedDiff leaves out of its rendered diff.

func (Result) UnifiedDiff

func (r Result) UnifiedDiff() string

UnifiedDiff renders a unified, git-style diff between the desired and observed values of DriftEntries, as two minimal YAML documents built from just the drifted leaf paths (shared parent keys act as diff context). Returns "" when there's no drift, or when every drifted path is redacted (see below). It deliberately excludes in-sync/not-observed/observed-only paths that would otherwise show up as diff noise.

Redacted entries are left out of the diffed documents entirely: Diff sets both their Desired and Observed to the same "REDACTED" placeholder, which would render as a no-op diff line (identical text on both sides) rather than a leak, but that silently hides the fact that the field drifted. Callers should list r.RedactedPaths separately when non-empty.

Jump to

Keyboard shortcuts

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