Skip to content

Commit 674a8be

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 55ab11d commit 674a8be

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
@@ -487,3 +487,21 @@ func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(
487487
// ReferencedResources have no equivalent in v1alpha5
488488
return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s)
489489
}
490+
491+
func Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(in *infrav1.Bastion, out *Bastion, s conversion.Scope) error {
492+
err := autoConvert_v1alpha8_Bastion_To_v1alpha5_Bastion(in, out, s)
493+
if err != nil {
494+
return err
495+
}
496+
in.FloatingIP = out.Instance.FloatingIP
497+
return nil
498+
}
499+
500+
func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bastion, s conversion.Scope) error {
501+
err := autoConvert_v1alpha5_Bastion_To_v1alpha8_Bastion(in, out, s)
502+
if err != nil {
503+
return err
504+
}
505+
in.Instance.FloatingIP = out.FloatingIP
506+
return nil
507+
}

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) {
@@ -741,6 +745,7 @@ func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
741745
out.Instance.ServerGroup = nil
742746
}
743747

748+
out.FloatingIP = in.Instance.FloatingIP
744749
return nil
745750
}
746751

@@ -754,5 +759,6 @@ func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bast
754759
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
755760
}
756761

762+
out.Instance.FloatingIP = in.FloatingIP
757763
return nil
758764
}

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
}
@@ -168,7 +172,14 @@ func (r *OpenStackClusterTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error
168172

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

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

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

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

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

225247
var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackMachineTemplate]{
226248
"spec": conversion.HashedFieldRestorer(
@@ -313,6 +335,7 @@ func Convert_v1alpha7_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
313335
out.Instance.ServerGroup = nil
314336
}
315337

338+
out.FloatingIP = in.Instance.FloatingIP
316339
return nil
317340
}
318341

@@ -326,6 +349,7 @@ func Convert_v1alpha8_Bastion_To_v1alpha7_Bastion(in *infrav1.Bastion, out *Bast
326349
out.Instance.ServerGroupID = in.Instance.ServerGroup.ID
327350
}
328351

352+
out.Instance.FloatingIP = in.FloatingIP
329353
return nil
330354
}
331355

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
@@ -60,10 +60,6 @@ type OpenStackMachineSpec struct {
6060
// If not specified a default port will be added for the default cluster network.
6161
Ports []PortOpts `json:"ports,omitempty"`
6262

63-
// The floatingIP which will be associated to the machine, only used for master.
64-
// The floatingIP should have been created and haven't been associated.
65-
FloatingIP string `json:"floatingIP,omitempty"`
66-
6763
// The names of the security groups to assign to the instance
6864
SecurityGroups []SecurityGroupFilter `json:"securityGroups,omitempty"`
6965

api/v1alpha8/types.go

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

351351
//+optional
352352
AvailabilityZone string `json:"availabilityZone,omitempty"`
353+
354+
// FloatingIP which will be associated to the bastion machine.
355+
// The floating IP should already exist and should not be associated with a port.
356+
//+optional
357+
FloatingIP string `json:"floatingIP,omitempty"`
353358
}
354359

355360
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
@@ -4811,6 +4811,11 @@ spec:
48114811
type: string
48124812
enabled:
48134813
type: boolean
4814+
floatingIP:
4815+
description: FloatingIP which will be associated to the bastion
4816+
machine. The floating IP should already exist and should not
4817+
be associated with a port.
4818+
type: string
48144819
instance:
48154820
description: Instance for the bastion itself
48164821
properties:
@@ -4886,11 +4891,6 @@ spec:
48864891
description: The flavor reference for the flavor for your
48874892
server instance.
48884893
type: string
4889-
floatingIP:
4890-
description: The floatingIP which will be associated to the
4891-
machine, only used for master. The floatingIP should have
4892-
been created and haven't been associated.
4893-
type: string
48944894
identityRef:
48954895
description: IdentityRef is a reference to a identity to be
48964896
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
@@ -2338,6 +2338,11 @@ spec:
23382338
type: string
23392339
enabled:
23402340
type: boolean
2341+
floatingIP:
2342+
description: FloatingIP which will be associated to the
2343+
bastion machine. The floating IP should already exist
2344+
and should not be associated with a port.
2345+
type: string
23412346
instance:
23422347
description: Instance for the bastion itself
23432348
properties:
@@ -2419,11 +2424,6 @@ spec:
24192424
description: The flavor reference for the flavor for
24202425
your server instance.
24212426
type: string
2422-
floatingIP:
2423-
description: The floatingIP which will be associated
2424-
to the machine, only used for master. The floatingIP
2425-
should have been created and haven't been associated.
2426-
type: string
24272427
identityRef:
24282428
description: IdentityRef is a reference to a identity
24292429
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
@@ -1725,11 +1725,6 @@ spec:
17251725
flavor:
17261726
description: The flavor reference for the flavor for your server instance.
17271727
type: string
1728-
floatingIP:
1729-
description: The floatingIP which will be associated to the machine,
1730-
only used for master. The floatingIP should have been created and
1731-
haven't been associated.
1732-
type: string
17331728
identityRef:
17341729
description: IdentityRef is a reference to a identity to be used when
17351730
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
@@ -1438,11 +1438,6 @@ spec:
14381438
description: The flavor reference for the flavor for your
14391439
server instance.
14401440
type: string
1441-
floatingIP:
1442-
description: The floatingIP which will be associated to the
1443-
machine, only used for master. The floatingIP should have
1444-
been created and haven't been associated.
1445-
type: string
14461441
identityRef:
14471442
description: IdentityRef is a reference to a identity to be
14481443
used when reconciling this cluster

controllers/openstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
359359
return err
360360
}
361361
clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)
362-
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, openStackCluster.Spec.Bastion.Instance.FloatingIP)
362+
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, openStackCluster.Spec.Bastion.FloatingIP)
363363
if err != nil {
364364
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to get or create floating IP for bastion: %w", err))
365365
return fmt.Errorf("failed to get or create floating IP for bastion: %w", err)

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)