Skip to content

Commit 126e10a

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 86f78d6 commit 126e10a

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
@@ -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
@@ -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)