Documentation
¶
Overview ¶
Package reconciler provides catalog synchronization and reconciliation capabilities. It handles merging data from multiple sources, detecting changes, and applying updates while respecting data authorities and merge strategies.
Index ¶
- func ConvertCatalogsMapToSources(srcs map[sources.Type]catalogs.Catalog) []sources.Source
- func NewMockSource(sourceType sources.Type, catalog catalogs.Catalog) sources.Source
- type AuthorityStrategy
- func (s *AuthorityStrategy) ApplyStrategy() differ.ApplyStrategy
- func (s *AuthorityStrategy) Description() string
- func (s *AuthorityStrategy) ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)
- func (s *AuthorityStrategy) ShouldMerge(resourceType sources.ResourceType) bool
- func (s *AuthorityStrategy) Type() StrategyType
- func (s *AuthorityStrategy) ValidateResult(result *Result) error
- type Merger
- type Option
- type Reconciler
- type Result
- type ResultMetadata
- type ResultStatistics
- type SourceOrderStrategy
- func (s *SourceOrderStrategy) ApplyStrategy() differ.ApplyStrategy
- func (s *SourceOrderStrategy) Description() string
- func (s *SourceOrderStrategy) ResolveConflict(_ string, values map[sources.Type]any) (any, sources.Type, string)
- func (s *SourceOrderStrategy) ShouldMerge(resourceType sources.ResourceType) bool
- func (s *SourceOrderStrategy) Type() StrategyType
- func (s *SourceOrderStrategy) ValidateResult(result *Result) error
- type Strategy
- type StrategyType
- type ValidationError
- type ValidationResult
- type ValidationWarning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertCatalogsMapToSources ¶
ConvertCatalogsMapToSources converts the old map format to sources slice for testing.
Types ¶
type AuthorityStrategy ¶
type AuthorityStrategy struct {
// contains filtered or unexported fields
}
AuthorityStrategy uses field authorities to resolve conflicts.
func (*AuthorityStrategy) ApplyStrategy ¶
func (s *AuthorityStrategy) ApplyStrategy() differ.ApplyStrategy
ApplyStrategy returns how changes should be applied.
func (*AuthorityStrategy) Description ¶
func (s *AuthorityStrategy) Description() string
Description returns a human-readable description.
func (*AuthorityStrategy) ResolveConflict ¶
func (s *AuthorityStrategy) ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)
ResolveConflict uses authorities to resolve conflicts.
func (*AuthorityStrategy) ShouldMerge ¶
func (s *AuthorityStrategy) ShouldMerge(resourceType sources.ResourceType) bool
ShouldMerge determines if resources should be merged.
func (*AuthorityStrategy) Type ¶
func (s *AuthorityStrategy) Type() StrategyType
Type returns the strategy type.
func (*AuthorityStrategy) ValidateResult ¶
ValidateResult validates the reconciliation result.
type Merger ¶
type Merger interface {
// Models merges models from multiple sources
Models(sources map[sources.Type][]catalogs.Model) ([]catalogs.Model, provenance.Map, error)
// Providers merges providers from multiple sources
Providers(sources map[sources.Type][]catalogs.Provider) ([]catalogs.Provider, provenance.Map, error)
}
Merger performs the actual merging of resources.
type Option ¶
type Option func(*options) error
Option is a function that configures a Reconciler.
func WithAuthorities ¶
WithAuthorities sets the field authorities.
func WithBaseline ¶
WithBaseline sets an existing catalog to compare against for change detection.
func WithEnhancers ¶
WithEnhancers adds model enhancers to the pipeline.
func WithProvenance ¶
WithProvenance enables field-level tracking.
func WithStrategy ¶
WithStrategy sets the merge strategy.
type Reconciler ¶
type Reconciler interface {
// Sources reconciles multiple catalogs from different sources
// The primary source determines which models exist; other sources provide enrichment only
Sources(ctx context.Context, primary sources.Type, srcs []sources.Source) (*Result, error)
}
Reconciler is the main interface for reconciling data from multiple sources.
type Result ¶
type Result struct {
// Core data
Catalog catalogs.Catalog
Changeset *differ.Changeset
AppliedChanges *differ.Changeset
// Tracking maps
ProviderAPICounts map[catalogs.ProviderID]int
ModelProviderMap map[string]catalogs.ProviderID
// Metadata
Metadata ResultMetadata
// Provenance tracking
Provenance provenance.Map
// Issues
Errors []error
Warnings []string
}
Result represents the outcome of a reconciliation operation.
func (*Result) Finalize ¶
func (r *Result) Finalize()
Finalize calculates duration and marks completion.
func (*Result) HasChanges ¶
HasChanges returns true if any changes were detected.
func (*Result) WasApplied ¶
WasApplied returns true if changes were applied.
type ResultMetadata ¶
type ResultMetadata struct {
// StartTime when reconciliation started
StartTime time.Time
// EndTime when reconciliation completed
EndTime time.Time
// Duration of the reconciliation
Duration time.Duration
// Sources that were reconciled
Sources []sources.Type
// Strategy used for reconciliation
Strategy Strategy
// DryRun indicates if this was a dry-run
DryRun bool
// Statistics about the reconciliation
Stats ResultStatistics
}
ResultMetadata contains metadata about the reconciliation process.
type ResultStatistics ¶
type ResultStatistics struct {
ModelsProcessed int
ProvidersProcessed int
ConflictsResolved int
ResourcesSkipped int
TotalTimeMs int64
}
ResultStatistics contains statistics about the reconciliation.
type SourceOrderStrategy ¶
type SourceOrderStrategy struct {
// contains filtered or unexported fields
}
SourceOrderStrategy resolves conflicts using a fixed source precedence order. Sources earlier in the priority slice have higher precedence than sources later in the slice.
func (*SourceOrderStrategy) ApplyStrategy ¶
func (s *SourceOrderStrategy) ApplyStrategy() differ.ApplyStrategy
ApplyStrategy returns how changes should be applied.
func (*SourceOrderStrategy) Description ¶
func (s *SourceOrderStrategy) Description() string
Description returns a human-readable description.
func (*SourceOrderStrategy) ResolveConflict ¶
func (s *SourceOrderStrategy) ResolveConflict(_ string, values map[sources.Type]any) (any, sources.Type, string)
ResolveConflict uses source priority order to resolve conflicts.
func (*SourceOrderStrategy) ShouldMerge ¶
func (s *SourceOrderStrategy) ShouldMerge(resourceType sources.ResourceType) bool
ShouldMerge determines if resources should be merged.
func (*SourceOrderStrategy) Type ¶
func (s *SourceOrderStrategy) Type() StrategyType
Type returns the strategy type.
func (*SourceOrderStrategy) ValidateResult ¶
ValidateResult validates the reconciliation result.
type Strategy ¶
type Strategy interface {
// Type returns the strategy type
Type() StrategyType
// Description returns a human-readable description
Description() string
// ShouldMerge determines if resources should be merged
ShouldMerge(resourceType sources.ResourceType) bool
// ResolveConflict determines how to resolve conflicts
ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)
// ValidateResult validates the reconciliation result
ValidateResult(result *Result) error
// ApplyStrategy returns how changes should be applied
ApplyStrategy() differ.ApplyStrategy
}
Strategy defines how reconciliation should be performed.
func NewAuthorityStrategy ¶
NewAuthorityStrategy creates a new authority-based strategy.
func NewSourceOrderStrategy ¶
NewSourceOrderStrategy creates a new source priority order strategy. The priorityOrder slice determines precedence: earlier elements have higher priority.
type StrategyType ¶
type StrategyType string
StrategyType represents the type of reconciliation strategy.
const ( // StrategyTypeFieldAuthority uses field-specific authority scores to resolve conflicts. StrategyTypeFieldAuthority StrategyType = "field-authority" // StrategyTypeSourceOrder uses source ordering to resolve conflicts. StrategyTypeSourceOrder StrategyType = "source-order" )
func (StrategyType) Name ¶
func (s StrategyType) Name() string
Name returns the name of the strategy type.
func (StrategyType) String ¶
func (s StrategyType) String() string
String returns the string representation of a strategy type.
type ValidationError ¶
type ValidationError struct {
ResourceType sources.ResourceType
ResourceID string
Field string
Message string
}
ValidationError represents a validation error.
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []ValidationError
Warnings []ValidationWarning
}
ValidationResult represents the result of validating a catalog or changeset.
func (*ValidationResult) HasWarnings ¶
func (v *ValidationResult) HasWarnings() bool
HasWarnings returns true if there are warnings.
func (*ValidationResult) IsValid ¶
func (v *ValidationResult) IsValid() bool
IsValid returns true if validation passed.
func (*ValidationResult) String ¶
func (v *ValidationResult) String() string
String returns a string representation of the validation result.
type ValidationWarning ¶
type ValidationWarning struct {
ResourceType sources.ResourceType
ResourceID string
Field string
Message string
}
ValidationWarning represents a validation warning.