Skip to content

Commit 16e467f

Browse files
stephenfindulek
authored andcommitted
api: Add ServerGroupFilter
Allow users to request Server Groups by either name or ID. This aligns us with the pattern of filters used for other resources such as Security Groups and Ports. Additionally `ReferencedResources` field is added to `BastionStatus` and `OpenStackMachineStatus` as a container to hold all the IDs of resources computed by the controllers. `ServerGroupID` is the first field added there. Signed-off-by: Stephen Finucane <[email protected]>
1 parent a1b9e4e commit 16e467f

23 files changed

+750
-145
lines changed

api/v1alpha5/conversion.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,18 @@ func Convert_v1alpha8_PortOpts_To_v1alpha5_PortOpts(in *infrav1.PortOpts, out *P
213213
}
214214

215215
func Convert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s conversion.Scope) error {
216-
return autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
216+
err := autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
217+
if err != nil {
218+
return err
219+
}
220+
221+
if in.ServerGroupID != "" {
222+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
223+
} else {
224+
out.ServerGroup = &infrav1.ServerGroupFilter{}
225+
}
226+
227+
return nil
217228
}
218229

219230
func Convert_v1alpha8_APIServerLoadBalancer_To_v1alpha5_APIServerLoadBalancer(in *infrav1.APIServerLoadBalancer, out *APIServerLoadBalancer, s conversion.Scope) error {
@@ -246,6 +257,7 @@ func Convert_v1alpha5_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
246257
out.State = infrav1.InstanceState(in.State)
247258
out.IP = in.IP
248259
out.FloatingIP = in.FloatingIP
260+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
249261
return nil
250262
}
251263

@@ -257,6 +269,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha5_Instance(in *infrav1.BastionStat
257269
out.State = InstanceState(in.State)
258270
out.IP = in.IP
259271
out.FloatingIP = in.FloatingIP
272+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
260273
return nil
261274
}
262275

@@ -435,5 +448,19 @@ func Convert_v1alpha5_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
435448
}
436449

437450
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
438-
return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
451+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
452+
if err != nil {
453+
return err
454+
}
455+
456+
if in.ServerGroup != nil {
457+
out.ServerGroupID = in.ServerGroup.ID
458+
}
459+
460+
return nil
461+
}
462+
463+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error {
464+
// ReferencedResources have no equivalent in v1alpha5
465+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s)
439466
}

api/v1alpha5/conversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestConvertFrom(t *testing.T) {
7979
Spec: OpenStackMachineSpec{},
8080
ObjectMeta: metav1.ObjectMeta{
8181
Annotations: map[string]string{
82-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"},\"status\":{\"ready\":false}}",
82+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"},\"status\":{\"ready\":false,\"referencedResources\":{}}}",
8383
},
8484
},
8585
},

api/v1alpha5/zz_generated.conversion.go

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
362362
// Networks were previously created first, so need to come before ports
363363
out.Ports = append(ports, out.Ports...)
364364
}
365+
366+
if in.ServerGroupID != "" {
367+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
368+
} else {
369+
out.ServerGroup = &infrav1.ServerGroupFilter{}
370+
}
371+
365372
return nil
366373
}
367374

@@ -480,6 +487,7 @@ func Convert_v1alpha6_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
480487
out.State = infrav1.InstanceState(in.State)
481488
out.IP = in.IP
482489
out.FloatingIP = in.FloatingIP
490+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
483491
return nil
484492
}
485493

@@ -491,6 +499,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStat
491499
out.State = InstanceState(in.State)
492500
out.IP = in.IP
493501
out.FloatingIP = in.FloatingIP
502+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
494503
return nil
495504
}
496505

@@ -657,5 +666,47 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
657666
}
658667

