diff

package
v2.7.8 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateDiff

func StateDiff(live, config *unstructured.Unstructured, diffConfig DiffConfig) (diff.DiffResult, error)

StateDiff will apply all required normalizations and calculate the diffs between the live and the config/desired states.

func StateDiffs

func StateDiffs(lives, configs []*unstructured.Unstructured, diffConfig DiffConfig) (*diff.DiffResultList, error)

StateDiffs will apply all required normalizations and calculate the diffs between the live and the config/desired states.

Types

type DiffConfig

type DiffConfig interface {
	// Validate will check if the current configurations are set properly.
	Validate() error
	// DiffFromCache will verify if it should retrieve the cached ResourceDiff based on this
	// DiffConfig.
	DiffFromCache(appName string) (bool, []*v1alpha1.ResourceDiff)
	// Ignores Application level ignore difference configurations.
	Ignores() []v1alpha1.ResourceIgnoreDifferences
	// Overrides is map of system configurations to override the Application ones.
	// The key should follow the "group/kind" format.
	Overrides() map[string]v1alpha1.ResourceOverride
	AppLabelKey() string
	TrackingMethod() string
	// AppName the Application name. Used to retrieve the cached diff.
	AppName() string
	// NoCache defines if should retrieve the diff from cache.
	NoCache() bool
	// StateCache is used when retrieving the diff from the cache.
	StateCache() *appstatecache.Cache
	IgnoreAggregatedRoles() bool
	// Logger used during the diff.
	Logger() *logr.Logger
	// GVKParser returns a parser able to build a TypedValue used in
	// structured merge diffs.
	GVKParser() *k8smanagedfields.GvkParser
	// StructuredMergeDiff defines if the diff should be calculated using
	// structured merge diffs. Will use standard 3-way merge diffs if
	// returns false.
	StructuredMergeDiff() bool
	// Manager returns the manager that should be used by the diff while
	// calculating the structured merge diff.
	Manager() string
}

DiffConfig defines methods to retrieve the configurations used while applying diffs and normalizing resources.

type DiffConfigBuilder

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

DiffConfigBuilder is used as a safe way to create valid DiffConfigs.

func NewDiffConfigBuilder

func NewDiffConfigBuilder() *DiffConfigBuilder

NewDiffConfigBuilder create a new DiffConfigBuilder instance.

func (*DiffConfigBuilder) Build

func (b *DiffConfigBuilder) Build() (DiffConfig, error)

Build will first validate the current state of the diff config and return the DiffConfig implementation if no errors are found. Will return nil and the error details otherwise.

func (*DiffConfigBuilder) WithCache

func (b *DiffConfigBuilder) WithCache(s *appstatecache.Cache, appName string) *DiffConfigBuilder

WithCache sets the appstatecache.Cache and the appName in the diff config. Those the are two objects necessary to retrieve a cached diff.

func (*DiffConfigBuilder) WithDiffSettings

func (b *DiffConfigBuilder) WithDiffSettings(id []v1alpha1.ResourceIgnoreDifferences, o map[string]v1alpha1.ResourceOverride, ignoreAggregatedRoles bool) *DiffConfigBuilder

WithDiffSettings will set the diff settings in the builder.

func (*DiffConfigBuilder) WithGVKParser added in v2.4.0

WithGVKParser sets the gvkParser in the diff config.

func (*DiffConfigBuilder) WithLogger

func (b *DiffConfigBuilder) WithLogger(l logr.Logger) *DiffConfigBuilder

WithLogger sets the logger in the diff config.

func (*DiffConfigBuilder) WithManager added in v2.5.0

func (b *DiffConfigBuilder) WithManager(manager string) *DiffConfigBuilder

WithManager defines the manager that should be using during structured merge diffs.

func (*DiffConfigBuilder) WithNoCache

func (b *DiffConfigBuilder) WithNoCache() *DiffConfigBuilder

WithNoCache sets the nocache in the diff config.

func (*DiffConfigBuilder) WithStructuredMergeDiff added in v2.5.0

func (b *DiffConfigBuilder) WithStructuredMergeDiff(smd bool) *DiffConfigBuilder

WithStructuredMergeDiff defines if the diff should be calculated using structured merge.

func (*DiffConfigBuilder) WithTracking

func (b *DiffConfigBuilder) WithTracking(appLabelKey, trackingMethod string) *DiffConfigBuilder

WithTrackingMethod sets the tracking in the diff config.

type IgnoreDiffConfig

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

IgnoreDiffConfig holds the ignore difference configurations defined in argo-cm as well as in the Application resource.

func NewIgnoreDiffConfig

func NewIgnoreDiffConfig(ignores []v1alpha1.ResourceIgnoreDifferences, overrides map[string]v1alpha1.ResourceOverride) *IgnoreDiffConfig

NewIgnoreDiffConfig creates a new NewIgnoreDiffConfig.

func (*IgnoreDiffConfig) HasIgnoreDifference

func (i *IgnoreDiffConfig) HasIgnoreDifference(group, kind, name, namespace string) (bool, *IgnoreDifference)

HasIgnoreDifference will verify if the provided resource identifiers have any ignore difference configurations associated with them. It will first check if there are system level ignore difference configurations for the current group/kind. If so, this will be returned taking precedence over Application specific ignore difference configurations.

type IgnoreDifference

type IgnoreDifference struct {
	//JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
	JSONPointers []string
	//JQPathExpressions is a JQ path list that will be evaludated during the diff process
	JQPathExpressions []string
	// ManagedFieldsManagers is a list of trusted managers. Fields mutated by those managers will take precedence over the
	// desired state defined in the SCM and won't be displayed in diffs
	ManagedFieldsManagers []string
}

IgnoreDifference holds the configurations to be used while ignoring differences from live and desired states.

type NormalizationResult

type NormalizationResult struct {
	Lives   []*unstructured.Unstructured
	Targets []*unstructured.Unstructured
}

NormalizationResult holds the normalized lives and target resources.

func Normalize

func Normalize(lives, configs []*unstructured.Unstructured, diffConfig DiffConfig) (*NormalizationResult, error)

Normalize applies the full normalization on the lives and configs resources based on the provided DiffConfig.

Jump to

Keyboard shortcuts

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