compare

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 50 Imported by: 2

Documentation

Overview

Package compare provides compare utilities.

Index

Constants

View Source
const (

	// DiffSeparator separates diff outputs.
	DiffSeparator = "**********************************\n"

	// DiffsFoundMsg is the diffs found message.
	DiffsFoundMsg = "there are differences between the cluster CRs and the reference CRs"
)
View Source
const (
	// JSON is json format.
	JSON string = "json"
	// Yaml is yaml format.
	Yaml string = "yaml"
	// PatchYaml is patch yaml format.
	PatchYaml string = "generate-patches"
	// Junit is junit format.
	Junit string = "junit"
)
View Source
const (
	// MissingCRsMsg is the missing CRs message.
	MissingCRsMsg = "Missing CRs"
	// MatchedMoreThanOne is returned when more than one matches.
	MatchedMoreThanOne = "Should only match one but matched"
)
View Source
const ReferenceVersionV1 string = "v1"

ReferenceVersionV1 is the v1 reference version.

View Source
const ReferenceVersionV2 string = "v2"

ReferenceVersionV2 is the v2 reference version.

View Source
const SprigImportFlag = `<<sprig>>`

SprigImportFlag is used to flag sprig imports.

Variables

AllCRs holds all custom resources. In order to use `lookupCRs` and `lookupCR`, AllCRs must be populated.

View Source
var FieldSeparator = "_"

FieldSeparator is the default field separator.

View Source
var FuncHelp = make(map[string]string)

FuncHelp holds documentation for functions.

View Source
var InlineDiffs = map[InlineDiffType]InlineDiff{
	// contains filtered or unexported fields
}

InlineDiffs maps diff types to implementations.

View Source
var OutputFormats = []string{JSON, Yaml, PatchYaml, Junit}

OutputFormats defines the available output formats.

Functions

func CapturegroupQuoteMeta added in v0.3.0

func CapturegroupQuoteMeta(pattern string, groups []CgInfo) string

CapturegroupQuoteMeta transforms all non-capturegroup text in the pattern via Regex.QuoteMeta(), reusing previously-computed group indices Additionally this will add appropriate word or end-of-string anchors to capturegroups and/or the whole pattern according to the global 'quoteEscapeFull' option

func DisplayFuncmap added in v0.10.0

func DisplayFuncmap(w io.Writer) error

DisplayFuncmap writes the available functions to the writer.

func FromYAML added in v0.0.2

func FromYAML(str string) map[string]any

FromYAML converts a YAML document into a map[string]any.

This is not a general-purpose YAML parser, and will not parse all valid YAML documents. Additionally, because its intended use is within templates it tolerates errors. It will insert the returned error message string into m["Error"] in the returned map.

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns a mapping of all of the functions that Engine has.

Because some functions are late-bound (e.g. contain context-sensitive data), the functions may not all perform identically outside of an Engine as they will inside of an Engine.

Known late-bound functions:

  • "include": executes a named template and returns its output as a string.

These are late-bound after template parsing via InitInclude. The version included in the FuncMap is a placeholder that will return an error if called before binding.

func InitInclude added in v0.13.0

func InitInclude(t *template.Template)

InitInclude binds the late-bound "include" template function to a parsed template. This must be called after template parsing but before execution. It replaces the placeholder include function with a real implementation that can execute named sub-templates.

func MergeManifests added in v0.0.2

func MergeManifests(localRef, clusterCR *unstructured.Unstructured) (updateLocalRef *unstructured.Unstructured, err error)

MergeManifests will return an attempt to update the localRef with the clusterCR. In the case of an error it will return an unmodified localRef.

func NestedField added in v0.4.0

func NestedField(obj any, fields ...string) (any, bool, error)

NestedField returns a reference to a nested field. Returns false if value is not found and an error if unable to traverse obj.

This is a copy of unstructured.NestedFieldNoCopy but can also traverse slices If the value is a slice it will try to convert the field into an int (and use it as the index)

func NestedString added in v0.4.0

func NestedString(obj any, fields ...string) (string, bool, error)

NestedString returns the string value of a nested field.

func NewCmd

NewCmd creates a new compare command.

func RemoveNestedField added in v0.4.0

func RemoveNestedField(obj any, fields ...string) any

RemoveNestedField removes the nested field from the obj.

func SetNestedString added in v0.4.0

func SetNestedString(obj any, value string, fields ...string) error

SetNestedString sets the string value of a nested field.

Types

type AllOf added in v0.1.1

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

AllOf requires all of the components.

func (*AllOf) GetTemplates added in v0.1.1

func (g *AllOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*AllOf) SetTemplates added in v0.1.1

func (g *AllOf) SetTemplates(t []*ReferenceTemplateV2)

func (*AllOf) UnmarshalJSON added in v0.1.1