659668
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
660-
return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
669+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
670+
if err != nil {
671+
return err
672+
}
673+
674+
if in.ServerGroup != nil {
675+
out.ServerGroupID = in.ServerGroup.ID
676+
}
677+
678+
return nil
679+
}
680+
681+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
682+
// ReferencedResources have no equivalent in v1alpha6
683+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in, out, s)
684+
}
685+
686+
func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error {
687+
err := autoConvert_v1alpha6_Bastion_To_v1alpha8_Bastion(in, out, s)
688+
if err != nil {
689+
return err
690+
}
691+
692+
if in.Instance.ServerGroupID != "" {
693+
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID}
694+
} else {
695+
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{}
696+
}
697+
698+
return nil
699+
}
700+
701+
func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bastion, s apiconversion.Scope) error {
702+
err := autoConvert_v1alpha8_Bastion_To_v1alpha6_Bastion(in, out, s)
703+
if err != nil {
704+
return err
705+
}
706+
707+
if in.Instance.ServerGroup != nil && in.Instance.ServerGroup.ID != "" {
708+
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
709+
}
710+
711+
return nil
661712
}

api/v1alpha6/conversion_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ 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+
},
91114
}
92115
}
93116

@@ -112,42 +135,51 @@ func TestFuzzyConversion(t *testing.T) {
112135
Hub: &infrav1.OpenStackClusterTemplate{},
113136
Spoke: &OpenStackClusterTemplate{},
114137
HubAfterMutation: ignoreDataAnnotation,
138+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
115139
})))
116140

117141
t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
118142
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
119143
Hub: &infrav1.OpenStackClusterTemplate{},
120144
Spoke: &OpenStackClusterTemplate{},
121145
HubAfterMutation: ignoreDataAnnotation,
146+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
122147
},
148+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
123149
})))
124150

125151
t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
126152
Hub: &infrav1.OpenStackMachine{},
127153
Spoke: &OpenStackMachine{},
128154
HubAfterMutation: ignoreDataAnnotation,
155+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
129156
})))
130157

131158
t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
132159
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
133160
Hub: &infrav1.OpenStackMachine{},
134161
Spoke: &OpenStackMachine{},
135162
HubAfterMutation: ignoreDataAnnotation,
163+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
136164
},
165+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
137166
})))
138167

139168
t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
140169
Hub: &infrav1.OpenStackMachineTemplate{},
141170
Spoke: &OpenStackMachineTemplate{},
142171
HubAfterMutation: ignoreDataAnnotation,
172+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
143173
})))
144174

145175
t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
146176
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
147177
Hub: &infrav1.OpenStackMachineTemplate{},
148178
Spoke: &OpenStackMachineTemplate{},
149179
HubAfterMutation: ignoreDataAnnotation,
180+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
150181
},
182+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
151183
})))
152184
}
153185

@@ -181,6 +213,7 @@ func TestNetworksToPorts(t *testing.T) {
181213
},
182214
},
183215
},
216+
ServerGroup: &infrav1.ServerGroupFilter{},
184217
},
185218
},
186219
{
@@ -214,6 +247,7 @@ func TestNetworksToPorts(t *testing.T) {
214247
},
215248
},
216249
},
250+
ServerGroup: &infrav1.ServerGroupFilter{},
217251
},
218252
},
219253
{
@@ -245,6 +279,7 @@ func TestNetworksToPorts(t *testing.T) {
245279
},
246280
},
247281
},
282+
ServerGroup: &infrav1.ServerGroupFilter{},
248283
},
249284
},
250285
{
@@ -300,6 +335,7 @@ func TestNetworksToPorts(t *testing.T) {
300335
},
301336
},
302337
},
338+
ServerGroup: &infrav1.ServerGroupFilter{},
303339
},
304340
},
305341
{
@@ -370,6 +406,7 @@ func TestNetworksToPorts(t *testing.T) {
370406
},
371407
},
372408
},
409+
ServerGroup: &infrav1.ServerGroupFilter{},
373410
},
374411
},
375412
}
@@ -472,7 +509,8 @@ func TestPortOptsConvertTo(t *testing.T) {
472509
Spec: infrav1.OpenStackMachineTemplateSpec{
473510
Template: infrav1.OpenStackMachineTemplateResource{
474511
Spec: infrav1.OpenStackMachineSpec{
475-
Ports: tt.hubPortOpts,
512+
Ports: tt.hubPortOpts,
513+
ServerGroup: &infrav1.ServerGroupFilter{},
476514
},
477515
},
478516
},

0 commit comments

Comments
 (0)