compare

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 38 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DiffSeparator = "**********************************\n"

	DiffsFoundMsg = "there are differences between the cluster CRs and the reference CRs"
)
View Source
const (
	Json string = "json"
	Yaml string = "yaml"
)

Variables

View Source
var FieldSeparator = "_"
View Source
var OutputFormats = []string{Json, Yaml}

Functions

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"
  • "tpl"

These are late-bound in Engine.Render(). The version included in the FuncMap is a placeholder.

func GetRefFS added in v0.0.2

func GetRefFS(refConfig string) (fs.FS, error)

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.

Types

type Component

type Component struct {
	Name              string               `json:"name"`
	Type              ComponentType        `json:"type,omitempty"`
	RequiredTemplates []*ReferenceTemplate `json:"requiredTemplates,omitempty"`
	OptionalTemplates []*ReferenceTemplate `json:"optionalTemplates,omitempty"`
}

type ComponentType

type ComponentType string
const (
	Required ComponentType = "Required"
	Optional ComponentType = "Optional"
)

type CorrelationSettings

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

type Correlator

type Correlator interface {
	Match(*unstructured.Unstructured) ([]*ReferenceTemplate, 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 DiffSum

type DiffSum struct {
	DiffOutput         string `json:"DiffOutput"`
	CorrelatedTemplate string `json:"CorrelatedTemplate"`
	CRName             string `json:"CRName"`
}

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

func (DiffSum) HasDiff

func (s DiffSum) HasDiff() bool

func (DiffSum) String

func (s DiffSum) String() string

type ExactMatchCorrelator

type ExactMatchCorrelator 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(crToTemplate map[string]string, templates []*ReferenceTemplate) (*ExactMatchCorrelator, error)

func (ExactMatchCorrelator) Match

type FieldCorrelator

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

func (*FieldCorrelator) ClaimTemplates

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

func (FieldCorrelator) Match

func (*FieldCorrelator) ValidateTemplates

func (f *FieldCorrelator) ValidateTemplates() error

type FieldsToOmit

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

type GroupCorrelator

type GroupCorrelator 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(fieldGroups [][][]string, templates []*ReferenceTemplate) (*GroupCorrelator, 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) Match

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 []*ManifestPath
	// 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

type ManifestPath

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

func (*ManifestPath) Process

func (p *ManifestPath) Process() error

type ManualCorrelation

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

type MergeError

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

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

type MultiCorrelator

type MultiCorrelator 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(correlators []Correlator) *MultiCorrelator

func (MultiCorrelator) Match

type Options

type Options struct {
	CRs resource.FilenameOptions

	ShowManagedFields bool
	OutputFormat      string

	Concurrency int

	genericiooptions.IOStreams
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions(ioStreams genericiooptions.IOStreams) *Options

func (*Options) Complete

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

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"`
}

Output Contains the complete output of the command

func (Output) Print

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

func (Output) String

func (o Output) String(showEmptyDiffs bool) string

type Part

type Part struct {
	Name       string      `json:"name"`
	Components []Component `json:"components"`
}

type Reference

type Reference struct {
	Parts                 []Part       `json:"parts"`
	TemplateFunctionFiles []string     `json:"templateFunctionFiles,omitempty"`
	FieldsToOmit          FieldsToOmit `json:"fieldsToOmit,omitempty"`
}

func GetReference added in v0.0.2

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

func (*Reference) GetTemplates added in v0.0.2

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

type ReferenceTemplate

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

func ParseTemplates added in v0.0.2

func ParseTemplates(templateReference []*ReferenceTemplate, functionTemplates []string, fsys fs.FS, ref *Reference) ([]*ReferenceTemplate, error)

func (ReferenceTemplate) Exec

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

func (ReferenceTemplate) FieldsToOmit

func (rf ReferenceTemplate) FieldsToOmit(fieldsToOmit FieldsToOmit) []*ManifestPath

func (ReferenceTemplate) Name

func (rf ReferenceTemplate) Name() string

func (ReferenceTemplate) ValidateFieldsToOmit

func (rf ReferenceTemplate) ValidateFieldsToOmit(fieldsToOmit FieldsToOmit) error

type ReferenceTemplateConfig

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

type Summary

type Summary struct {
	RequiredCRS  map[string]map[string][]string `json:"RequiredCRS"`
	NumMissing   int                            `json:"NumMissing"`
	UnmatchedCRS []string                       `json:"UnmatchedCRS"`
	NumDiffCRs   int                            `json:"NumDiffCRs"`
	TotalCRs     int                            `json:"TotalCRs"`
	MetadataHash string                         `json:"MetadataHash"`
}

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

func (Summary) String

func (s Summary) String() string

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"`
}

Jump to

Keyboard shortcuts

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