func (g *AllOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type AllOrNoneOf added in v0.1.1

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

AllOrNoneOf requires all or none of the components.

func (*AllOrNoneOf) GetTemplates added in v0.1.1

func (g *AllOrNoneOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*AllOrNoneOf) SetTemplates added in v0.1.1

func (g *AllOrNoneOf) SetTemplates(t []*ReferenceTemplateV2)

func (*AllOrNoneOf) UnmarshalJSON added in v0.1.1

func (g *AllOrNoneOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type AnyOf added in v0.1.1

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

AnyOf requires any of the components.

func (*AnyOf) GetTemplates added in v0.1.1

func (g *AnyOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*AnyOf) SetTemplates added in v0.1.1

func (g *AnyOf) SetTemplates(t []*ReferenceTemplateV2)

func (*AnyOf) UnmarshalJSON added in v0.1.1

func (g *AnyOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type AnyOneOf added in v0.1.1

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

AnyOneOf requires any one of the components.

func (*AnyOneOf) GetTemplates added in v0.1.1

func (g *AnyOneOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*AnyOneOf) SetTemplates added in v0.1.1

func (g *AnyOneOf) SetTemplates(t []*ReferenceTemplateV2)

func (*AnyOneOf) UnmarshalJSON added in v0.1.1

func (g *AnyOneOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type CRMetadata added in v0.3.0

type CRMetadata struct {
	Description string `json:"description,omitempty"`
}

CRMetadata holds metadata.

type CapturedValues added in v0.4.0

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

CapturedValues holds captured values from regex.

type CapturegroupsInlineDiff added in v0.3.0

type CapturegroupsInlineDiff struct{}

CapturegroupsInlineDiff handles inline diffs for capture groups.

func (CapturegroupsInlineDiff) Diff added in v0.3.0

func (id CapturegroupsInlineDiff) Diff(pattern, value string, sharedCapturedValues CapturedValues) (string, CapturedValues)

Diff is the main entrypoint called by compare.go

func (CapturegroupsInlineDiff) Validate added in v0.3.0

func (id CapturegroupsInlineDiff) Validate(pattern string) error

Validate is the validation entrypoint called by referenceV2.go

type CgInfo added in v0.3.0

type CgInfo struct {
	Name  string
	Full  string
	Start int
	End   int
}

CgInfo holds information about a capture group.

func CapturegroupIndex added in v0.3.0

func CapturegroupIndex(pattern string) []CgInfo

CapturegroupIndex returns a list of the valid-looking capturegroup indices within the given pattern string. Each inner list is a tuple of start:end indices that can be used to extract a capture group. For example:

groups := CaptureGroupIndex(pattern)
loc := groups[0]
cg := pattern[loc[0],loc[1]]

type ComponentTypeV1 added in v0.1.1

type ComponentTypeV1 string

ComponentTypeV1 is a v1 component type.

const (
	// Required is a required component type.
	Required ComponentTypeV1 = "Required"
	// Optional is an optional component.
	Optional ComponentTypeV1 = "Optional"
)

type ComponentV1 added in v0.1.1

type ComponentV1 struct {
	Name              string                 `json:"name"`
	Type              ComponentTypeV1        `json:"type,omitempty"`
	RequiredTemplates []*ReferenceTemplateV1 `json:"requiredTemplates,omitempty"`
	OptionalTemplates []*ReferenceTemplateV1 `json:"optionalTemplates,omitempty"`
}

ComponentV1 is a v1 component.

type ComponentV2 added in v0.1.1

type ComponentV2 struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	OneOf       `json:"oneOf,omitempty"`
	NoneOf      `json:"noneOf,omitempty"`
	AllOf       `json:"allOf,omitempty"`
	AnyOf       `json:"anyOf,omitempty"`
	AnyOneOf    `json:"anyOneOf,omitempty"`
	AllOrNoneOf `json:"allOrNoneOf,omitempty"`
	// contains filtered or unexported fields
}

ComponentV2 defines a component in v2.

type ComponentV2Group added in v0.1.1

type ComponentV2Group interface {
	SetTemplates([]*ReferenceTemplateV2)
	GetTemplates(*PartV2, *ComponentV2) []*ReferenceTemplateV2
	UnmarshalJSON([]byte) (err error)
	// contains filtered or unexported methods
}

ComponentV2Group defines a component group.

type CorrelationEntry added in v0.1.1

type CorrelationEntry interface {
	GetIdentifier() string
	GetMetadata() *unstructured.Unstructured
}

CorrelationEntry is an interface for correlation entries.

type CorrelationSettings

type CorrelationSettings struct {
	ManualCorrelation ManualCorrelation `json:"manualCorrelation"`
}

CorrelationSettings holds correlation settings.

type Correlator

type Correlator[T CorrelationEntry] interface {
	Match(*unstructured.Unstructured) ([]T, error)
}

Correlator provides an abstraction that allow the usage of different Resource correlation logics in the kubectl cluster-compare. The correlation process Matches for each Resource a template.

type DiffInfo added in v0.13.0

type DiffInfo struct {
	CapturedValues
	// contains filtered or unexported fields
}

DiffInfo holds info about a diff.

func NewDiffInfo added in v0.8.0

func NewDiffInfo(pattern string, sharedCapturedValues CapturedValues) DiffInfo

NewDiffInfo creates a new DiffInfo.

type DiffSum

type DiffSum struct {
	DiffOutput         string   `json:"DiffOutput"`
	CorrelatedTemplate string   `json:"CorrelatedTemplate"`
	CRName             string   `json:"CRName"`
	Patched            string   `json:"Patched,omitempty"`
	OverrideReasons    []string `json:"OverrideReason,omitempty"`
	Description        string   `json:"description,omitempty"`
}

DiffSum Contains the diff output and correlation info of a specific CR

func (DiffSum) HasDiff

func (s DiffSum) HasDiff() bool

HasDiff returns whether there is a diff.

func (DiffSum) String

func (s DiffSum) String() string

func (DiffSum) WasPatched added in v0.1.1

func (s DiffSum) WasPatched() bool

WasPatched returns whether it was patched.

type DoNotMatch added in v0.10.0

type DoNotMatch struct {
	Reason string
}

DoNotMatch indicates a regex should not match.

func (DoNotMatch) Error added in v0.10.0

func (e DoNotMatch) Error() string

type ExactMatchCorrelator

type ExactMatchCorrelator[T CorrelationEntry] struct {
	// contains filtered or unexported fields
}

ExactMatchCorrelator Matches templates by exact match between a predefined config including pairs of Resource names and there equivalent template. The names of the resources are in the apiVersion-kind-namespace-name format. For fields that are not namespaced apiVersion-kind-name format will be used.

func NewExactMatchCorrelator

func NewExactMatchCorrelator[T CorrelationEntry](matchPairs map[string]string, templates []T) (*ExactMatchCorrelator[T], error)

NewExactMatchCorrelator creates a new exact match correlator.

func (ExactMatchCorrelator[T]) Match

func (c ExactMatchCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match matches the object using exact matching.

type FieldCorrelator

type FieldCorrelator[T CorrelationEntry] struct {
	Fields [][]string
	// contains filtered or unexported fields
}

FieldCorrelator correlates by field.

func (*FieldCorrelator[T]) ClaimTemplates

func (f *FieldCorrelator[T]) ClaimTemplates(templates []T) []T

ClaimTemplates claims templates.

func (FieldCorrelator[T]) Match

func (f FieldCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match matches the object.

func (*FieldCorrelator[T]) ValidateTemplates

func (f *FieldCorrelator[T]) ValidateTemplates() error

ValidateTemplates validates templates.

type FieldsToOmit

type FieldsToOmit interface {
	GetDefault() string
	GetItems() map[string][]*ManifestPathV1
}

FieldsToOmit defines fields to omit.

type FieldsToOmitV1 added in v0.1.1

type FieldsToOmitV1 struct {
	DefaultOmitRef string                       `json:"defaultOmitRef,omitempty"`
	Items          map[string][]*ManifestPathV1 `json:"items,omitempty"`
}

FieldsToOmitV1 holds fields to omit for v1.

func (*FieldsToOmitV1) GetDefault added in v0.1.1

func (toOmit *FieldsToOmitV1) GetDefault() string

GetDefault returns the default fields to omit.

func (*FieldsToOmitV1) GetItems added in v0.1.1

func (toOmit *FieldsToOmitV1) GetItems() map[string][]*ManifestPathV1

GetItems returns the items to omit.

type FieldsToOmitV2 added in v0.2.0

type FieldsToOmitV2 struct {
	DefaultOmitRef string                            `json:"defaultOmitRef,omitempty"`
	Items          map[string][]*FieldsToOmitV2Entry `json:"items,omitempty"`
	// contains filtered or unexported fields
}

FieldsToOmitV2 holds fields to omit for v2.

func (*FieldsToOmitV2) GetDefault added in v0.2.0

func (toOmit *FieldsToOmitV2) GetDefault() string

GetDefault returns the default fields to omit.

func (*FieldsToOmitV2) GetItems added in v0.2.0

func (toOmit *FieldsToOmitV2) GetItems() map[string][]*ManifestPathV1

GetItems returns the items.

type FieldsToOmitV2Entry added in v0.2.0

type FieldsToOmitV2Entry struct {
	*ManifestPathV1
	Include string `json:"include,omitempty"`
	// contains filtered or unexported fields
}

FieldsToOmitV2Entry holds fields to omit for v2 entry.

type GroupCorrelator

type GroupCorrelator[T CorrelationEntry] struct {
	// contains filtered or unexported fields
}

GroupCorrelator Matches templates by hashing predefined fields. All The templates are indexed by hashing groups of `indexed` fields. The `indexed` fields can be nested. Resources will be attempted to be matched with hashing by the group with the largest amount of `indexed` fields. In case a Resource Matches by a hash a group of templates the group correlator will continue looking for a match (with groups with less `indexed fields`) until it finds a distinct match, in case it doesn't, MultipleMatches error will be returned. Templates will be only indexed by a group of fields only if all fields in group are not templated.

func NewGroupCorrelator

func NewGroupCorrelator[T CorrelationEntry](fieldGroups [][][]string, objects []T) (*GroupCorrelator[T], error)

NewGroupCorrelator creates a new GroupCorrelator using inputted fieldGroups and generated GroupFunctions and templatesByGroups. The templates will be divided into different kinds of groups based on the fields that are templated. Templates will be added to the kind of group that contains the biggest amount of fully defined `indexed` fields. For fieldsGroups = {{{"metadata", "namespace"}, {"kind"}}, {{"kind"}}} and the following templates: [fixedKindTemplate, fixedNamespaceKindTemplate] the fixedNamespaceKindTemplate will be added to a mapping where the keys are in the format of `namespace_kind`. The fixedKindTemplate will be added to a mapping where the keys are in the format of `kind`.

func (*GroupCorrelator[T]) Match

func (c *GroupCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match matches the object using group matching.

type HTTPFS

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

HTTPFS represents a file system that retrieves files from a http server by returning the http response body, ideal for http servers that return raw files

func (HTTPFS) Open

func (fs HTTPFS) Open(name string) (fs.File, error)

Open creates a http request and returns a http body reader object representing a file for reading.

type HTTPFile

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

HTTPFile represents a file obtained from an HTTP response body.

func (HTTPFile) Close

func (f HTTPFile) Close() error

Close closes the http body reader.

func (HTTPFile) Read

func (f HTTPFile) Read(b []byte) (int, error)

Read returns the http body.

func (HTTPFile) Stat

func (f HTTPFile) Stat() (fs.FileInfo, error)

Stat returns the HTTP file information.

type HTTPFileInfo

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

HTTPFileInfo represents information about the http raw resource

func (HTTPFileInfo) IsDir

func (f HTTPFileInfo) IsDir() bool

IsDir abbreviation for Mode().IsDir()

func (HTTPFileInfo) ModTime

func (f HTTPFileInfo) ModTime() time.Time

ModTime returns the time of the http response

func (HTTPFileInfo) Mode

func (f HTTPFileInfo) Mode() fs.FileMode

Mode returns the file mode bits - always returns fs.ModeTemporary because file isn't in local file system and is a http resource

func (HTTPFileInfo) Name

func (f HTTPFileInfo) Name() string

Name returns the uri of the file from the requested base URL

func (HTTPFileInfo) Size

func (f HTTPFileInfo) Size() int64

Size returns the length of the http body

func (HTTPFileInfo) Sys

func (f HTTPFileInfo) Sys() any

Sys underlying data source - returns nil

type InfoObject

type InfoObject struct {
	FieldsToOmit []*ManifestPathV1
	// contains filtered or unexported fields
}

InfoObject matches the diff.Object interface, it contains the objects that shall be compared.

func (InfoObject) Live

func (obj InfoObject) Live() runtime.Object

Live Returns the cluster version of the object

func (InfoObject) Merged

func (obj InfoObject) Merged() (runtime.Object, error)

Merged Returns the Injected Reference Version of the Resource

func (InfoObject) Name

func (obj InfoObject) Name() string

Name returns the name of the object.

type InlineDiff added in v0.3.0

type InlineDiff interface {
	Diff(templateValue, crValue string, sharedCapturedValues CapturedValues) (string, CapturedValues)
	Validate(templateValue string) error
}

InlineDiff defines an inline diff.

type InlineDiffError added in v0.3.0

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

InlineDiffError represents an inline diff error.

func (InlineDiffError) Error added in v0.3.0

func (e InlineDiffError) Error() string

type InlineDiffType added in v0.13.0

type InlineDiffType string

InlineDiffType represents the type of inline diff.

type ManifestPathV1 added in v0.1.1

type ManifestPathV1 struct {
	PathToKey string `json:"pathToKey"`
	IsPrefix  bool   `json:"isPrefix,omitempty"`
	// contains filtered or unexported fields
}

ManifestPathV1 represents a manifest path in v1.

func (*ManifestPathV1) Process added in v0.1.1

func (p *ManifestPathV1) Process() error

Process processes the manifest path.

type ManualCorrelation

type ManualCorrelation struct {
	CorrelationPairs map[string]string `json:"correlationPairs"`
}

ManualCorrelation holds manual correlation.

type MergeError

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

MergeError represents an error during merge.

func (MergeError) Error

func (e MergeError) Error() string

type MetricsTracker added in v0.0.2

type MetricsTracker struct {
	UnMatchedCRs []*unstructured.Unstructured

	MatchedTemplatesNames map[string]int
	// contains filtered or unexported fields
}

MetricsTracker Matches templates by using an existing correlator and gathers summary info related the correlation.

func NewMetricsTracker added in v0.0.2

func NewMetricsTracker() *MetricsTracker

NewMetricsTracker creates a new metrics tracker.

type MultiCorrelator

type MultiCorrelator[T CorrelationEntry] struct {
	// contains filtered or unexported fields
}

MultiCorrelator Matches templates by attempting to find a match with one of its predefined Correlators.

func NewMultiCorrelator

func NewMultiCorrelator[T CorrelationEntry](correlators []Correlator[T]) *MultiCorrelator[T]

NewMultiCorrelator creates a new multi correlator.

func (*MultiCorrelator[T]) AddCorrelator added in v0.13.0

func (c *MultiCorrelator[T]) AddCorrelator(correlator Correlator[T])

AddCorrelator adds a correlator to the multi correlator.

func (MultiCorrelator[T]) Match

func (c MultiCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match matches the object using all correlators.

type NoneOf added in v0.1.1

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

NoneOf requires none of the components.

func (*NoneOf) GetTemplates added in v0.1.1

func (g *NoneOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*NoneOf) SetTemplates added in v0.1.1

func (g *NoneOf) SetTemplates(t []*ReferenceTemplateV2)

func (*NoneOf) UnmarshalJSON added in v0.1.1

func (g *NoneOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type OneOf added in v0.1.1

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

OneOf requires one of the components.

func (*OneOf) GetTemplates added in v0.1.1

func (g *OneOf) GetTemplates(part *PartV2, component *ComponentV2) []*ReferenceTemplateV2

func (*OneOf) SetTemplates added in v0.1.1

func (g *OneOf) SetTemplates(t []*ReferenceTemplateV2)

func (*OneOf) UnmarshalJSON added in v0.1.1

func (g *OneOf) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals JSON.

type Options

type Options struct {
	CRs             resource.FilenameOptions
	ReferenceConfig string

	ShowManagedFields bool
	OutputFormat      string

	Concurrency int

	TmpDir string

	genericiooptions.IOStreams
	// contains filtered or unexported fields
}

Options holds command options.

func NewOptions

func NewOptions(ioStreams genericiooptions.IOStreams) *Options

NewOptions creates new options.

func (*Options) Complete

func (o *Options) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error

Complete completes the options.

func (*Options) GetRefFS added in v0.9.0

func (o *Options) GetRefFS() (fs.FS, error)

GetRefFS returns the reference file system.

func (*Options) Run

func (o *Options) Run() error

Run uses the factory to parse file arguments (in case of local mode) or gather all cluster resources matching templates types. For each Resource it finds the matching Resource template and injects, compares, and runs against differ.

type Output

type Output struct {
	Summary  *Summary   `json:"Summary"`
	Diffs    *[]DiffSum `json:"Diffs"`
	Warnings []Warning  `json:"Warnings,omitempty"`
	// contains filtered or unexported fields
}

Output Contains the complete output of the command

func (Output) JunitReport added in v0.9.0

func (o Output) JunitReport() *junit.TestSuites

JunitReport converts the given Output object to the equivalent junit.xml

func (Output) Print

func (o Output) Print(format string, out io.Writer, showEmptyDiffs bool) (int, error)

Print outputs the results.

func (Output) String

func (o Output) String(showEmptyDiffs bool) string

type OwnerReferenceCorrelator added in v0.13.0

type OwnerReferenceCorrelator[T CorrelationEntry] struct {
	// contains filtered or unexported fields
}

OwnerReferenceCorrelator searches for resources by checking if the resource appears in the ownerReferences field of any cluster resource. This handles cases where resources are managed by operators and don't exist as standalone objects but are referenced as owners.

func NewOwnerReferenceCorrelator added in v0.13.0

func NewOwnerReferenceCorrelator[T CorrelationEntry](templates []T, clusterCRs []*unstructured.Unstructured) *OwnerReferenceCorrelator[T]

NewOwnerReferenceCorrelator creates a new OwnerReferenceCorrelator It builds an index of all ownerReferences found in cluster resources

func (OwnerReferenceCorrelator[T]) Match added in v0.13.0

func (c OwnerReferenceCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match searches for the resource in the pre-built ownerReferences index

type PartV1 added in v0.1.1

type PartV1 struct {
	Name       string        `json:"name"`
	Components []ComponentV1 `json:"components"`
}

PartV1 is a v1 part.

type PartV2 added in v0.1.1

type PartV2 struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Components  []*ComponentV2 `json:"components"`
}

PartV2 defines a part in v2.

type PerFieldConfigV2 added in v0.3.0

type PerFieldConfigV2 struct {
	PathToKey      string         `json:"pathToKey,omitempty"`
	InlineDiffFunc InlineDiffType `json:"inlineDiffFunc,omitempty"`
}

PerFieldConfigV2 holds per field config.

type Reference

type Reference interface {
	GetAPIVersion() string
	GetTemplates() []ReferenceTemplate
	GetValidationIssues(matchedTemplates map[string]int) (map[string]map[string]ValidationIssue, int)
	GetFieldsToOmit() FieldsToOmit
	GetTemplateFunctionFiles() []string
}

Reference defines a reference.

func GetReference added in v0.0.2

func GetReference(fsys fs.FS, referenceFileName string) (Reference, error)

GetReference gets the reference.

type ReferenceTemplate

type ReferenceTemplate interface {
	GetFieldsToOmit(fieldsToOmit FieldsToOmit) []*ManifestPathV1
	Exec(params map[string]any) (*unstructured.Unstructured, error)
	GetMetadata() *unstructured.Unstructured
	GetIdentifier() string
	GetPath() string
	GetConfig() TemplateConfig
	GetTemplateTree() *parse.Tree
	GetDescription() string
}

ReferenceTemplate defines a reference template.

func ParseTemplates added in v0.0.2

func ParseTemplates(ref Reference, fsys fs.FS) ([]ReferenceTemplate, error)

ParseTemplates parses templates.

func ParseV1Templates added in v0.1.1

func ParseV1Templates(ref *ReferenceV1, fsys fs.FS) ([]ReferenceTemplate, error)

ParseV1Templates parses templates for a v1 reference.

func ParseV2Templates added in v0.1.1

func ParseV2Templates(ref *ReferenceV2, fsys fs.FS) ([]ReferenceTemplate, error)

ParseV2Templates parses v2 templates.

type ReferenceTemplateConfigV1 added in v0.1.1

type ReferenceTemplateConfigV1 struct {
	AllowMerge       bool     `json:"ignore-unspecified-fields,omitempty"`
	FieldsToOmitRefs []string `json:"fieldsToOmitRefs,omitempty"`
}

ReferenceTemplateConfigV1 holds configuration for v1 reference templates.

func (ReferenceTemplateConfigV1) GetAllowMerge added in v0.1.1

func (config ReferenceTemplateConfigV1) GetAllowMerge() bool

GetAllowMerge returns whether merging is allowed.

func (ReferenceTemplateConfigV1) GetFieldsToOmitRefs added in v0.1.1

func (config ReferenceTemplateConfigV1) GetFieldsToOmitRefs() []string

GetFieldsToOmitRefs returns the fields to omit references.

func (ReferenceTemplateConfigV1) GetInlineDiffFuncs added in v0.3.0

func (config ReferenceTemplateConfigV1) GetInlineDiffFuncs() map[string]InlineDiffType

GetInlineDiffFuncs returns the inline diff functions.

type ReferenceTemplateConfigV2 added in v0.3.0

type ReferenceTemplateConfigV2 struct {
	PerField []*PerFieldConfigV2 `json:"perField,omitempty"`
	ReferenceTemplateConfigV1
}

ReferenceTemplateConfigV2 holds configuration.

func (ReferenceTemplateConfigV2) GetInlineDiffFuncs added in v0.3.0

func (config ReferenceTemplateConfigV2) GetInlineDiffFuncs() map[string]InlineDiffType

GetInlineDiffFuncs returns inline diff funcs.

type ReferenceTemplateV1 added in v0.1.1

type ReferenceTemplateV1 struct {
	*template.Template `json:"-"`
	Path               string                    `json:"path"`
	Description        string                    `json:"description,omitempty"`
	Config             ReferenceTemplateConfigV1 `json:"config,omitempty"`
	// contains filtered or unexported fields
}

ReferenceTemplateV1 is a v1 reference template.

func (ReferenceTemplateV1) Exec added in v0.1.1

func (rf ReferenceTemplateV1) Exec(params map[string]any) (*unstructured.Unstructured, error)

Exec executes the template.

func (ReferenceTemplateV1) GetConfig added in v0.1.1

func (rf ReferenceTemplateV1) GetConfig() TemplateConfig

GetConfig returns the template config.

func (ReferenceTemplateV1) GetDescription added in v0.3.0

func (rf ReferenceTemplateV1) GetDescription() string

GetDescription returns the template description.

func (ReferenceTemplateV1) GetFieldsToOmit added in v0.1.1

func (rf ReferenceTemplateV1) GetFieldsToOmit(fieldsToOmit FieldsToOmit) []*ManifestPathV1

GetFieldsToOmit returns the fields to omit for this template.

func (ReferenceTemplateV1) GetIdentifier added in v0.1.1

func (rf ReferenceTemplateV1) GetIdentifier() string

GetIdentifier returns the template identifier.

func (ReferenceTemplateV1) GetMetadata added in v0.1.1

func (rf ReferenceTemplateV1) GetMetadata() *unstructured.Unstructured

GetMetadata returns the template metadata.

func (ReferenceTemplateV1) GetPath added in v0.1.1

func (rf ReferenceTemplateV1) GetPath() string

GetPath returns the template path.

func (ReferenceTemplateV1) GetTemplateTree added in v0.1.1

func (rf ReferenceTemplateV1) GetTemplateTree() *parse.Tree

GetTemplateTree returns the parsed template tree.

func (ReferenceTemplateV1) ValidateFieldsToOmit added in v0.1.1

func (rf ReferenceTemplateV1) ValidateFieldsToOmit(fieldsToOmit FieldsToOmit) error

ValidateFieldsToOmit validates the fields to omit.

type ReferenceTemplateV2 added in v0.3.0

type ReferenceTemplateV2 struct {
	Config ReferenceTemplateConfigV2 `json:"config,omitempty"`

	ReferenceTemplateV1
	// contains filtered or unexported fields
}

ReferenceTemplateV2 represents a reference template in v2.

func (ReferenceTemplateV2) GetConfig added in v0.3.0

func (rf ReferenceTemplateV2) GetConfig() TemplateConfig

GetConfig returns the template config.

func (ReferenceTemplateV2) GetDescription added in v0.4.0

func (rf ReferenceTemplateV2) GetDescription() string

GetDescription returns the description.

type ReferenceV1 added in v0.1.1

type ReferenceV1 struct {
	Version string `json:"apiVersion,omitempty"`

	Parts                 []PartV1        `json:"parts"`
	TemplateFunctionFiles []string        `json:"templateFunctionFiles,omitempty"`
	FieldsToOmit          *FieldsToOmitV1 `json:"fieldsToOmit,omitempty"`
	// contains filtered or unexported fields
}

ReferenceV1 is a v1 reference.

func (*ReferenceV1) GetAPIVersion added in v0.1.1

func (r *ReferenceV1) GetAPIVersion() string

GetAPIVersion returns the API version.

func (*ReferenceV1) GetFieldsToOmit added in v0.1.1

func (r *ReferenceV1) GetFieldsToOmit() FieldsToOmit

GetFieldsToOmit returns the fields to omit.

func (*ReferenceV1) GetTemplateFunctionFiles added in v0.1.1

func (r *ReferenceV1) GetTemplateFunctionFiles() []string

GetTemplateFunctionFiles returns the template function files.

func (*ReferenceV1) GetTemplates added in v0.1.1

func (r *ReferenceV1) GetTemplates() []ReferenceTemplate

GetTemplates returns the templates.

func (*ReferenceV1) GetValidationIssues added in v0.1.1

func (r *ReferenceV1) GetValidationIssues(matchedTemplates map[string]int) (map[string]map[string]ValidationIssue, int)

GetValidationIssues returns the validation issues.

type ReferenceV2 added in v0.1.1

type ReferenceV2 struct {
	Version string `json:"apiVersion,omitempty"`

	Parts                 []*PartV2       `json:"parts"`
	TemplateFunctionFiles []string        `json:"templateFunctionFiles,omitempty"`
	FieldsToOmit          *FieldsToOmitV2 `json:"fieldsToOmit,omitempty"`
	// contains filtered or unexported fields
}

ReferenceV2 is a v2 reference.

func (*ReferenceV2) GetAPIVersion added in v0.1.1

func (r *ReferenceV2) GetAPIVersion() string

GetAPIVersion returns the API version.

func (*ReferenceV2) GetFieldsToOmit added in v0.1.1

func (r *ReferenceV2) GetFieldsToOmit() FieldsToOmit

GetFieldsToOmit returns the fields to omit.

func (*ReferenceV2) GetTemplateFunctionFiles added in v0.1.1

func (r *ReferenceV2) GetTemplateFunctionFiles() []string

GetTemplateFunctionFiles returns the template function files.

func (*ReferenceV2) GetTemplates added in v0.1.1

func (r *ReferenceV2) GetTemplates() []ReferenceTemplate

GetTemplates returns the templates.

func (*ReferenceV2) GetValidationIssues added in v0.1.1

func (r *ReferenceV2) GetValidationIssues(matchedTemplates map[string]int) (map[string]map[string]ValidationIssue, int)

GetValidationIssues returns the validation issues.

type RegexInlineDiff added in v0.3.0

type RegexInlineDiff struct{}

RegexInlineDiff handles inline diffs for regex.

func (RegexInlineDiff) Diff added in v0.3.0

func (id RegexInlineDiff) Diff(regex, crValue string, sharedCapturedValues CapturedValues) (string, CapturedValues)

Diff returns the inline diff for regex.

func (RegexInlineDiff) Validate added in v0.3.0

func (id RegexInlineDiff) Validate(regex string) error

Validate validates a regex.

type SubjectsCorrelator added in v0.13.0

type SubjectsCorrelator[T CorrelationEntry] struct {
	// contains filtered or unexported fields
}

SubjectsCorrelator searches for resources by checking if the resource appears in the subjects field of RBAC resources (ClusterRoleBindings, RoleBindings). This handles cases where ServiceAccounts and other subjects are referenced but don't exist as standalone objects in the collection.

func NewSubjectsCorrelator added in v0.13.0

func NewSubjectsCorrelator[T CorrelationEntry](templates []T, clusterCRs []*unstructured.Unstructured) *SubjectsCorrelator[T]

NewSubjectsCorrelator creates a new SubjectsCorrelator It builds an index of all subjects found in RBAC resources

func (SubjectsCorrelator[T]) Match added in v0.13.0

func (c SubjectsCorrelator[T]) Match(object *unstructured.Unstructured) ([]T, error)

Match searches for the resource in the pre-built subjects index

type Summary

type Summary struct {
	ValidationIssues       map[string]map[string]ValidationIssue `json:"ValidationIssuses"`
	NumMissing             int                                   `json:"NumMissing"`
	UnmatchedCRS           []string                              `json:"UnmatchedCRS"`
	NumDiffCRs             int                                   `json:"NumDiffCRs"`
	TotalCRs               int                                   `json:"TotalCRs"`
	MetadataHash           string                                `json:"MetadataHash"`
	PatchedCRs             int                                   `json:"patchedCRs"`
	MatchedByReferenceOnly []string                              `json:"matchedByReferenceOnly,omitempty"`
}

Summary Contains all info included in the Summary output of the compare command

func (Summary) String

func (s Summary) String() string

type TemplateConfig added in v0.1.1

type TemplateConfig interface {
	GetAllowMerge() bool
	GetFieldsToOmitRefs() []string
	GetInlineDiffFuncs() map[string]InlineDiffType
}

TemplateConfig defines template configuration.

type UnknownMatch

type UnknownMatch struct {
	Resource *unstructured.Unstructured
}

UnknownMatch an error that can be returned by a Correlator in a case no template was matched for a Resource.

func (UnknownMatch) Error

func (e UnknownMatch) Error() string

type UserConfig

type UserConfig struct {
	CorrelationSettings CorrelationSettings `json:"correlationSettings"`
}

UserConfig holds user config.

type UserOverride added in v0.1.1

type UserOverride struct {
	Name         string    `json:"name,omitempty"`
	APIVersion   string    `json:"apiVersion,omitempty"`
	Kind         string    `json:"kind,omitempty"`
	Namespace    string    `json:"namespace,omitempty"`
	ExactMatch   string    `json:"exactMatch,omitempty"`
	Reason       string    `json:"reason"`
	Type         patchType `json:"type"`
	Patch        string    `json:"patch"`
	TemplatePath string    `json:"templatePath"`
}

UserOverride represents a user override.

func CreateMergePatch added in v0.1.1

func CreateMergePatch(temp ReferenceTemplate, obj *InfoObject, reason string) (*UserOverride, error)

CreateMergePatch creates a merge patch.

func LoadUserOverrides added in v0.1.1

func LoadUserOverrides(path string) ([]*UserOverride, error)

LoadUserOverrides loads user overrides.

func (UserOverride) Apply added in v0.1.1

Apply applies the override.

func (UserOverride) GetIdentifier added in v0.1.1

func (o UserOverride) GetIdentifier() string

GetIdentifier returns the identifier.

func (UserOverride) GetMetadata added in v0.1.1

func (o UserOverride) GetMetadata() *unstructured.Unstructured

GetMetadata returns the metadata.

func (UserOverride) GetName added in v0.1.1

func (o UserOverride) GetName() string

GetName returns the name.

type ValidationIssue added in v0.1.1

type ValidationIssue struct {
	Msg        string                `json:"Msg,omitempty"`
	CRs        []string              `json:"CRs,omitempty"`
	CRMetadata map[string]CRMetadata `json:"crMetadata,omitempty"`
}

ValidationIssue holds a validation issue.

type Warning added in v0.13.0

type Warning struct {
	Type      string   `json:"type"`
	Message   string   `json:"message"`
	Resources []string `json:"resources"`
}

Warning represents a warning message in the output

Jump to

Keyboard shortcuts

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