Skip to content

Commit 7e0ee45

Browse files
committed
fix conversion to address new signature in UnconditionalFieldRestorer
1 parent f8a1d17 commit 7e0ee45

File tree

3 files changed

+72
-47
lines changed

3 files changed

+72
-47
lines changed

api/v1alpha6/conversion.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *inf
6161
// We restore the whole Ports since they are anyway immutable.
6262
dst.Ports = previous.Ports
6363
dst.AdditionalBlockDevices = previous.AdditionalBlockDevices
64+
dst.ServerGroup = previous.ServerGroup
65+
}
66+
67+
func restorev1alpha8MachineStatus(previous *infrav1.OpenStackMachineStatus, dst *infrav1.OpenStackMachineStatus) {
68+
dst.ReferencedResources = previous.ReferencedResources
6469
}
6570

6671
func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
@@ -257,6 +262,12 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
257262
},
258263
restorev1alpha8MachineSpec,
259264
),
265+
"status": conversion.HashedFieldRestorer(
266+
func(c *infrav1.OpenStackMachine) *infrav1.OpenStackMachineStatus {
267+
return &c.Status
268+
},
269+
restorev1alpha8MachineStatus,
270+
),
260271
}
261272

262273
func (r *OpenStackMachine) ConvertTo(dstRaw ctrlconversion.Hub) error {
@@ -358,7 +369,7 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
358369
if in.ServerGroupID != "" {
359370
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
360371
} else {
361-
out.ServerGroup = &infrav1.ServerGroupFilter{}
372+
out.ServerGroup = nil
362373
}
363374

364375
return nil
@@ -684,7 +695,7 @@ func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
684695
if in.Instance.ServerGroupID != "" {
685696
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID}
686697
} else {
687-
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{}
698+
out.Instance.ServerGroup = nil
688699
}
689700

690701
return nil

api/v1alpha6/conversion_test.go

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,6 @@ func TestFuzzyConversion(t *testing.T) {
8888
status.ExternalNetwork.APIServerLoadBalancer = nil
8989
}
9090
},
91-
92-
func(v1alpha8OpenStackMachine *infrav1.OpenStackMachine, c fuzz.Continue) {
93-
c.FuzzNoCustom(v1alpha8OpenStackMachine)
94-
95-
// None of the following fields have ever been set in v1alpha6
96-
v1alpha8OpenStackMachine.Status.ReferencedResources = infrav1.ReferencedMachineResources{}
97-
},
98-
99-
func(v1alpha8OpenStackCluster *infrav1.OpenStackCluster, c fuzz.Continue) {
100-
c.FuzzNoCustom(v1alpha8OpenStackCluster)
101-
102-
// None of the following fields have ever been set in v1alpha6
103-
if v1alpha8OpenStackCluster.Status.Bastion != nil {
104-
v1alpha8OpenStackCluster.Status.Bastion.ReferencedResources = infrav1.ReferencedMachineResources{}
105-
}
106-
},
107-
108-
func(v1alpha8ServerGroupFilter *infrav1.ServerGroupFilter, c fuzz.Continue) {
109-
c.FuzzNoCustom(v1alpha8ServerGroupFilter)
110-
111-
// None of the following fields have ever been set in v1alpha6
112-
v1alpha8ServerGroupFilter.Name = ""
113-
},
11491
}
11592
}
11693

@@ -135,51 +112,42 @@ func TestFuzzyConversion(t *testing.T) {
135112
Hub: &infrav1.OpenStackClusterTemplate{},
136113
Spoke: &OpenStackClusterTemplate{},
137114
HubAfterMutation: ignoreDataAnnotation,
138-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
139115
})))
140116

141117
t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
142118
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
143119
Hub: &infrav1.OpenStackClusterTemplate{},
144120
Spoke: &OpenStackClusterTemplate{},
145121
HubAfterMutation: ignoreDataAnnotation,
146-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
147122
},
148-
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
149123
})))
150124

151125
t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
152126
Hub: &infrav1.OpenStackMachine{},
153127
Spoke: &OpenStackMachine{},
154128
HubAfterMutation: ignoreDataAnnotation,
155-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
156129
})))
157130

158131
t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
159132
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
160133
Hub: &infrav1.OpenStackMachine{},
161134
Spoke: &OpenStackMachine{},
162135
HubAfterMutation: ignoreDataAnnotation,
163-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
164136
},
165-
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
166137
})))
167138

168139
t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
169140
Hub: &infrav1.OpenStackMachineTemplate{},
170141
Spoke: &OpenStackMachineTemplate{},
171142
HubAfterMutation: ignoreDataAnnotation,
172-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
173143
})))
174144

175145
t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
176146
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
177147
Hub: &infrav1.OpenStackMachineTemplate{},
178148
Spoke: &OpenStackMachineTemplate{},
179149
HubAfterMutation: ignoreDataAnnotation,
180-
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
181150
},
182-
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
183151
})))
184152
}
185153

