Documentation
¶
Overview ¶
Package diffprocessor contains the logic to calculate and render diffs.
Index ¶
- type CompDiffProcessor
- type ComponentFactories
- type DefaultCompDiffProcessor
- type DefaultDiffCalculator
- func (c *DefaultDiffCalculator) CalculateDiff(ctx context.Context, composite *un.Unstructured, desired *un.Unstructured) (*dt.ResourceDiff, error)
- func (c *DefaultDiffCalculator) CalculateDiffs(ctx context.Context, xr *cmp.Unstructured, desired render.Outputs) (map[string]*dt.ResourceDiff, error)
- func (c *DefaultDiffCalculator) CalculateRemovedResourceDiffs(ctx context.Context, xr *un.Unstructured, renderedResources map[string]bool) (map[string]*dt.ResourceDiff, error)
- func (c *DefaultDiffCalculator) SetDiffOptions(options renderer.DiffOptions)
- type DefaultDiffProcessor
- func (p *DefaultDiffProcessor) DiffSingleResource(ctx context.Context, res *un.Unstructured, ...) (map[string]*dt.ResourceDiff, error)
- func (p *DefaultDiffProcessor) Initialize(ctx context.Context) error
- func (p *DefaultDiffProcessor) PerformDiff(ctx context.Context, stdout io.Writer, resources []*un.Unstructured, ...) error
- func (p *DefaultDiffProcessor) RenderWithRequirements(ctx context.Context, xr *cmp.Unstructured, comp *apiextensionsv1.Composition, ...) (render.Outputs, error)
- func (p *DefaultDiffProcessor) SanitizeXR(res *un.Unstructured, resourceID string) (*cmp.Unstructured, bool, error)
- type DefaultResourceManager
- type DefaultSchemaValidator
- func (v *DefaultSchemaValidator) EnsureComposedResourceCRDs(ctx context.Context, resources []*un.Unstructured) error
- func (v *DefaultSchemaValidator) GetCRDs() []*extv1.CustomResourceDefinition
- func (v *DefaultSchemaValidator) LoadCRDs(ctx context.Context) error
- func (v *DefaultSchemaValidator) ValidateResources(ctx context.Context, xr *un.Unstructured, composed []cpd.Unstructured) error
- func (v *DefaultSchemaValidator) ValidateScopeConstraints(ctx context.Context, resource *un.Unstructured, expectedNamespace string, ...) error
- type DiffCalculator
- type DiffProcessor
- type ProcessorConfig
- type ProcessorOption
- func WithColorize(colorize bool) ProcessorOption
- func WithCompact(compact bool) ProcessorOption
- func WithDiffCalculatorFactory(...) ProcessorOption
- func WithDiffRendererFactory(factory func(logging.Logger, renderer.DiffOptions) renderer.DiffRenderer) ProcessorOption
- func WithLogger(logger logging.Logger) ProcessorOption
- func WithNamespace(namespace string) ProcessorOption
- func WithRenderFunc(renderFn RenderFunc) ProcessorOption
- func WithRequirementsProviderFactory(...) ProcessorOption
- func WithResourceManagerFactory(...) ProcessorOption
- func WithSchemaValidatorFactory(...) ProcessorOption
- type RenderFunc
- type RequirementsProvider
- type ResourceManager
- type SchemaValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompDiffProcessor ¶
type CompDiffProcessor interface { DiffComposition(ctx context.Context, stdout io.Writer, compositions []*un.Unstructured, namespace string) error Initialize(ctx context.Context) error }
CompDiffProcessor defines the interface for composition diffing.
func NewCompDiffProcessor ¶
func NewCompDiffProcessor(xrProc DiffProcessor, compositionClient xp.CompositionClient, opts ...ProcessorOption) CompDiffProcessor
NewCompDiffProcessor creates a new DefaultCompDiffProcessor.
type ComponentFactories ¶
type ComponentFactories struct { // ResourceManager creates a ResourceManager ResourceManager func(client k8.ResourceClient, defClient xp.DefinitionClient, logger logging.Logger) ResourceManager // SchemaValidator creates a SchemaValidator SchemaValidator func(schema k8.SchemaClient, def xp.DefinitionClient, logger logging.Logger) SchemaValidator // DiffCalculator creates a DiffCalculator DiffCalculator func(apply k8.ApplyClient, tree xp.ResourceTreeClient, resourceManager ResourceManager, logger logging.Logger, diffOptions renderer.DiffOptions) DiffCalculator // DiffRenderer creates a DiffRenderer DiffRenderer func(logger logging.Logger, diffOptions renderer.DiffOptions) renderer.DiffRenderer // RequirementsProvider creates an ExtraResourceProvider RequirementsProvider func(res k8.ResourceClient, def xp.EnvironmentClient, renderFunc RenderFunc, logger logging.Logger) *RequirementsProvider }
ComponentFactories contains factory functions for creating processor components.
type DefaultCompDiffProcessor ¶
type DefaultCompDiffProcessor struct {
// contains filtered or unexported fields
}
DefaultCompDiffProcessor implements CompDiffProcessor.
func (*DefaultCompDiffProcessor) DiffComposition ¶
func (p *DefaultCompDiffProcessor) DiffComposition(ctx context.Context, stdout io.Writer, compositions []*un.Unstructured, namespace string) error
DiffComposition processes composition changes and shows impact on existing XRs.
func (*DefaultCompDiffProcessor) Initialize ¶
func (p *DefaultCompDiffProcessor) Initialize(ctx context.Context) error
Initialize loads required resources.
type DefaultDiffCalculator ¶
type DefaultDiffCalculator struct {
// contains filtered or unexported fields
}
DefaultDiffCalculator implements the DiffCalculator interface.
func (*DefaultDiffCalculator) CalculateDiff ¶
func (c *DefaultDiffCalculator) CalculateDiff(ctx context.Context, composite *un.Unstructured, desired *un.Unstructured) (*dt.ResourceDiff, error)
CalculateDiff calculates the diff for a single resource.
func (*DefaultDiffCalculator) CalculateDiffs ¶
func (c *DefaultDiffCalculator) CalculateDiffs(ctx context.Context, xr *cmp.Unstructured, desired render.Outputs) (map[string]*dt.ResourceDiff, error)
CalculateDiffs collects all diffs for the desired resources and identifies resources to be removed.
func (*DefaultDiffCalculator) CalculateRemovedResourceDiffs ¶
func (c *DefaultDiffCalculator) CalculateRemovedResourceDiffs(ctx context.Context, xr *un.Unstructured, renderedResources map[string]bool) (map[string]*dt.ResourceDiff, error)
CalculateRemovedResourceDiffs identifies resources that would be removed and calculates their diffs.
func (*DefaultDiffCalculator) SetDiffOptions ¶
func (c *DefaultDiffCalculator) SetDiffOptions(options renderer.DiffOptions)
SetDiffOptions updates the diff options used by the calculator.
type DefaultDiffProcessor ¶
type DefaultDiffProcessor struct {
// contains filtered or unexported fields
}
DefaultDiffProcessor implements DiffProcessor with modular components.
func (*DefaultDiffProcessor) DiffSingleResource ¶
func (p *DefaultDiffProcessor) DiffSingleResource(ctx context.Context, res *un.Unstructured, compositionProvider types.CompositionProvider) (map[string]*dt.ResourceDiff, error)
DiffSingleResource handles one resource at a time and returns its diffs. The compositionProvider function is called to obtain the composition to use for rendering.
func (*DefaultDiffProcessor) Initialize ¶
func (p *DefaultDiffProcessor) Initialize(ctx context.Context) error
Initialize loads required resources like CRDs and environment configs.
func (*DefaultDiffProcessor) PerformDiff ¶
func (p *DefaultDiffProcessor) PerformDiff(ctx context.Context, stdout io.Writer, resources []*un.Unstructured, compositionProvider types.CompositionProvider) error
PerformDiff processes resources using a composition provider function.
func (*DefaultDiffProcessor) RenderWithRequirements ¶
func (p *DefaultDiffProcessor) RenderWithRequirements( ctx context.Context, xr *cmp.Unstructured, comp *apiextensionsv1.Composition, fns []pkgv1.Function, resourceID string, ) (render.Outputs, error)
RenderWithRequirements performs an iterative rendering process that discovers and fulfills requirements.
func (*DefaultDiffProcessor) SanitizeXR ¶
func (p *DefaultDiffProcessor) SanitizeXR(res *un.Unstructured, resourceID string) (*cmp.Unstructured, bool, error)
SanitizeXR makes an XR into a valid unstructured object that we can use in a dry-run apply.
type DefaultResourceManager ¶
type DefaultResourceManager struct {
// contains filtered or unexported fields
}
DefaultResourceManager implements ResourceManager interface.
func (*DefaultResourceManager) FetchCurrentObject ¶
func (m *DefaultResourceManager) FetchCurrentObject(ctx context.Context, composite *un.Unstructured, desired *un.Unstructured) (*un.Unstructured, bool, error)
FetchCurrentObject retrieves the current state of the object from the cluster It returns the current object, a boolean indicating if it's a new object, and any error.
func (*DefaultResourceManager) UpdateOwnerRefs ¶
func (m *DefaultResourceManager) UpdateOwnerRefs(ctx context.Context, parent *un.Unstructured, child *un.Unstructured)
UpdateOwnerRefs ensures all OwnerReferences have valid UIDs. It handles Claims and XRs differently according to Crossplane's ownership model: - Claims should never be controller owners of composed resources. - XRs should be controller owners and use their UID for matching references.
type DefaultSchemaValidator ¶
type DefaultSchemaValidator struct {
// contains filtered or unexported fields
}
DefaultSchemaValidator implements SchemaValidator interface.
func (*DefaultSchemaValidator) EnsureComposedResourceCRDs ¶
func (v *DefaultSchemaValidator) EnsureComposedResourceCRDs(ctx context.Context, resources []*un.Unstructured) error
EnsureComposedResourceCRDs checks if we have all the CRDs needed for the cpd resources and fetches any missing ones from the cluster.
func (*DefaultSchemaValidator) GetCRDs ¶
func (v *DefaultSchemaValidator) GetCRDs() []*extv1.CustomResourceDefinition
GetCRDs returns the current CRDs.
func (*DefaultSchemaValidator) LoadCRDs ¶
func (v *DefaultSchemaValidator) LoadCRDs(ctx context.Context) error
LoadCRDs loads CRDs from the cluster.
func (*DefaultSchemaValidator) ValidateResources ¶
func (v *DefaultSchemaValidator) ValidateResources(ctx context.Context, xr *un.Unstructured, composed []cpd.Unstructured) error
ValidateResources validates resources using schema validation.
func (*DefaultSchemaValidator) ValidateScopeConstraints ¶
func (v *DefaultSchemaValidator) ValidateScopeConstraints(ctx context.Context, resource *un.Unstructured, expectedNamespace string, isClaimRoot bool) error
ValidateScopeConstraints validates that a resource has the appropriate namespace for its scope and that namespaced resources match the expected namespace (no cross-namespace refs).
type DiffCalculator ¶
type DiffCalculator interface { // CalculateDiff computes the diff for a single resource CalculateDiff(ctx context.Context, composite *un.Unstructured, desired *un.Unstructured) (*dt.ResourceDiff, error) // CalculateDiffs computes all diffs for the rendered resources and identifies resources to be removed CalculateDiffs(ctx context.Context, xr *cmp.Unstructured, desired render.Outputs) (map[string]*dt.ResourceDiff, error) // CalculateRemovedResourceDiffs identifies resources that would be removed and calculates their diffs CalculateRemovedResourceDiffs(ctx context.Context, xr *un.Unstructured, renderedResources map[string]bool) (map[string]*dt.ResourceDiff, error) }
DiffCalculator calculates differences between resources.
func NewDiffCalculator ¶
func NewDiffCalculator(apply k8.ApplyClient, tree xp.ResourceTreeClient, resourceManager ResourceManager, logger logging.Logger, diffOptions renderer.DiffOptions) DiffCalculator
NewDiffCalculator creates a new DefaultDiffCalculator.
type DiffProcessor ¶
type DiffProcessor interface { // PerformDiff processes resources using a composition provider function PerformDiff(ctx context.Context, stdout io.Writer, resources []*un.Unstructured, compositionProvider types.CompositionProvider) error // Initialize loads required resources like CRDs and environment configs Initialize(ctx context.Context) error }
DiffProcessor interface for processing resources.
func NewDiffProcessor ¶
func NewDiffProcessor(k8cs k8.Clients, xpcs xp.Clients, opts ...ProcessorOption) DiffProcessor
NewDiffProcessor creates a new DefaultDiffProcessor with the provided options.
type ProcessorConfig ¶
type ProcessorConfig struct { // Namespace is the namespace to use for resources Namespace string // Colorize determines whether to use colors in the diff output Colorize bool // Compact determines whether to show a compact diff format Compact bool // Logger is the logger to use Logger logging.Logger // RenderFunc is the function to use for rendering resources RenderFunc RenderFunc // Factories provide factory functions for creating components Factories ComponentFactories }
ProcessorConfig contains configuration for the DiffProcessor.
func (*ProcessorConfig) GetDiffOptions ¶
func (c *ProcessorConfig) GetDiffOptions() renderer.DiffOptions
GetDiffOptions returns DiffOptions based on the ProcessorConfig.
func (*ProcessorConfig) SetDefaultFactories ¶
func (c *ProcessorConfig) SetDefaultFactories()
SetDefaultFactories sets default component factory functions if not already set.
type ProcessorOption ¶
type ProcessorOption func(*ProcessorConfig)
ProcessorOption defines a function that can modify a ProcessorConfig.
func WithColorize ¶
func WithColorize(colorize bool) ProcessorOption
WithColorize sets whether to use colors in diff output.
func WithCompact ¶
func WithCompact(compact bool) ProcessorOption
WithCompact sets whether to use compact diff format.
func WithDiffCalculatorFactory ¶
func WithDiffCalculatorFactory(factory func(k8.ApplyClient, xp.ResourceTreeClient, ResourceManager, logging.Logger, renderer.DiffOptions) DiffCalculator) ProcessorOption
WithDiffCalculatorFactory sets the DiffCalculator factory function.
func WithDiffRendererFactory ¶
func WithDiffRendererFactory(factory func(logging.Logger, renderer.DiffOptions) renderer.DiffRenderer) ProcessorOption
WithDiffRendererFactory sets the DiffRenderer factory function.
func WithLogger ¶
func WithLogger(logger logging.Logger) ProcessorOption
WithLogger sets the logger for the processor.
func WithNamespace ¶
func WithNamespace(namespace string) ProcessorOption
WithNamespace sets the namespace for the processor.
func WithRenderFunc ¶
func WithRenderFunc(renderFn RenderFunc) ProcessorOption
WithRenderFunc sets the render function for the processor.
func WithRequirementsProviderFactory ¶
func WithRequirementsProviderFactory(factory func(k8.ResourceClient, xp.EnvironmentClient, RenderFunc, logging.Logger) *RequirementsProvider) ProcessorOption
WithRequirementsProviderFactory sets the RequirementsProvider factory function.
func WithResourceManagerFactory ¶
func WithResourceManagerFactory(factory func(k8.ResourceClient, xp.DefinitionClient, logging.Logger) ResourceManager) ProcessorOption
WithResourceManagerFactory sets the ResourceManager factory function.
func WithSchemaValidatorFactory ¶
func WithSchemaValidatorFactory(factory func(k8.SchemaClient, xp.DefinitionClient, logging.Logger) SchemaValidator) ProcessorOption
WithSchemaValidatorFactory sets the SchemaValidator factory function.
type RenderFunc ¶
type RenderFunc func(ctx context.Context, log logging.Logger, in render.Inputs) (render.Outputs, error)
RenderFunc defines the signature of a function that can render resources.
type RequirementsProvider ¶
type RequirementsProvider struct {
// contains filtered or unexported fields
}
RequirementsProvider consolidates requirement processing with caching.
func NewRequirementsProvider ¶
func NewRequirementsProvider(res k8.ResourceClient, env xp.EnvironmentClient, renderFn RenderFunc, logger logging.Logger) *RequirementsProvider
NewRequirementsProvider creates a new provider with caching.
func (*RequirementsProvider) ClearCache ¶
func (p *RequirementsProvider) ClearCache()
ClearCache clears all cached resources.
func (*RequirementsProvider) Initialize ¶
func (p *RequirementsProvider) Initialize(ctx context.Context) error
Initialize pre-fetches resources like environment configs.
func (*RequirementsProvider) ProvideRequirements ¶
func (p *RequirementsProvider) ProvideRequirements(ctx context.Context, requirements map[string]v1.Requirements, xrNamespace string) ([]*un.Unstructured, error)
ProvideRequirements provides requirements, checking cache first.
type ResourceManager ¶
type ResourceManager interface { // FetchCurrentObject retrieves the current state of an object from the cluster FetchCurrentObject(ctx context.Context, composite *un.Unstructured, desired *un.Unstructured) (*un.Unstructured, bool, error) // UpdateOwnerRefs ensures all OwnerReferences have valid UIDs UpdateOwnerRefs(ctx context.Context, parent *un.Unstructured, child *un.Unstructured) }
ResourceManager handles resource-related operations like fetching, updating owner refs, and identifying resources to be removed.
func NewResourceManager ¶
func NewResourceManager(client k8.ResourceClient, defClient xp.DefinitionClient, logger logging.Logger) ResourceManager
NewResourceManager creates a new DefaultResourceManager.
type SchemaValidator ¶
type SchemaValidator interface { // ValidateResources validates resources using schema validation ValidateResources(ctx context.Context, xr *un.Unstructured, composed []cpd.Unstructured) error // EnsureComposedResourceCRDs ensures we have all required CRDs for validation EnsureComposedResourceCRDs(ctx context.Context, resources []*un.Unstructured) error // ValidateScopeConstraints validates that a resource has the appropriate namespace for its scope // and that namespaced resources match the expected namespace (no cross-namespace refs) ValidateScopeConstraints(ctx context.Context, resource *un.Unstructured, expectedNamespace string, isClaimRoot bool) error }
SchemaValidator handles validation of resources against CRD schemas.
func NewSchemaValidator ¶
func NewSchemaValidator(sClient k8.SchemaClient, dClient xp.DefinitionClient, logger logging.Logger) SchemaValidator
NewSchemaValidator creates a new DefaultSchemaValidator.