Skip to content

Commit 32369b6

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

25 files changed

+975
-162
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: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ 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
6465
}
6566

6667
func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
@@ -76,6 +77,10 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
7677
if previous.Network == nil && dst.Network != nil && reflect.ValueOf(*dst.Network).IsZero() {
7778
dst.Network = nil
7879
}
80+
81+
if previous.Bastion != nil {
82+
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
83+
}
7984
}
8085

8186
func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
@@ -257,6 +262,13 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
257262
},
258263
restorev1alpha8MachineSpec,
259264
),
265+
266+
// No equivalent in v1alpha6
267+
"refresources": conversion.UnconditionalFieldRestorer(
268+
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
269+
return &c.Status.ReferencedResources
270+
},
271+
),
260272
}
261273

262274
func (r *OpenStackMachine) ConvertTo(dstRaw ctrlconversion.Hub) error {
@@ -354,6 +366,13 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
354366
// Networks were previously created first, so need to come before ports
355367
out.Ports = append(ports, out.Ports...)
356368
}
369+
370+
if in.ServerGroupID != "" {
371+
out.ServerGroup = &infrav1.ServerGroupFilter{ID: in.ServerGroupID}
372+
} else {
373+
out.ServerGroup = nil
374+
}
375+
357376
return nil
358377
}
359378

@@ -649,5 +668,47 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
649668
}
650669

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

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)