diff

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package diff provides functionality for comparing Kubernetes objects and generating diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertResourceChange

func AssertResourceChange(t *testing.T, results Results, expectedKey string, expectedChangeType ChangeType)

AssertResourceChange checks if a specific resource has the expected change type

Types

type ChangeType

type ChangeType int

ChangeType represents the type of change for a resource

const (
	// Unchanged indicates that a resource exists in both base and head with no changes
	Unchanged ChangeType = iota
	// Changed indicates that a resource exists in both base and head with changes
	Changed
	// Created indicates that a resource exists only in head (newly created)
	Created
	// Deleted indicates that a resource exists only in base (deleted)
	Deleted
)

func (ChangeType) String

func (ct ChangeType) String() string

String returns the string representation of ChangeType

type Options

type Options struct {
	FilterOption          *filter.Option // Filtering options
	Context               int            // Number of context lines in diff output
	DisableMaskingSecrets bool           // Disable masking of secret values (default: false)
}

Options controls the diff behavior with filtering and masking options

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default diff options

type ResourceKey

type ResourceKey struct {
	Name      string
	Namespace string
	Group     string
	Kind      string
}

ResourceKey uniquely identifies a Kubernetes resource

func GetChangedResourceKeys

func GetChangedResourceKeys(results Results) []ResourceKey

GetChangedResourceKeys extracts resources that have any type of change (Created, Changed, Deleted) DEPRECATED: Use Results.Apply() with custom filter or multiple GetResourceKeysByType() calls

func ParseResourceKey

func ParseResourceKey(key string) ResourceKey

ParseResourceKey parses a string resource key into ResourceKey

func (ResourceKey) String

func (k ResourceKey) String() string

String returns a string representation of the ResourceKey

type Result

type Result struct {
	Type ChangeType // Type of change (Created, Changed, Deleted, Unchanged)
	Diff string     // Diff string representation
}

Result represents the result of a diff operation for a resource

func (Result) String

func (dr Result) String() string

String returns the string representation of Result

type Results

type Results map[ResourceKey]Result

Results represents a collection of diff results for multiple resources

func Objects

func Objects(base, head []*unstructured.Unstructured, opts *Options) (Results, error)

Objects compares two sets of Kubernetes objects and returns the diff

func Yaml

func Yaml(baseReader, headReader io.Reader, opts *Options) (Results, error)

Yaml compares YAML from two io.Reader sources and returns the diff

func YamlString

func YamlString(baseYaml, headYaml string, opts *Options) (Results, error)

YamlString compares two YAML strings and returns the diff

func (Results) Apply

func (dr Results) Apply(filter func(ResourceKey, Result) bool) Results

Apply returns a new Results containing only resources that match the filter function

func (Results) Count

func (dr Results) Count() int

Count returns the total number of resources in the Results

func (Results) CountByType

func (dr Results) CountByType(changeType ChangeType) int

CountByType returns the number of resources with the specified change type

func (Results) FilterByKind

func (dr Results) FilterByKind(kind string) Results

FilterByKind returns a new Results containing only resources with the specified kind

func (Results) FilterByNamespace

func (dr Results) FilterByNamespace(namespace string) Results

FilterByNamespace returns a new Results containing only resources with the specified namespace

func (Results) FilterByResourceName

func (dr Results) FilterByResourceName(name string) Results

FilterByResourceName returns a new Results containing only resources with the specified name

func (Results) FilterByType

func (dr Results) FilterByType(changeType ChangeType) Results

FilterByType returns a new Results containing only resources with the specified change type

func (Results) FilterChanged

func (dr Results) FilterChanged() Results

FilterChanged returns a new Results containing only changed resources

func (Results) FilterCreated

func (dr Results) FilterCreated() Results

FilterCreated returns a new Results containing only created resources

func (Results) FilterDeleted

func (dr Results) FilterDeleted() Results

FilterDeleted returns a new Results containing only deleted resources

func (Results) FilterUnchanged

func (dr Results) FilterUnchanged() Results

FilterUnchanged returns a new Results containing only unchanged resources

func (Results) GetResourceKeys

func (dr Results) GetResourceKeys() []ResourceKey

GetResourceKeys returns a slice of all resource keys in the Results

func (Results) GetResourceKeysByType

func (dr Results) GetResourceKeysByType(changeType ChangeType) []ResourceKey

GetResourceKeysByType returns a slice of resource keys with the specified change type

func (Results) GetStatistics

func (dr Results) GetStatistics() Statistics

GetStatistics returns statistics about the diff results

func (Results) HasChanges

func (dr Results) HasChanges() bool

HasChanges returns true if there are any changes (Created, Changed, or Deleted resources)

func (Results) IsEmpty

func (dr Results) IsEmpty() bool

IsEmpty returns true if the Results contains no resources

func (Results) StringDiff

func (dr Results) StringDiff() string

StringDiff returns a concatenated string of all diff results with summary header

func (Results) StringDiffMarkdown added in v0.0.5

func (dr Results) StringDiffMarkdown() string

StringDiffMarkdown returns a concatenated string of all diff results with markdown formatting

func (Results) StringSummary

func (dr Results) StringSummary() string

StringSummary returns a summary string organized by change types: Unchanged, Changed, Create, Delete

func (Results) StringSummaryAsComments

func (dr Results) StringSummaryAsComments() string

StringSummaryAsComments returns the summary content formatted as comment lines

func (Results) StringSummaryMarkdown added in v0.0.5

func (dr Results) StringSummaryMarkdown() string

StringSummaryMarkdown returns a summary string in Markdown format

type Statistics

type Statistics struct {
	Total     int
	Changed   int
	Created   int
	Deleted   int
	Unchanged int
}

Statistics represents statistics about diff results

Jump to

Keyboard shortcuts

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