|
| 1 | +// Package resolver provides the central logic for calculating the "Effective Specification" of a MultigresCluster. |
| 2 | +// |
| 3 | +// In the Multigres Operator, a cluster's configuration can come from multiple sources: |
| 4 | +// 1. Inline Configurations (defined directly in the MultigresCluster CR). |
| 5 | +// 2. Template References (pointing to CoreTemplate, CellTemplate, or ShardTemplate CRs). |
| 6 | +// 3. Overrides (partial patches applied on top of a template). |
| 7 | +// 4. Hardcoded Defaults (fallback values for safety). |
| 8 | +// |
| 9 | +// The Resolver is the single source of truth for merging these sources. It ensures that |
| 10 | +// the Reconciler and the Webhook always agree on what the final configuration should be. |
| 11 | +// |
| 12 | +// # Logic Hierarchy |
| 13 | +// |
| 14 | +// When calculating the final configuration for a component, the Resolver applies the |
| 15 | +// following precedence (highest to lowest): |
| 16 | +// |
| 17 | +// 1. Inline Spec (if provided, it ignores templates entirely). |
| 18 | +// 2. Overrides (patches specific fields of the template). |
| 19 | +// 3. Template Spec (the base configuration from the referenced CR). |
| 20 | +// 4. Global Defaults (hardcoded constants like default images or replicas). |
| 21 | +// |
| 22 | +// # Dual Usage |
| 23 | +// |
| 24 | +// This package is designed to be used in two distinct phases: |
| 25 | +// |
| 26 | +// 1. Mutation (Webhook): |
| 27 | +// The 'PopulateClusterDefaults' method is safe to call during admission. It applies |
| 28 | +// static defaults (images, explicit template names) to the API object itself, |
| 29 | +// solving the "Invisible Defaults" problem without making external API calls. |
| 30 | +// |
| 31 | +// 2. Reconciliation (Controller): |
| 32 | +// The 'Resolve...' and 'Merge...' methods are used during reconciliation. They |
| 33 | +// fetch external templates from the API server and merge them to determine the |
| 34 | +// actual state the child resources (StatefulSets, Services) should match. |
| 35 | +// |
| 36 | +// Usage: |
| 37 | +// |
| 38 | +// // Create a resolver |
| 39 | +// res := resolver.NewResolver(client, namespace, cluster.Spec.TemplateDefaults) |
| 40 | +// |
| 41 | +// // Webhook: Apply static defaults to the object |
| 42 | +// res.PopulateClusterDefaults(cluster) |
| 43 | +// |
| 44 | +// // Controller: Calculate final config for a specific component |
| 45 | +// template, err := res.ResolveShardTemplate(ctx, "my-shard-template") |
| 46 | +// finalConfig := resolver.MergeShardConfig(template, overrides, nil) |
| 47 | +package resolver |
0 commit comments