Skip to content

Commit 9b4858e

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 fdc5f49 commit 9b4858e

25 files changed

+990
-148
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: 63 additions & 1 deletion
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 {
@@ -354,6 +365,13 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
354365
// Networks were previously created first, so need to come before ports
355366
out.Ports = append(ports, out.Ports...)
356367
}
368+
369+
if in.ServerGroupID != "" {
370+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
371+
} else {
372+
out.ServerGroup = nil
373+
}
374+
357375
return nil
358376
}
359377

@@ -472,6 +490,7 @@ func Convert_v1alpha6_Instance_To_v1alpha8_BastionStatus(in *Instance, out *infr
472490
out.State = infrav1.InstanceState(in.State)
473491
out.IP = in.IP
474492
out.FloatingIP = in.FloatingIP
493+
out.ReferencedResources.ServerGroupID = in.ServerGroupID
475494
return nil
476495
}
477496

@@ -483,6 +502,7 @@ func Convert_v1alpha8_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStat
483502
out.State = InstanceState(in.State)
484503
out.IP = in.IP
485504
out.FloatingIP = in.FloatingIP
505+
out.ServerGroupID = in.ReferencedResources.ServerGroupID
486506
return nil
487507
}
488508

@@ -649,5 +669,47 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
649669
}
650670

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

api/v1alpha6/zz_generated.conversion.go

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

0 commit comments

Comments
 (0)