diff --git a/api/v1alpha5/conversion.go b/api/v1alpha5/conversion.go index 3029ab1038..b4855587e0 100644 --- a/api/v1alpha5/conversion.go +++ b/api/v1alpha5/conversion.go @@ -504,3 +504,21 @@ func Convert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus( // ReferencedResources have no equivalent in v1alpha5 return autoConvert_v1alpha8_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s) } + +func Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(in *infrav1.Bastion, out *Bastion, s conversion.Scope) error { + err := autoConvert_v1alpha8_Bastion_To_v1alpha5_Bastion(in, out, s) + if err != nil { + return err + } + in.FloatingIP = out.Instance.FloatingIP + return nil +} + +func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bastion, s conversion.Scope) error { + err := autoConvert_v1alpha5_Bastion_To_v1alpha8_Bastion(in, out, s) + if err != nil { + return err + } + in.Instance.FloatingIP = out.FloatingIP + return nil +} diff --git a/api/v1alpha5/zz_generated.conversion.go b/api/v1alpha5/zz_generated.conversion.go index 23e8f4595c..af5bc6fcbf 100644 --- a/api/v1alpha5/zz_generated.conversion.go +++ b/api/v1alpha5/zz_generated.conversion.go @@ -54,16 +54,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*Bastion)(nil), (*v1alpha8.Bastion)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(a.(*Bastion), b.(*v1alpha8.Bastion), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1alpha8.Bastion)(nil), (*Bastion)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(a.(*v1alpha8.Bastion), b.(*Bastion), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*ExternalRouterIPParam)(nil), (*v1alpha8.ExternalRouterIPParam)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha5_ExternalRouterIPParam_To_v1alpha8_ExternalRouterIPParam(a.(*ExternalRouterIPParam), b.(*v1alpha8.ExternalRouterIPParam), scope) }); err != nil { @@ -299,6 +289,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*Bastion)(nil), (*v1alpha8.Bastion)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(a.(*Bastion), b.(*v1alpha8.Bastion), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*Instance)(nil), (*v1alpha8.BastionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha5_Instance_To_v1alpha8_BastionStatus(a.(*Instance), b.(*v1alpha8.BastionStatus), scope) }); err != nil { @@ -359,6 +354,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha8.Bastion)(nil), (*Bastion)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(a.(*v1alpha8.Bastion), b.(*Bastion), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1alpha8.LoadBalancer)(nil), (*LoadBalancer)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha8_LoadBalancer_To_v1alpha5_LoadBalancer(a.(*v1alpha8.LoadBalancer), b.(*LoadBalancer), scope) }); err != nil { @@ -463,25 +463,16 @@ func autoConvert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *v1alpha8 return nil } -// Convert_v1alpha5_Bastion_To_v1alpha8_Bastion is an autogenerated conversion function. -func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *v1alpha8.Bastion, s conversion.Scope) error { - return autoConvert_v1alpha5_Bastion_To_v1alpha8_Bastion(in, out, s) -} - func autoConvert_v1alpha8_Bastion_To_v1alpha5_Bastion(in *v1alpha8.Bastion, out *Bastion, s conversion.Scope) error { out.Enabled = in.Enabled if err := Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(&in.Instance, &out.Instance, s); err != nil { return err } out.AvailabilityZone = in.AvailabilityZone + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha8_Bastion_To_v1alpha5_Bastion is an autogenerated conversion function. -func Convert_v1alpha8_Bastion_To_v1alpha5_Bastion(in *v1alpha8.Bastion, out *Bastion, s conversion.Scope) error { - return autoConvert_v1alpha8_Bastion_To_v1alpha5_Bastion(in, out, s) -} - func autoConvert_v1alpha5_ExternalRouterIPParam_To_v1alpha8_ExternalRouterIPParam(in *ExternalRouterIPParam, out *v1alpha8.ExternalRouterIPParam, s conversion.Scope) error { out.FixedIP = in.FixedIP if err := Convert_v1alpha5_SubnetParam_To_v1alpha8_SubnetFilter(&in.Subnet, &out.Subnet, s); err != nil { @@ -1073,7 +1064,7 @@ func autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( out.Ports = nil } // WARNING: in.Subnet requires manual conversion: does not exist in peer-type - out.FloatingIP = in.FloatingIP + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type if in.SecurityGroups != nil { in, out := &in.SecurityGroups, &out.SecurityGroups *out = make([]v1alpha8.SecurityGroupFilter, len(*in)) @@ -1113,7 +1104,6 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec( } else { out.Ports = nil } - out.FloatingIP = in.FloatingIP if in.SecurityGroups != nil { in, out := &in.SecurityGroups, &out.SecurityGroups *out = make([]SecurityGroupParam, len(*in)) diff --git a/api/v1alpha6/conversion.go b/api/v1alpha6/conversion.go index ab8d50a1bd..2e2000cfd4 100644 --- a/api/v1alpha6/conversion.go +++ b/api/v1alpha6/conversion.go @@ -40,6 +40,10 @@ func restorev1alpha6MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMa dst.Networks = previous.Networks dst.Ports = previous.Ports dst.SecurityGroups = previous.SecurityGroups + + // FloatingIP is removed from v1alpha7 with no replacement, so can't be + // losslessly converted. Restore the previously stored value on down-conversion. + dst.FloatingIP = previous.FloatingIP } func restorev1alpha6ClusterStatus(previous *OpenStackClusterStatus, dst *OpenStackClusterStatus) { @@ -759,6 +763,7 @@ func Convert_v1alpha6_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast out.Instance.ServerGroup = nil } + out.FloatingIP = in.Instance.FloatingIP return nil } @@ -772,5 +777,6 @@ func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bast out.Instance.ServerGroupID = in.Instance.ServerGroup.ID } + out.Instance.FloatingIP = in.FloatingIP return nil } diff --git a/api/v1alpha6/zz_generated.conversion.go b/api/v1alpha6/zz_generated.conversion.go index 63ab1b88b3..8a00f25e45 100644 --- a/api/v1alpha6/zz_generated.conversion.go +++ b/api/v1alpha6/zz_generated.conversion.go @@ -485,6 +485,7 @@ func autoConvert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *v1alpha8.Bastion, out return err } out.AvailabilityZone = in.AvailabilityZone + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type return nil } @@ -1086,7 +1087,7 @@ func autoConvert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( out.Ports = nil } // WARNING: in.Subnet requires manual conversion: does not exist in peer-type - out.FloatingIP = in.FloatingIP + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type if in.SecurityGroups != nil { in, out := &in.SecurityGroups, &out.SecurityGroups *out = make([]v1alpha8.SecurityGroupFilter, len(*in)) @@ -1126,7 +1127,6 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec( } else { out.Ports = nil } - out.FloatingIP = in.FloatingIP if in.SecurityGroups != nil { in, out := &in.SecurityGroups, &out.SecurityGroups *out = make([]SecurityGroupParam, len(*in)) diff --git a/api/v1alpha7/conversion.go b/api/v1alpha7/conversion.go index 25dab7a655..31862c3f86 100644 --- a/api/v1alpha7/conversion.go +++ b/api/v1alpha7/conversion.go @@ -65,6 +65,10 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack ), } +func restorev1alpha7MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) { + dst.FloatingIP = previous.FloatingIP +} + func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) { dst.ServerGroup = previous.ServerGroup dst.Image = previous.Image @@ -169,7 +173,14 @@ func (r *OpenStackClusterTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error var _ ctrlconversion.Convertible = &OpenStackMachine{} -var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine]{} +var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine]{ + "spec": conversion.HashedFieldRestorer( + func(c *OpenStackMachine) *OpenStackMachineSpec { + return &c.Spec + }, + restorev1alpha7MachineSpec, + ), +} var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{ "spec": conversion.HashedFieldRestorer( @@ -221,7 +232,18 @@ func (r *OpenStackMachineList) ConvertFrom(srcRaw ctrlconversion.Hub) error { var _ ctrlconversion.Convertible = &OpenStackMachineTemplate{} -var v1alpha7OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStackMachineTemplate]{} +func restorev1alpha7MachineTemplateSpec(previous *OpenStackMachineTemplateSpec, dst *OpenStackMachineTemplateSpec) { + restorev1alpha7MachineSpec(&previous.Template.Spec, &dst.Template.Spec) +} + +var v1alpha7OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStackMachineTemplate]{ + "spec": conversion.HashedFieldRestorer( + func(c *OpenStackMachineTemplate) *OpenStackMachineTemplateSpec { + return &c.Spec + }, + restorev1alpha7MachineTemplateSpec, + ), +} var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackMachineTemplate]{ "spec": conversion.HashedFieldRestorer( @@ -331,6 +353,7 @@ func Convert_v1alpha7_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast out.Instance.ServerGroup = nil } + out.FloatingIP = in.Instance.FloatingIP return nil } @@ -344,6 +367,7 @@ func Convert_v1alpha8_Bastion_To_v1alpha7_Bastion(in *infrav1.Bastion, out *Bast out.Instance.ServerGroupID = in.Instance.ServerGroup.ID } + out.Instance.FloatingIP = in.FloatingIP return nil } diff --git a/api/v1alpha7/zz_generated.conversion.go b/api/v1alpha7/zz_generated.conversion.go index 25b03fcc7e..2df0972e6e 100644 --- a/api/v1alpha7/zz_generated.conversion.go +++ b/api/v1alpha7/zz_generated.conversion.go @@ -543,6 +543,7 @@ func autoConvert_v1alpha8_Bastion_To_v1alpha7_Bastion(in *v1alpha8.Bastion, out return err } out.AvailabilityZone = in.AvailabilityZone + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type return nil } @@ -1236,7 +1237,7 @@ func autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( // WARNING: in.ImageUUID requires manual conversion: does not exist in peer-type out.SSHKeyName = in.SSHKeyName out.Ports = *(*[]v1alpha8.PortOpts)(unsafe.Pointer(&in.Ports)) - out.FloatingIP = in.FloatingIP + // WARNING: in.FloatingIP requires manual conversion: does not exist in peer-type out.SecurityGroups = *(*[]v1alpha8.SecurityGroupFilter)(unsafe.Pointer(&in.SecurityGroups)) out.Trunk = in.Trunk out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags)) @@ -1257,7 +1258,6 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec( // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName out.Ports = *(*[]PortOpts)(unsafe.Pointer(&in.Ports)) - out.FloatingIP = in.FloatingIP out.SecurityGroups = *(*[]SecurityGroupFilter)(unsafe.Pointer(&in.SecurityGroups)) out.Trunk = in.Trunk out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags)) diff --git a/api/v1alpha8/openstackmachine_types.go b/api/v1alpha8/openstackmachine_types.go index d5b27b4648..61d29bad86 100644 --- a/api/v1alpha8/openstackmachine_types.go +++ b/api/v1alpha8/openstackmachine_types.go @@ -56,10 +56,6 @@ type OpenStackMachineSpec struct { // If not specified a default port will be added for the default cluster network. Ports []PortOpts `json:"ports,omitempty"` - // The floatingIP which will be associated to the machine, only used for master. - // The floatingIP should have been created and haven't been associated. - FloatingIP string `json:"floatingIP,omitempty"` - // The names of the security groups to assign to the instance SecurityGroups []SecurityGroupFilter `json:"securityGroups,omitempty"` diff --git a/api/v1alpha8/types.go b/api/v1alpha8/types.go index 016fb258ed..bdbf2155bf 100644 --- a/api/v1alpha8/types.go +++ b/api/v1alpha8/types.go @@ -362,6 +362,11 @@ type Bastion struct { //+optional AvailabilityZone string `json:"availabilityZone,omitempty"` + + // FloatingIP which will be associated to the bastion machine. + // The floating IP should already exist and should not be associated with a port. + //+optional + FloatingIP string `json:"floatingIP,omitempty"` } type APIServerLoadBalancer struct { diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml index 0a8cf90fd1..476a313e17 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -4811,6 +4811,11 @@ spec: type: string enabled: type: boolean + floatingIP: + description: FloatingIP which will be associated to the bastion + machine. The floating IP should already exist and should not + be associated with a port. + type: string instance: description: Instance for the bastion itself properties: @@ -4886,11 +4891,6 @@ spec: description: The flavor reference for the flavor for your server instance. type: string - floatingIP: - description: The floatingIP which will be associated to the - machine, only used for master. The floatingIP should have - been created and haven't been associated. - type: string identityRef: description: IdentityRef is a reference to a identity to be used when reconciling this cluster diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml index 08e725eae4..c37a536dc8 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -2338,6 +2338,11 @@ spec: type: string enabled: type: boolean + floatingIP: + description: FloatingIP which will be associated to the + bastion machine. The floating IP should already exist + and should not be associated with a port. + type: string instance: description: Instance for the bastion itself properties: @@ -2419,11 +2424,6 @@ spec: description: The flavor reference for the flavor for your server instance. type: string - floatingIP: - description: The floatingIP which will be associated - to the machine, only used for master. The floatingIP - should have been created and haven't been associated. - type: string identityRef: description: IdentityRef is a reference to a identity to be used when reconciling this cluster diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml index a0bde06ad8..744bf7bd31 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -1725,11 +1725,6 @@ spec: flavor: description: The flavor reference for the flavor for your server instance. type: string - floatingIP: - description: The floatingIP which will be associated to the machine, - only used for master. The floatingIP should have been created and - haven't been associated. - type: string identityRef: description: IdentityRef is a reference to a identity to be used when reconciling this cluster diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml index 16da499668..670a1d9868 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml @@ -1438,11 +1438,6 @@ spec: description: The flavor reference for the flavor for your server instance. type: string - floatingIP: - description: The floatingIP which will be associated to the - machine, only used for master. The floatingIP should have - been created and haven't been associated. - type: string identityRef: description: IdentityRef is a reference to a identity to be used when reconciling this cluster diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index 9b857b7011..e954631e1d 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -412,7 +412,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl } clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name) - floatingIP := openStackCluster.Spec.Bastion.Instance.FloatingIP + floatingIP := openStackCluster.Spec.Bastion.FloatingIP if openStackCluster.Status.Bastion.FloatingIP != "" { // Some floating IP has already been created for this bastion, make sure we re-use it floatingIP = openStackCluster.Status.Bastion.FloatingIP diff --git a/docs/book/src/clusteropenstack/configuration.md b/docs/book/src/clusteropenstack/configuration.md index 7802107f02..1a075bc57e 100644 --- a/docs/book/src/clusteropenstack/configuration.md +++ b/docs/book/src/clusteropenstack/configuration.md @@ -649,7 +649,7 @@ spec: ... bastion: ... - floatingIP: + floatingIP: ``` 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. diff --git a/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md b/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md index 1183805d26..512f61d83a 100644 --- a/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md +++ b/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md @@ -6,11 +6,12 @@ - [Migration](#migration) - [API Changes](#api-changes) - [`OpenStackMachine`](#openstackmachine) - - [Change to `serverGroupID`](#change-to-servergroupid) + - [⚠️ Change to `serverGroupID`](#️-change-to-servergroupid) - [`OpenStackCluster`](#openstackcluster) - [Change to externalNetworkID](#change-to-externalnetworkid) - [Changes to image](#change-to-image) - [Removal of imageUUID](#removal-of-imageuuid) + - [Change to floatingIP](#change-to-floatingip) @@ -123,3 +124,35 @@ becomes image: id: "72a6a1e6-3e0a-4a8b-9b4c-2d6f9e3e5f0a" ``` + +#### Change to floatingIP + +The `OpenStackMachineSpec.FloatingIP` field has moved to `OpenStackClusterSpec.Bastion.FloatingIP`. +For example, if you had the following `OpenStackMachineTemplate`: + +```yaml +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha6 +kind: OpenStackMachineTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + spec: + .. + floatingIP: "1.2.3.4" +``` + +This will safely converted to use `Bastion.FloatingIP` when upgrading to version 0.8. + +To use the new `Bastion.FloatingIP` field, here is an example: + +```yaml +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha7 +kind: OpenStackCluster +metadata: + name: ${CLUSTER_NAME} +spec: + .. + bastion: + floatingIP: "1.2.3.4" +```