Skip to content

Commit 568d7e6

Browse files
refactor(cluster-handler): centralize defaulting constants for webhook preparation
This change extracts hardcoded default values (replica counts, template names) from the MultigresCluster controller logic into a dedicated `constants.go` file. Key changes: - Created `constants.go` to hold Level 4 defaults (e.g., DefaultEtcdReplicas=3). - Updated `template_logic.go` and `multigrescluster_controller.go` to use these constants. - Updated controller tests to assert against the constant rather than a magic number, ensuring tests remain robust if defaults change. - Added code comments explicitly noting that these files should eventually move to a shared `pkg/multigres/defaults` package to support the future Mutating Webhook without circular dependencies. This ensures that both the reconciliation loop and the future admission webhook will rely on a Single Source of Truth for defaulting logic.
1 parent 2cc5b10 commit 568d7e6

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package multigrescluster
2+
3+
// NOTE: We may want to consider moving this and template_logic.go to a different package at some point.
4+
// These can be used by
5+
6+
const (
7+
// DefaultEtcdReplicas is the default number of replicas for the managed Etcd cluster if not specified.
8+
DefaultEtcdReplicas int32 = 3
9+
10+
// DefaultAdminReplicas is the default number of replicas for the MultiAdmin deployment if not specified.
11+
DefaultAdminReplicas int32 = 1
12+
13+
// FallbackCoreTemplate is the name of the template to look for if no specific template is referenced.
14+
FallbackCoreTemplate = "default"
15+
16+
// FallbackCellTemplate is the name of the template to look for if no specific template is referenced.
17+
FallbackCellTemplate = "default"
18+
19+
// FallbackShardTemplate is the name of the template to look for if no specific template is referenced.
20+
FallbackShardTemplate = "default"
21+
)

pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (r *MultigresClusterReconciler) reconcileGlobalComponents(ctx context.Conte
163163
},
164164
}
165165
if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, ts, func() error {
166-
replicas := int32(3)
166+
replicas := DefaultEtcdReplicas
167167
if topoSpec.Etcd.Replicas != nil {
168168
replicas = *topoSpec.Etcd.Replicas
169169
}
@@ -190,7 +190,7 @@ func (r *MultigresClusterReconciler) reconcileGlobalComponents(ctx context.Conte
190190
},
191191
}
192192
if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, deploy, func() error {
193-
replicas := int32(1)
193+
replicas := DefaultAdminReplicas
194194
if multiAdminSpec.Replicas != nil {
195195
replicas = *multiAdminSpec.Replicas
196196
}

pkg/cluster-handler/controller/multigrescluster/template_logic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (r *TemplateResolver) ResolveCoreTemplate(ctx context.Context, templateName
3939
name = r.Defaults.CoreTemplate
4040
}
4141
if name == "" {
42-
name = "default"
42+
name = FallbackCoreTemplate
4343
isImplicitFallback = true
4444
}
4545

@@ -67,7 +67,7 @@ func (r *TemplateResolver) ResolveCellTemplate(ctx context.Context, templateName
6767
name = r.Defaults.CellTemplate
6868
}
6969
if name == "" {
70-
name = "default"
70+
name = FallbackCellTemplate
7171
isImplicitFallback = true
7272
}
7373

@@ -94,7 +94,7 @@ func (r *TemplateResolver) ResolveShardTemplate(ctx context.Context, templateNam
9494
name = r.Defaults.ShardTemplate
9595
}
9696
if name == "" {
97-
name = "default"
97+
name = FallbackShardTemplate
9898
isImplicitFallback = true
9999
}
100100

0 commit comments

Comments
 (0)