types

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package types provides types used in the renderer in order to facilitate code reuse in test

Index

Constants

View Source
const (
	DiffTypeWordAdded    = "added"
	DiffTypeWordRemoved  = "removed"
	DiffTypeWordModified = "modified"
	DiffTypeWordEqual    = "equal"
)

DiffTypeWord constants for human-readable JSON output. These are used in structured output (JSON/YAML) for better readability.

View Source
const (
	DiffKeyOld  = "old"  // Current state for modified resources
	DiffKeyNew  = "new"  // Desired state for modified resources
	DiffKeySpec = "spec" // Full spec for added/removed resources
)

DiffKey constants for structured diff output. These are the keys used in the diff map to hold resource states.

View Source
const (
	// ColorRed an ANSI "begin red" character.
	ColorRed = "\x1b[31m"
	// ColorGreen an ANSI "begin green" character.
	ColorGreen = "\x1b[32m"
	// ColorYellow an ANSI "begin yellow" character.
	ColorYellow = "\x1b[33m"
	// ColorReset an ANSI "reset color" character.
	ColorReset = "\x1b[0m"
)

Colors for terminal output.

Variables

This section is empty.

Functions

func MakeDiffKey

func MakeDiffKey(apiVersion, kind, namespace, name string) string

MakeDiffKey creates a unique key for a resource diff. Format: apiVersion/kind/namespace/name (namespace may be empty for cluster-scoped resources).

func MakeDiffKeyFromResource added in v0.6.2

func MakeDiffKeyFromResource(res *un.Unstructured) string

MakeDiffKeyFromResource creates a unique key for a resource diff from an Unstructured resource. This is a convenience wrapper around MakeDiffKey that extracts all fields from the resource.

Types

type DiffType

type DiffType string

DiffType represents the type of diff (added, removed, modified).

const (
	// DiffTypeAdded an added section.
	DiffTypeAdded DiffType = "+"
	// DiffTypeRemoved a removed section.
	DiffTypeRemoved DiffType = "-"
	// DiffTypeModified a modified section.
	DiffTypeModified DiffType = "~"
	// DiffTypeEqual an unchanged section.
	DiffTypeEqual DiffType = "="
)

func (DiffType) ToWord added in v0.7.0

func (d DiffType) ToWord() string

ToWord converts a DiffType symbol to its human-readable word.

type OutputError added in v0.7.0

type OutputError struct {
	ResourceID string `json:"resourceID,omitempty"`
	Message    string `json:"message"`
}

OutputError represents an error in structured output. Used consistently by both XR diff and comp diff for machine-readable error handling. Note: Only JSON tags are used because sigs.k8s.io/yaml uses JSON tags for YAML serialization.

func (OutputError) FormatError added in v0.7.0

func (e OutputError) FormatError() string

FormatError returns a human-readable error string. If ResourceID is empty, it uses "<global>" to indicate a system-level error not tied to any specific resource (e.g., cluster connection issues).

type ResourceDiff

type ResourceDiff struct {
	Gvk          schema.GroupVersionKind
	Namespace    string
	ResourceName string
	DiffType     DiffType
	LineDiffs    []diffmatchpatch.Diff
	Current      *un.Unstructured // Optional, for reference
	Desired      *un.Unstructured // Optional, for reference
}

ResourceDiff represents the diff for a specific resource.

func (*ResourceDiff) GetDiffKey

func (d *ResourceDiff) GetDiffKey() string

GetDiffKey returns a key that can be used to identify this object for use in a map.

Jump to

Keyboard shortcuts

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