Skip to content

Commit 3eb70ea

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 6df0da0 commit 3eb70ea

25 files changed

+678
-108
lines changed

api/v1alpha5/conversion.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,16 @@ 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+
}
224+
225+
return nil
217226
}
218227

219228
func Convert_v1alpha8_APIServerLoadBalancer_To_v1alpha5_APIServerLoadBalancer(in *infrav1.APIServerLoadBalancer, out *APIServerLoadBalancer, s conversion.Scope) error {
@@ -246,6 +255,7 @@ func Convert_v1alpha5_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
246255
out.State = infrav1.InstanceState(in.State)
247256
out.IP = in.IP
248257
out.FloatingIP = in.FloatingIP
258+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
249259
return nil
250260
}
251261

@@ -257,6 +267,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha5_Instance(in *infrav1.BastionStat
257267
out.State = InstanceState(in.State)
258268
out.IP = in.IP
259269
out.FloatingIP = in.FloatingIP
270+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
260271
return nil
261272
}
262273

@@ -435,5 +446,19 @@ func Convert_v1alpha5_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
435446
}
436447

437448
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)
449+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
450+
if err != nil {
451+
return err
452+
}
453+
454+
if in.ServerGroup != nil {
455+
out.ServerGroupID = in.ServerGroup.ID
456+
}
457+
458+
return nil
459+
}
460+
461+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error {
462+
// ReferencedResources have no equivalent in v1alpha5
463+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s)
439464
}

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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ 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+
}
365369
return nil
366370
}
367371

@@ -480,6 +484,7 @@ func Convert_v1alpha6_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
480484
out.State = infrav1.InstanceState(in.State)
481485
out.IP = in.IP
482486
out.FloatingIP = in.FloatingIP
487+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
483488
return nil
484489
}
485490

@@ -491,6 +496,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStat
491496
out.State = InstanceState(in.State)
492497
out.IP = in.IP
493498
out.FloatingIP = in.FloatingIP
499+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
494500
return nil
495501
}
496502

@@ -657,5 +663,19 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
657663
}
658664

659665
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)
666+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
667+
if err != nil {
668+
return err
669+
}
670+
671+
if in.ServerGroup != nil {
672+
out.ServerGroupID = in.ServerGroup.ID
673+
}
674+
675+
return nil
676+
}
677+
678+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
679+
// ReferencedResources have no equivalent in v1alpha7
680+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in, out, s)
661681
}

api/v1alpha6/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func TestFuzzyConversion(t *testing.T) {
8888
status.ExternalNetwork.APIServerLoadBalancer = nil
8989
}
9090
},
91+
92+
func(v1alpha8Bastion *infrav1.Bastion, c fuzz.Continue) {
93+
c.FuzzNoCustom(v1alpha8Bastion)
94+
95+
// None of the following fields have ever been set in v1alpha6
96+
v1alpha8Bastion.Instance.ServerGroup.Name = ""
97+
},
9198
}
9299
}
93100

api/v1alpha6/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/v1alpha7/conversion.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha7
1818

1919
import (
20+
apiconversion "k8s.io/apimachinery/pkg/conversion"
2021
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2122

2223
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8"
@@ -232,3 +233,39 @@ func (r *OpenStackMachineTemplateList) ConvertFrom(srcRaw ctrlconversion.Hub) er
232233
src := srcRaw.(*infrav1.OpenStackMachineTemplateList)
233234
return Convert_v1alpha8_OpenStackMachineTemplateList_To_v1alpha7_OpenStackMachineTemplateList(src, r, nil)
234235
}
236+
237+
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
238+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s)
239+
if err != nil {
240+
return err
241+
}
242+
243+
if in.ServerGroup != nil {
244+
out.ServerGroupID = in.ServerGroup.ID
245+
}
246+
247+
return nil
248+
}
249+
250+
func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s apiconversion.Scope) error {
251+
err := autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
252+
if err != nil {
253+
return err
254+
}
255+
256+
if in.ServerGroupID != "" {
257+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
258+
}
259+
260+
return nil
261+
}
262+
263+
func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
264+
// ReferencedResources have no equivalent in v1alpha7
265+
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in, out, s)
266+
}
267+
268+
func Convert_v1alpha8_BastionStatus_To_v1alpha7_BastionStatus(in *infrav1.BastionStatus, out *BastionStatus, s apiconversion.Scope) error {
269+
// ReferencedResources have no equivalent in v1alpha7
270+
return autoConvert_v1alpha8_BastionStatus_To_v1alpha7_BastionStatus(in, out, s)
271+
}

api/v1alpha7/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func TestFuzzyConversion(t *testing.T) {
6060
func(status *OpenStackClusterStatus, c fuzz.Continue) {
6161
c.FuzzNoCustom(status)
6262
},
63+
64+
func(v1alpha8Bastion *infrav1.Bastion, c fuzz.Continue) {
65+
c.FuzzNoCustom(v1alpha8Bastion)
66+
67+
// None of the following fields have ever been set in v1alpha7
68+
v1alpha8Bastion.Instance.ServerGroup.Name = ""
69+
},
6370
}
6471
}
6572

api/v1alpha7/openstackmachine_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type OpenStackMachineSpec struct {
9090
// +optional
9191
AdditionalBlockDevices []AdditionalBlockDevice `json:"additionalBlockDevices,omitempty"`
9292

93-
// The server group to assign the machine to
93+
// The server group to assign the machine to.
9494
ServerGroupID string `json:"serverGroupID,omitempty"`
9595

9696
// IdentityRef is a reference to a identity to be used when reconciling this cluster

api/v1alpha7/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ type AdditionalBlockDevice struct {
215215
Storage BlockDeviceStorage `json:"storage"`
216216
}
217217

218+
type ServerGroupFilter struct {
219+
ID string `json:"id,omitempty"`
220+
Name string `json:"name,omitempty"`
221+
}
222+
218223
// BlockDeviceType defines the type of block device to create.
219224
type BlockDeviceType string
220225

0 commit comments

Comments
 (0)