Skip to content

Commit 0796264

Browse files
EmilienMmdbooth
andcommitted
Move FloatingIP to Bastion spec
Re-adding commit which was previously erroneously added to v1alpha7 and reverted. (cherry picked from commit f19a6cc) Updated to target v1alpha8 instead of v1alpha7. Conversion code is reworked from previous commit to be minimal. Co-Authored-By: Matthew Booth <[email protected]>
1 parent 4f994cb commit 0796264

15 files changed

+117
-55
lines changed

api/v1alpha5/conversion.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,21 @@ func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(
504504
// ReferencedResources have no equivalent in v1alpha5
505505
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s)
506506
}
507+
508+
func Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(in *infrav1.Bastion, out *Bastion, s conversion.Scope) error {
509+
err := autoConvert_v1alpha8_Bastion_To_v1alpha5_Bastion(in, out, s)
510+
if err != nil {
511+
return err
512+
}
513+
in.FloatingIP = out.Instance.FloatingIP
514+
return nil
515+
}
516+
517+
func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bastion, s conversion.Scope) error {
518+
err := autoConvert_v1alpha5_Bastion_To_v1alpha8_Bastion(in, out, s)
519+
if err != nil {
520+
return err
521+
}
522+
in.Instance.FloatingIP = out.FloatingIP
523+
return nil
524+
}

api/v1alpha5/zz_generated.conversion.go

Lines changed: 12 additions & 22 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func restorev1alpha6MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMa
4040
dst.Networks = previous.Networks
4141
dst.Ports = previous.Ports
4242
dst.SecurityGroups = previous.SecurityGroups
43+
44+
// FloatingIP is removed from v1alpha7 with no replacement, so can't be
45+
// losslessly converted. Restore the previously stored value on down-conversion.
46+
dst.FloatingIP = previous.FloatingIP
4347
}
4448

4549
func restorev1alpha6ClusterStatus(previous *OpenStackClusterStatus, dst *OpenStackClusterStatus) {
@@ -759,6 +763,7 @@ func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
759763
out.Instance.ServerGroup = nil
760764
}
761765

766+
out.FloatingIP = in.Instance.FloatingIP
762767
return nil
763768
}
764769

@@ -772,5 +777,6 @@ func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bast
772777
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
773778
}
774779

780+
out.Instance.FloatingIP = in.FloatingIP
775781
return nil
776782
}

api/v1alpha6/zz_generated.conversion.go

Lines changed: 2 additions & 2 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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack
6565
),
6666
}
6767

68+
func restorev1alpha7MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) {
69+
dst.FloatingIP = previous.FloatingIP
70+
}
71+
6872
func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
6973
dst.ServerGroup = previous.ServerGroup
7074
dst.Image = previous.Image
@@ -169,7 +173,14 @@ func (r *OpenStackClusterTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error
169173

170174
var _ ctrlconversion.Convertible = &OpenStackMachine{}
171175

172-
var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine]{}
176+
var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine]{
177+
"spec": conversion.HashedFieldRestorer(
178+
func(c *OpenStackMachine) *OpenStackMachineSpec {
179+
return &c.Spec
180+
},
181+
restorev1alpha7MachineSpec,
182+
),
183+
}
173184

174185
var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{
175186
"spec": conversion.HashedFieldRestorer(
@@ -221,7 +232,18 @@ func (r *OpenStackMachineList) ConvertFrom(srcRaw ctrlconversion.Hub) error {
221232

222233
var _ ctrlconversion.Convertible = &OpenStackMachineTemplate{}
223234

224-
var v1alpha7OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStackMachineTemplate]{}
235+
func restorev1alpha7MachineTemplateSpec(previous *OpenStackMachineTemplateSpec, dst *OpenStackMachineTemplateSpec) {
236+
restorev1alpha7MachineSpec(&previous.Template.Spec, &dst.Template.Spec)
237+
}
238+
239+
var v1alpha7OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStackMachineTemplate]{
240+
"spec": conversion.HashedFieldRestorer(
241+
func(c *OpenStackMachineTemplate) *OpenStackMachineTemplateSpec {
242+
return &c.Spec
243+
},
244+
restorev1alpha7MachineTemplateSpec,
245+
),
246+
}
225247

226248
var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackMachineTemplate]{
227249
"spec": conversion.HashedFieldRestorer(
@@ -331,6 +353,7 @@ func Convert_v1alpha7_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
331353
out.Instance.ServerGroup = nil
332354
}
333355

356+
out.FloatingIP = in.Instance.FloatingIP
334357
return nil
335358
}
336359

@@ -344,6 +367,7 @@ func Convert_v1alpha8_Bastion_To_v1alpha7_Bastion(in *infrav1.Bastion, out *Bast
344367
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
345368
}
346369

