diff

package
v0.13.0-rc1 Latest Latest
Warning

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

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

Documentation

Overview

Package diff compares AICR snapshots to detect configuration drift. It performs field-level comparison between two snapshots, reporting added, removed, and modified readings across all measurement types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteTable

func WriteTable(w io.Writer, result *Result) error

WriteTable writes the diff result as a human-readable table. Returns a structured error wrapping the first write failure encountered (useful for broken-pipe or full-disk scenarios on the target writer).

A nil result is treated as a malformed call rather than a successful empty diff: it returns ErrCodeInvalidRequest so callers don't silently ship a "NO CHANGES" report for what was actually a programming error.

Types

type Change

type Change struct {
	// Kind is the type of change (added, removed, modified).
	Kind ChangeKind `json:"kind" yaml:"kind"`
	// Severity classifies the impact.
	Severity Severity `json:"severity" yaml:"severity"`
	// Path is the dot-separated location (e.g., "K8s.server.version").
	Path string `json:"path" yaml:"path"`
	// Baseline is the value in the baseline snapshot. Nil for Added changes.
	Baseline *string `json:"baseline,omitempty" yaml:"baseline,omitempty"`
	// Target is the value in the target snapshot. Nil for Removed changes.
	Target *string `json:"target,omitempty" yaml:"target,omitempty"`
}

Change represents a single field-level difference between two snapshots.

Baseline and Target are pointers so the JSON/YAML schema can distinguish a genuinely-absent side (nil → field omitted via omitempty) from a present reading whose value happens to be the empty string (`&""` → field present as `""`). Conflating these on the wire would make Modified-to-empty indistinguishable from Removed for downstream consumers.

type ChangeKind

type ChangeKind string

ChangeKind describes the type of difference detected.

const (
	// Added indicates a value exists in the target but not the baseline.
	Added ChangeKind = "added"
	// Removed indicates a value exists in the baseline but not the target.
	Removed ChangeKind = "removed"
	// Modified indicates a value changed between baseline and target.
	Modified ChangeKind = "modified"
)

type Result

type Result struct {
	// BaselineSource identifies the baseline (file path, ConfigMap URI, etc.).
	BaselineSource string `json:"baselineSource,omitempty" yaml:"baselineSource,omitempty"`
	// TargetSource identifies the target snapshot.
	TargetSource string `json:"targetSource,omitempty" yaml:"targetSource,omitempty"`
	// Changes is the list of field-level differences.
	Changes []Change `json:"changes" yaml:"changes"`
	// Summary contains aggregate counts.
	Summary Summary `json:"summary" yaml:"summary"`
}

Result contains the complete diff output.

func Snapshots

func Snapshots(baseline, target *snapshotter.Snapshot) *Result

Snapshots compares two snapshots and returns a structured diff result. The baseline is the reference state; the target is the current state. If either baseline or target is nil, returns an empty Result (no drift).

func (*Result) HasDrift

func (r *Result) HasDrift() bool

HasDrift returns true if any field-level changes were detected. Derives the answer from len(Changes) directly so a caller-constructed Result (where Summary may not have been populated) reports correctly, and a nil receiver safely returns false instead of panicking.

type Severity

type Severity string

Severity classifies the impact of a detected change.

const (
	// SeverityInfo indicates an informational change.
	SeverityInfo Severity = "info"
)

type Summary

type Summary struct {
	Added    int `json:"added" yaml:"added"`
	Removed  int `json:"removed" yaml:"removed"`
	Modified int `json:"modified" yaml:"modified"`
	Total    int `json:"total" yaml:"total"`
}

Summary provides aggregate counts.

Jump to

Keyboard shortcuts

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