Skip to content

Commit ffb5aa4

Browse files
stephenfinEmilienMdulek
committed
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. Co-Authored-By: Emilien Macchi <[email protected]> Co-Authored-By: Michał Dulko <[email protected]> Co-Authored-By: Stephen Finucane <[email protected]>
1 parent 7166330 commit ffb5aa4

26 files changed

+958
-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
@@ -354,6 +354,13 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
354354
// Networks were previously created first, so need to come before ports
355355
out.Ports = append(ports, out.Ports...)
356356
}
357+
358+
if in.ServerGroupID != "" {
359+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
360+
} else {
361+
out.ServerGroup = &infrav1.ServerGroupFilter{}
362+
}
363+
357364
return nil
358365
}
359366

@@ -472,6 +479,7 @@ func Convert_v1alpha6_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
472479
out.State = infrav1.InstanceState(in.State)
473480
out.IP = in.IP
474481
out.FloatingIP = in.FloatingIP
482+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
475483
return nil
476484
}
477485

@@ -483,6 +491,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStat
483491
out.State = InstanceState(in.State)
484492
out.IP = in.IP
485493
out.FloatingIP = in.FloatingIP
494+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
486495
return nil
487496
}
488497

@@ -649,5 +658,47 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
649658
}
650659

651660
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
652-
return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
661+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
662+
if err != nil {
663+
return err
664+
}
665+
666+
if in.ServerGroup != nil {
667+
out.ServerGroupID = in.ServerGroup.ID
668+
}
669+
670+
return nil
671+
}
672+
673+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
674+
// ReferencedResources have no equivalent in v1alpha6
675+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in, out, s)
676+
}
677+
678+
func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error {
679+
err := autoConvert_v1alpha6_Bastion_To_v1alpha8_Bastion(in, out, s)
680+
if err != nil {
681+
return err
682+
}
683+
684+
if in.Instance.ServerGroupID != "" {
685+
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{ID: in.Instance.ServerGroupID}
686+
} else {
687+
out.Instance.ServerGroup = &infrav1.ServerGroupFilter{}
688+
}
689+
690+
return nil
691+
}
692+
693+
func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bastion, s apiconversion.Scope) error {
694+
err := autoConvert_v1alpha8_Bastion_To_v1alpha6_Bastion(in, out, s)
695+
if err != nil {
696+
return err
697+
}
698+
699+
if in.Instance.ServerGroup != nil && in.Instance.ServerGroup.ID != "" {
700+
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
701+
}
702+
703+
return nil
653704
}

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)