370+
out.Instance.FloatingIP = in.FloatingIP
347371
return nil
348372
}
349373

api/v1alpha7/zz_generated.conversion.go

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

api/v1alpha8/openstackmachine_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ type OpenStackMachineSpec struct {
5656
// If not specified a default port will be added for the default cluster network.
5757
Ports []PortOpts `json:"ports,omitempty"`
5858

59-
// The floatingIP which will be associated to the machine, only used for master.
60-
// The floatingIP should have been created and haven't been associated.
61-
FloatingIP string `json:"floatingIP,omitempty"`
62-
6359
// The names of the security groups to assign to the instance
6460
SecurityGroups []SecurityGroupFilter `json:"securityGroups,omitempty"`
6561

api/v1alpha8/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ type Bastion struct {
362362

363363
//+optional
364364
AvailabilityZone string `json:"availabilityZone,omitempty"`
365+
366+
// FloatingIP which will be associated to the bastion machine.
367+
// The floating IP should already exist and should not be associated with a port.
368+
//+optional
369+
FloatingIP string `json:"floatingIP,omitempty"`
365370
}
366371

367372
type APIServerLoadBalancer struct {

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,6 +4906,11 @@ spec:
49064906
type: string
49074907
enabled:
49084908
type: boolean
4909+
floatingIP:
4910+
description: |-
4911+
FloatingIP which will be associated to the bastion machine.
4912+
The floating IP should already exist and should not be associated with a port.
4913+
type: string
49094914
instance:
49104915
description: Instance for the bastion itself
49114916
properties:
@@ -4981,11 +4986,6 @@ spec:
49814986
description: The flavor reference for the flavor for your
49824987
server instance.
49834988
type: string
4984-
floatingIP:
4985-
description: |-
4986-
The floatingIP which will be associated to the machine, only used for master.
4987-
The floatingIP should have been created and haven't been associated.
4988-
type: string
49894989
identityRef:
49904990
description: IdentityRef is a reference to a identity to be
49914991
used when reconciling this cluster

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,11 @@ spec:
23312331
type: string
23322332
enabled:
23332333
type: boolean
2334+
floatingIP:
2335+
description: |-
2336+
FloatingIP which will be associated to the bastion machine.
2337+
The floating IP should already exist and should not be associated with a port.
2338+
type: string
23342339
instance:
23352340
description: Instance for the bastion itself
23362341
properties:
@@ -2407,11 +2412,6 @@ spec:
24072412
description: The flavor reference for the flavor for
24082413
your server instance.
24092414
type: string
2410-
floatingIP:
2411-
description: |-
2412-
The floatingIP which will be associated to the machine, only used for master.
2413-
The floatingIP should have been created and haven't been associated.
2414-
type: string
24152415
identityRef:
24162416
description: IdentityRef is a reference to a identity
24172417
to be used when reconciling this cluster

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,11 +1780,6 @@ spec:
17801780
flavor:
17811781
description: The flavor reference for the flavor for your server instance.
17821782
type: string
1783-
floatingIP:
1784-
description: |-
1785-
The floatingIP which will be associated to the machine, only used for master.
1786-
The floatingIP should have been created and haven't been associated.
1787-
type: string
17881783
identityRef:
17891784
description: IdentityRef is a reference to a identity to be used when
17901785
reconciling this cluster

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,11 +1455,6 @@ spec:
14551455
description: The flavor reference for the flavor for your
14561456
server instance.
14571457
type: string
1458-
floatingIP:
1459-
description: |-
1460-
The floatingIP which will be associated to the machine, only used for master.
1461-
The floatingIP should have been created and haven't been associated.
1462-
type: string
14631458
identityRef:
14641459
description: IdentityRef is a reference to a identity to be
14651460
used when reconciling this cluster

controllers/openstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
412412
}
413413

414414
clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)
415-
floatingIP := openStackCluster.Spec.Bastion.Instance.FloatingIP
415+
floatingIP := openStackCluster.Spec.Bastion.FloatingIP
416416
if openStackCluster.Status.Bastion.FloatingIP != "" {
417417
// Some floating IP has already been created for this bastion, make sure we re-use it
418418
floatingIP = openStackCluster.Status.Bastion.FloatingIP

docs/book/src/clusteropenstack/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ spec:
649649
...
650650
bastion:
651651
...
652-
floatingIP: <Floating IP address>
652+
floatingIP: <Floating IP address>
653653
```
654654

655655
If `managedSecurityGroups: true`, security group rule opening 22/tcp is added to security groups for bastion, controller, and worker nodes respectively. Otherwise, you have to add `securityGroups` to the `bastion` in `OpenStackCluster` spec and `OpenStackMachineTemplate` spec template respectively.

0 commit comments

Comments
 (0)