Skip to content

Commit 792bcbc

Browse files
refactor(cluster-handler): update controller to use pointer-based resolver API
The `resolver` package was recently refactored to return pointers for large specification structs (like `StatelessSpec`) instead of returning them by value. This improvement avoids unnecessary copying of data structures and aligns with standard Kubernetes operator patterns. This commit updates the `MultigresCluster` controller to consume this new API signature: - Updated `reconcileCells` to handle the pointer return values from `MergeCellConfig`. - Added necessary dereferencing when assigning the Gateway spec to the Cell CR, ensuring the configuration is correctly applied to the child resources.
1 parent a166eb6 commit 792bcbc

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (r *MultigresClusterReconciler) reconcileCells(
305305
cellCR.Spec.Zone = cellCfg.Zone
306306
cellCR.Spec.Region = cellCfg.Region
307307
cellCR.Spec.MultiGatewayImage = cluster.Spec.Images.MultiGateway
308-
cellCR.Spec.MultiGateway = gatewaySpec
308+
cellCR.Spec.MultiGateway = *gatewaySpec
309309
cellCR.Spec.AllCells = allCellNames
310310

311311
cellCR.Spec.GlobalTopoServer = globalTopoRef

pkg/resolver/cell.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func MergeCellConfig(
4545
template *multigresv1alpha1.CellTemplate,
4646
overrides *multigresv1alpha1.CellOverrides,
4747
inline *multigresv1alpha1.CellInlineSpec,
48-
) (multigresv1alpha1.StatelessSpec, *multigresv1alpha1.LocalTopoServerSpec) {
49-
var gateway multigresv1alpha1.StatelessSpec
48+
) (*multigresv1alpha1.StatelessSpec, *multigresv1alpha1.LocalTopoServerSpec) {
49+
gateway := &multigresv1alpha1.StatelessSpec{}
5050
var localTopo *multigresv1alpha1.LocalTopoServerSpec
5151

5252
if template != nil {
5353
if template.Spec.MultiGateway != nil {
54-
gateway = *template.Spec.MultiGateway.DeepCopy()
54+
gateway = template.Spec.MultiGateway.DeepCopy()
5555
}
5656
if template.Spec.LocalTopoServer != nil {
5757
localTopo = template.Spec.LocalTopoServer.DeepCopy()
@@ -60,12 +60,12 @@ func MergeCellConfig(
6060

6161
if overrides != nil {
6262
if overrides.MultiGateway != nil {
63-
mergeStatelessSpec(&gateway, overrides.MultiGateway)
63+
mergeStatelessSpec(gateway, overrides.MultiGateway)
6464
}
6565
}
6666

6767
if inline != nil {
68-
gw := *inline.MultiGateway.DeepCopy()
68+
gw := inline.MultiGateway.DeepCopy()
6969
var topo *multigresv1alpha1.LocalTopoServerSpec
7070
if inline.LocalTopoServer != nil {
7171
topo = inline.LocalTopoServer.DeepCopy()

pkg/resolver/cell_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestMergeCellConfig(t *testing.T) {
115115
tpl *multigresv1alpha1.CellTemplate
116116
overrides *multigresv1alpha1.CellOverrides
117117
inline *multigresv1alpha1.CellInlineSpec
118-
wantGw multigresv1alpha1.StatelessSpec
118+
wantGw *multigresv1alpha1.StatelessSpec
119119
wantTopo *multigresv1alpha1.LocalTopoServerSpec
120120
}{
121121
"Full Merge With Resources and Affinity Overrides": {
@@ -145,7 +145,7 @@ func TestMergeCellConfig(t *testing.T) {
145145
},
146146
},
147147
},
148-
wantGw: multigresv1alpha1.StatelessSpec{
148+
wantGw: &multigresv1alpha1.StatelessSpec{
149149
Replicas: ptr.To(int32(2)),
150150
PodAnnotations: map[string]string{"foo": "bar", "baz": "qux"},
151151
Resources: corev1.ResourceRequirements{
@@ -166,7 +166,7 @@ func TestMergeCellConfig(t *testing.T) {
166166
},
167167
},
168168
overrides: nil,
169-
wantGw: multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(1))},
169+
wantGw: &multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(1))},
170170
},
171171
"Preserve Base (Empty Override)": {
172172
tpl: &multigresv1alpha1.CellTemplate{
@@ -180,7 +180,7 @@ func TestMergeCellConfig(t *testing.T) {
180180
overrides: &multigresv1alpha1.CellOverrides{
181181
MultiGateway: &multigresv1alpha1.StatelessSpec{},
182182
},
183-
wantGw: multigresv1alpha1.StatelessSpec{
183+
wantGw: &multigresv1alpha1.StatelessSpec{
184184
Replicas: ptr.To(int32(1)),
185185
PodAnnotations: map[string]string{"foo": "bar"},
186186
},
@@ -197,7 +197,7 @@ func TestMergeCellConfig(t *testing.T) {
197197
PodLabels: map[string]string{"c": "d"},
198198
},
199199
},
200-
wantGw: multigresv1alpha1.StatelessSpec{
200+
wantGw: &multigresv1alpha1.StatelessSpec{
201201
Replicas: ptr.To(int32(1)),
202202
PodAnnotations: map[string]string{"a": "b"},
203203
PodLabels: map[string]string{"c": "d"},
@@ -215,7 +215,7 @@ func TestMergeCellConfig(t *testing.T) {
215215
Etcd: &multigresv1alpha1.EtcdSpec{Image: "inline-etcd"},
216216
},
217217
},
218-
wantGw: multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(99))},
218+
wantGw: &multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(99))},
219219
wantTopo: &multigresv1alpha1.LocalTopoServerSpec{
220220
Etcd: &multigresv1alpha1.EtcdSpec{Image: "inline-etcd"},
221221
},
@@ -225,11 +225,11 @@ func TestMergeCellConfig(t *testing.T) {
225225
overrides: &multigresv1alpha1.CellOverrides{
226226
MultiGateway: &multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(2))},
227227
},
228-
wantGw: multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(2))},
228+
wantGw: &multigresv1alpha1.StatelessSpec{Replicas: ptr.To(int32(2))},
229229
},
230230
"Nil Everything": {
231231
tpl: nil,
232-
wantGw: multigresv1alpha1.StatelessSpec{},
232+
wantGw: &multigresv1alpha1.StatelessSpec{},
233233
wantTopo: nil,
234234
},
235235
}

0 commit comments

Comments
 (0)