Documentation
¶
Overview ¶
Package renderer contains the logic for formatting and displaying diffs.
Index ¶
- func FormatDiff(diffs []diffmatchpatch.Diff, options DiffOptions) string
- func GenerateDiffWithOptions(_ context.Context, current, desired *un.Unstructured, logger logging.Logger, ...) (*t.ResourceDiff, error)
- func GetLineDiff(oldText, newText string) []diffmatchpatch.Diff
- type AffectedResourcesSummary
- type ChangeDetail
- type CompDiffOutput
- type CompDiffRenderer
- type CompactDiffFormatter
- type CompositionDiff
- type DefaultCompDiffRenderer
- type DefaultDiffRenderer
- type DiffFormatter
- type DiffOptions
- type DiffRenderer
- type DownstreamChanges
- type FullDiffFormatter
- type OutputError
- type OutputFormat
- type StructuredCompDiffRenderer
- type StructuredDiffOutput
- type StructuredDiffRenderer
- type Summary
- type XRImpact
- type XRStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDiff ¶
func FormatDiff(diffs []diffmatchpatch.Diff, options DiffOptions) string
FormatDiff formats a slice of diffs according to the provided options.
func GenerateDiffWithOptions ¶
func GenerateDiffWithOptions(_ context.Context, current, desired *un.Unstructured, logger logging.Logger, options DiffOptions) (*t.ResourceDiff, error)
GenerateDiffWithOptions produces a structured diff between two unstructured objects.
func GetLineDiff ¶
func GetLineDiff(oldText, newText string) []diffmatchpatch.Diff
GetLineDiff performs a proper line-by-line diff and returns the raw diffs.
Types ¶
type AffectedResourcesSummary ¶ added in v0.7.0
type AffectedResourcesSummary struct {
Total int `json:"total"`
WithChanges int `json:"withChanges"`
Unchanged int `json:"unchanged"`
WithErrors int `json:"withErrors"`
FilteredByPolicy int `json:"filteredByPolicy,omitempty"`
}
AffectedResourcesSummary contains counts of affected resources by status.
type ChangeDetail ¶ added in v0.6.0
type ChangeDetail struct {
Type string `json:"type"`
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Diff map[string]any `json:"diff"`
}
ChangeDetail represents a single resource change.
type CompDiffOutput ¶ added in v0.7.0
type CompDiffOutput struct {
Compositions []CompositionDiff
Errors []dt.OutputError // top-level errors (e.g., XRs that failed impact analysis)
}
CompDiffOutput is the top-level output for composition diffs (internal representation). This stores rich ResourceDiff data. Conversion to JSON happens in the renderer.
type CompDiffRenderer ¶ added in v0.7.0
type CompDiffRenderer interface {
// RenderCompDiff renders the complete composition diff output.
// This includes composition changes, affected XR list, and impact analysis.
RenderCompDiff(stdout io.Writer, output *CompDiffOutput) error
}
CompDiffRenderer renders composition diff results. Both human-readable and structured (JSON/YAML) renderers implement this interface.
func NewDefaultCompDiffRenderer ¶ added in v0.7.0
func NewDefaultCompDiffRenderer(logger logging.Logger, diffRenderer DiffRenderer, colorize bool) CompDiffRenderer
NewDefaultCompDiffRenderer creates a new human-readable composition diff renderer.
func NewStructuredCompDiffRenderer ¶ added in v0.7.0
func NewStructuredCompDiffRenderer(logger logging.Logger, format OutputFormat) CompDiffRenderer
NewStructuredCompDiffRenderer creates a new structured composition diff renderer.
type CompactDiffFormatter ¶
type CompactDiffFormatter struct{}
CompactDiffFormatter formats diffs with limited context lines.
func (*CompactDiffFormatter) Format ¶
func (f *CompactDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
Format implements the DiffFormatter interface for CompactDiffFormatter.
type CompositionDiff ¶ added in v0.7.0
type CompositionDiff struct {
Name string
Error error // per-composition error (nil if successful)
CompositionDiff *dt.ResourceDiff // the actual composition diff (nil if unchanged)
AffectedResources AffectedResourcesSummary
ImpactAnalysis []XRImpact
}
CompositionDiff represents the diff result for a single composition (internal). This stores rich ResourceDiff data. Conversion to JSON happens in the renderer.
func (*CompositionDiff) HasChanges ¶ added in v0.7.0
func (c *CompositionDiff) HasChanges() bool
HasChanges returns true if this composition diff has any changes.
type DefaultCompDiffRenderer ¶ added in v0.7.0
type DefaultCompDiffRenderer struct {
// contains filtered or unexported fields
}
DefaultCompDiffRenderer renders composition diffs in human-readable format.
func (*DefaultCompDiffRenderer) RenderCompDiff ¶ added in v0.7.0
func (r *DefaultCompDiffRenderer) RenderCompDiff(stdout io.Writer, output *CompDiffOutput) error
RenderCompDiff renders the composition diff in human-readable format.
type DefaultDiffRenderer ¶
type DefaultDiffRenderer struct {
// contains filtered or unexported fields
}
DefaultDiffRenderer implements the DiffRenderer interface.
func (*DefaultDiffRenderer) RenderDiffs ¶
func (r *DefaultDiffRenderer) RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff, errs []dt.OutputError) error
RenderDiffs formats and prints the diffs to the provided writer. For human-readable output, errors are written at the end after the summary.
func (*DefaultDiffRenderer) SetDiffOptions ¶
func (r *DefaultDiffRenderer) SetDiffOptions(options DiffOptions)
SetDiffOptions updates the diff options used by the renderer.
type DiffFormatter ¶
type DiffFormatter interface {
Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
}
DiffFormatter is the interface that defines the contract for diff formatters.
func NewFormatter ¶
func NewFormatter(compact bool) DiffFormatter
NewFormatter returns a DiffFormatter based on whether compact mode is desired.
type DiffOptions ¶
type DiffOptions struct {
// UseColors determines whether to colorize the output
UseColors bool
// AddPrefix is the prefix for added lines (default "+")
AddPrefix string
// DeletePrefix is the prefix for deleted lines (default "-")
DeletePrefix string
// ContextPrefix is the prefix for unchanged lines (default " ")
ContextPrefix string
// ContextLines is the number of unchanged lines to show before/after changes in compact mode
ContextLines int
// ChunkSeparator is the string used to separate chunks in compact mode
ChunkSeparator string
// Compact determines whether to show a compact diff
Compact bool
// IgnorePaths is a list of paths to ignore when calculating diffs
// Supports both simple paths (e.g., "metadata.annotations") and
// map key paths (e.g., "metadata.annotations[key.name/value]")
IgnorePaths []string
}
DiffOptions holds configuration options for the diff output.
func DefaultDiffOptions ¶
func DefaultDiffOptions() DiffOptions
DefaultDiffOptions returns the default options with colors enabled.
type DiffRenderer ¶
type DiffRenderer interface {
// RenderDiffs formats and outputs diffs to the provided writer.
// The errs parameter contains any resource processing errors to include in output.
RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff, errs []dt.OutputError) error
}
DiffRenderer handles rendering diffs to output.
func NewDiffRenderer ¶
func NewDiffRenderer(logger logging.Logger, diffOpts DiffOptions) DiffRenderer
NewDiffRenderer creates a new DefaultDiffRenderer with the given options.
func NewStructuredDiffRenderer ¶ added in v0.6.0
func NewStructuredDiffRenderer(logger logging.Logger, format OutputFormat) DiffRenderer
NewStructuredDiffRenderer creates a new structured renderer with the specified format.
type DownstreamChanges ¶ added in v0.7.0
type DownstreamChanges struct {
Summary Summary `json:"summary"`
Changes []ChangeDetail `json:"changes"`
}
DownstreamChanges contains the downstream resource changes for an XR.
type FullDiffFormatter ¶
type FullDiffFormatter struct{}
FullDiffFormatter formats diffs with all context lines.
func (*FullDiffFormatter) Format ¶
func (f *FullDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
Format implements the DiffFormatter interface for FullDiffFormatter.
type OutputError ¶ added in v0.7.0
type OutputError = dt.OutputError
OutputError is an alias for dt.OutputError for convenience. Use this type for error handling in structured output.
type OutputFormat ¶ added in v0.6.0
type OutputFormat string
OutputFormat represents the desired output format for diffs.
const ( // OutputFormatDiff is the default human-readable diff format. OutputFormatDiff OutputFormat = "diff" // OutputFormatJSON outputs structured JSON. OutputFormatJSON OutputFormat = "json" // OutputFormatYAML outputs structured YAML. OutputFormatYAML OutputFormat = "yaml" )
type StructuredCompDiffRenderer ¶ added in v0.7.0
type StructuredCompDiffRenderer struct {
// contains filtered or unexported fields
}
StructuredCompDiffRenderer renders composition diffs in JSON/YAML format.
func (*StructuredCompDiffRenderer) RenderCompDiff ¶ added in v0.7.0
func (r *StructuredCompDiffRenderer) RenderCompDiff(stdout io.Writer, output *CompDiffOutput) error
RenderCompDiff renders the composition diff in structured format (JSON/YAML).
type StructuredDiffOutput ¶ added in v0.6.0
type StructuredDiffOutput struct {
Summary Summary `json:"summary"`
Changes []ChangeDetail `json:"changes"`
Errors []dt.OutputError `json:"errors,omitempty"`
}
StructuredDiffOutput represents the structured output format for diffs. Note: Only JSON tags are used because sigs.k8s.io/yaml uses JSON tags for YAML serialization.
type StructuredDiffRenderer ¶ added in v0.6.0
type StructuredDiffRenderer struct {
// contains filtered or unexported fields
}
StructuredDiffRenderer renders diffs in structured formats (JSON/YAML).
func (*StructuredDiffRenderer) RenderDiffs ¶ added in v0.6.0
func (r *StructuredDiffRenderer) RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff, errs []dt.OutputError) error
RenderDiffs renders the diffs in the configured structured format.
type Summary ¶ added in v0.6.0
type Summary struct {
Added int `json:"added"`
Modified int `json:"modified"`
Removed int `json:"removed"`
}
Summary contains aggregated counts of changes.
type XRImpact ¶ added in v0.7.0
type XRImpact struct {
corev1.ObjectReference
Status XRStatus
Error error // store actual error, not string
Diffs map[string]*dt.ResourceDiff // downstream diffs (nil if unchanged/error)
}
XRImpact represents the impact analysis for a single XR (internal). This stores rich ResourceDiff data. Conversion to JSON happens in the renderer. Embeds corev1.ObjectReference for the common resource identity fields.
type XRStatus ¶ added in v0.7.0
type XRStatus string
XRStatus represents the processing status of an XR in composition diffs.
const ( // XRStatusChanged indicates the XR has downstream resource changes. XRStatusChanged XRStatus = "changed" // XRStatusUnchanged indicates the XR has no downstream resource changes. XRStatusUnchanged XRStatus = "unchanged" // XRStatusError indicates an error occurred while processing the XR. XRStatusError XRStatus = "error" )