@@ -213,7 +181,6 @@ func TestNetworksToPorts(t *testing.T) {
213181
},
214182
},
215183
},
216-
ServerGroup: &infrav1.ServerGroupFilter{},
217184
},
218185
},
219186
{
@@ -247,7 +214,6 @@ func TestNetworksToPorts(t *testing.T) {
247214
},
248215
},
249216
},
250-
ServerGroup: &infrav1.ServerGroupFilter{},
251217
},
252218
},
253219
{
@@ -279,7 +245,6 @@ func TestNetworksToPorts(t *testing.T) {
279245
},
280246
},
281247
},
282-
ServerGroup: &infrav1.ServerGroupFilter{},
283248
},
284249
},
285250
{
@@ -335,7 +300,6 @@ func TestNetworksToPorts(t *testing.T) {
335300
},
336301
},
337302
},
338-
ServerGroup: &infrav1.ServerGroupFilter{},
339303
},
340304
},
341305
{
@@ -406,7 +370,6 @@ func TestNetworksToPorts(t *testing.T) {
406370
},
407371
},
408372
},
409-
ServerGroup: &infrav1.ServerGroupFilter{},
410373
},
411374
},
412375
}
@@ -509,8 +472,7 @@ func TestPortOptsConvertTo(t *testing.T) {
509472
Spec: infrav1.OpenStackMachineTemplateSpec{
510473
Template: infrav1.OpenStackMachineTemplateResource{
511474
Spec: infrav1.OpenStackMachineSpec{
512-
Ports: tt.hubPortOpts,
513-
ServerGroup: &infrav1.ServerGroupFilter{},
475+
Ports: tt.hubPortOpts,
514476
},
515477
},
516478
},

api/v1alpha7/conversion.go

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,38 @@ var _ ctrlconversion.Convertible = &OpenStackCluster{}
2828

2929
var v1alpha7OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]{}
3030

31-
var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{}
31+
var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{
32+
"bastion": conversion.HashedFieldRestorer(
33+
func(c *infrav1.OpenStackCluster) **infrav1.Bastion {
34+
return &c.Spec.Bastion
35+
},
36+
restorev1alpha8Bastion,
37+
),
38+
"spec": conversion.HashedFieldRestorer(
39+
func(c *infrav1.OpenStackCluster) *infrav1.OpenStackClusterSpec {
40+
return &c.Spec
41+
},
42+
restorev1alpha8ClusterSpec,
43+
),
44+
}
45+
46+
func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
47+
dst.ServerGroup = previous.ServerGroup
48+
}
49+
50+
func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
51+
if *previous != nil && *dst != nil {
52+
restorev1alpha8MachineSpec(&(*previous).Instance, &(*dst).Instance)
53+
}
54+
}
55+
56+
func restorev1alpha8ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infrav1.OpenStackClusterSpec) {
57+
prevBastion := previous.Bastion
58+
dstBastion := dst.Bastion
59+
if prevBastion != nil && dstBastion != nil {
60+
restorev1alpha8MachineSpec(&prevBastion.Instance, &dstBastion.Instance)
61+
}
62+
}
3263

3364
func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
3465
dst := dstRaw.(*infrav1.OpenStackCluster)
@@ -68,7 +99,14 @@ var _ ctrlconversion.Convertible = &OpenStackClusterTemplate{}
6899

69100
var v1alpha7OpenStackClusterTemplateRestorer = conversion.RestorerFor[*OpenStackClusterTemplate]{}
70101

71-
var v1alpha8OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackClusterTemplate]{}
102+
var v1alpha8OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackClusterTemplate]{
103+
"bastion": conversion.HashedFieldRestorer(
104+
func(c *infrav1.OpenStackClusterTemplate) **infrav1.Bastion {
105+
return &c.Spec.Template.Spec.Bastion
106+
},
107+
restorev1alpha8Bastion,
108+
),
109+
}
72110

73111
func (r *OpenStackClusterTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
74112
dst := dstRaw.(*infrav1.OpenStackClusterTemplate)
@@ -94,7 +132,14 @@ var _ ctrlconversion.Convertible = &OpenStackMachine{}
94132

95133
var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine]{}
96134

97-
var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{}
135+
var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{
136+
"spec": conversion.HashedFieldRestorer(
137+
func(c *infrav1.OpenStackMachine) *infrav1.OpenStackMachineSpec {
138+
return &c.Spec
139+
},
140+
restorev1alpha8MachineSpec,
141+
),
142+
}
98143

99144
func (r *OpenStackMachine) ConvertTo(dstRaw ctrlconversion.Hub) error {
100145
dst := dstRaw.(*infrav1.OpenStackMachine)
@@ -132,7 +177,14 @@ var _ ctrlconversion.Convertible = &OpenStackMachineTemplate{}
132177

133178
var v1alpha7OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStackMachineTemplate]{}
134179

135-
var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackMachineTemplate]{}
180+
var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackMachineTemplate]{
181+
"spec": conversion.HashedFieldRestorer(
182+
func(c *infrav1.OpenStackMachineTemplate) *infrav1.OpenStackMachineSpec {
183+
return &c.Spec.Template.Spec
184+
},
185+
restorev1alpha8MachineSpec,
186+
),
187+
}
136188

137189
func (r *OpenStackMachineTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
138190
dst := dstRaw.(*infrav1.OpenStackMachineTemplate)
@@ -188,7 +240,7 @@ func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
188240
if in.ServerGroupID != "" {
189241
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
190242
} else {
191-
out.ServerGroup = &infrav1.ServerGroupFilter{}
243+
out.ServerGroup = nil
192244
}
193245

194246
return nil
@@ -213,7 +265,7 @@ func Convert_v1alpha7_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
213265
if in.Instance.ServerGroupID != "" {
214266
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID}
215267
} else {
216-
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{}
268+
out.Instance.ServerGroup = nil
217269
}
218270

219271
return nil

0 commit comments

Comments
 (0)