diff --git a/api/v1alpha3/conversion.go b/api/v1alpha3/conversion.go index 36450d694d..ff383b6e83 100644 --- a/api/v1alpha3/conversion.go +++ b/api/v1alpha3/conversion.go @@ -17,6 +17,8 @@ limitations under the License. package v1alpha3 import ( + unsafe "unsafe" + corev1 "k8s.io/api/core/v1" conversion "k8s.io/apimachinery/pkg/conversion" ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion" @@ -117,6 +119,10 @@ func Convert_v1alpha3_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O Name: in.CloudsSecret.Name, } } + out.APIServerLoadBalancer = infrav1.APIServerLoadBalancer{ + Enabled: in.ManagedAPIServerLoadBalancer, + AdditionalPorts: *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)), + } return autoConvert_v1alpha3_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s) } @@ -139,6 +145,10 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in *i Name: in.Bastion.Instance.IdentityRef.Name, } } + + out.ManagedAPIServerLoadBalancer = in.APIServerLoadBalancer.Enabled + out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancer.AdditionalPorts)) + return autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(in, out, s) } diff --git a/api/v1alpha3/conversion_test.go b/api/v1alpha3/conversion_test.go index 6c334dfe4f..31bb961d4f 100644 --- a/api/v1alpha3/conversion_test.go +++ b/api/v1alpha3/conversion_test.go @@ -25,10 +25,93 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" utilconversion "sigs.k8s.io/cluster-api/util/conversion" + ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion" infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" ) +func TestConvertTo(t *testing.T) { + g := gomega.NewWithT(t) + scheme := runtime.NewScheme() + g.Expect(AddToScheme(scheme)).To(gomega.Succeed()) + g.Expect(infrav1.AddToScheme(scheme)).To(gomega.Succeed()) + + tests := []struct { + name string + spoke ctrlconversion.Convertible + hub ctrlconversion.Hub + want ctrlconversion.Hub + }{ + { + name: "APIServer LoadBalancer Configuration", + spoke: &OpenStackCluster{ + Spec: OpenStackClusterSpec{ + ManagedAPIServerLoadBalancer: true, + APIServerLoadBalancerAdditionalPorts: []int{80, 443}, + }, + }, + hub: &infrav1.OpenStackCluster{}, + want: &infrav1.OpenStackCluster{ + Spec: infrav1.OpenStackClusterSpec{ + APIServerLoadBalancer: infrav1.APIServerLoadBalancer{ + Enabled: true, + AdditionalPorts: []int{80, 443}, + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.spoke.ConvertTo(tt.hub) + g.Expect(err).NotTo(gomega.HaveOccurred()) + g.Expect(tt.hub).To(gomega.Equal(tt.want)) + }) + } +} + +func TestConvertFrom(t *testing.T) { + g := gomega.NewWithT(t) + scheme := runtime.NewScheme() + g.Expect(AddToScheme(scheme)).To(gomega.Succeed()) + g.Expect(infrav1.AddToScheme(scheme)).To(gomega.Succeed()) + + tests := []struct { + name string + spoke ctrlconversion.Convertible + hub ctrlconversion.Hub + want ctrlconversion.Convertible + }{ + { + name: "APIServer LoadBalancer Configuration", + spoke: &OpenStackCluster{}, + hub: &infrav1.OpenStackCluster{ + Spec: infrav1.OpenStackClusterSpec{ + APIServerLoadBalancer: infrav1.APIServerLoadBalancer{ + Enabled: true, + AdditionalPorts: []int{80, 443}, + }, + }, + }, + want: &OpenStackCluster{ + Spec: OpenStackClusterSpec{ + ManagedAPIServerLoadBalancer: true, + APIServerLoadBalancerAdditionalPorts: []int{80, 443}, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.spoke.ConvertFrom(tt.hub) + g.Expect(err).NotTo(gomega.HaveOccurred()) + g.Expect(tt.spoke).To(gomega.Equal(tt.want)) + }) + } +} + func TestFuzzyConversion(t *testing.T) { g := gomega.NewWithT(t) scheme := runtime.NewScheme() diff --git a/api/v1alpha3/zz_generated.conversion.go b/api/v1alpha3/zz_generated.conversion.go index 45c9bee8c4..6c39e5a51f 100644 --- a/api/v1alpha3/zz_generated.conversion.go +++ b/api/v1alpha3/zz_generated.conversion.go @@ -676,10 +676,10 @@ func autoConvert_v1alpha3_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(i } out.ExternalNetworkID = in.ExternalNetworkID // WARNING: in.UseOctavia requires manual conversion: does not exist in peer-type - out.ManagedAPIServerLoadBalancer = in.ManagedAPIServerLoadBalancer + // WARNING: in.ManagedAPIServerLoadBalancer requires manual conversion: does not exist in peer-type out.APIServerFloatingIP = in.APIServerFloatingIP out.APIServerPort = in.APIServerPort - out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)) + // WARNING: in.APIServerLoadBalancerAdditionalPorts requires manual conversion: does not exist in peer-type out.ManagedSecurityGroups = in.ManagedSecurityGroups out.DisablePortSecurity = in.DisablePortSecurity out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags)) @@ -721,12 +721,11 @@ func autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha3_OpenStackClusterSpec(i out.ExternalRouterIPs = nil } out.ExternalNetworkID = in.ExternalNetworkID - out.ManagedAPIServerLoadBalancer = in.ManagedAPIServerLoadBalancer + // WARNING: in.APIServerLoadBalancer requires manual conversion: does not exist in peer-type // WARNING: in.DisableAPIServerFloatingIP requires manual conversion: does not exist in peer-type out.APIServerFloatingIP = in.APIServerFloatingIP // WARNING: in.APIServerFixedIP requires manual conversion: does not exist in peer-type out.APIServerPort = in.APIServerPort - out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)) out.ManagedSecurityGroups = in.ManagedSecurityGroups // WARNING: in.AllowAllInClusterTraffic requires manual conversion: does not exist in peer-type out.DisablePortSecurity = in.DisablePortSecurity diff --git a/api/v1alpha4/conversion_test.go b/api/v1alpha4/conversion_test.go index 6364261b16..2bffec9dc3 100644 --- a/api/v1alpha4/conversion_test.go +++ b/api/v1alpha4/conversion_test.go @@ -70,6 +70,24 @@ func TestConvertTo(t *testing.T) { }, }, }, + { + name: "APIServer LoadBalancer Configuration", + spoke: &OpenStackCluster{ + Spec: OpenStackClusterSpec{ + ManagedAPIServerLoadBalancer: true, + APIServerLoadBalancerAdditionalPorts: []int{80, 443}, + }, + }, + hub: &infrav1.OpenStackCluster{}, + want: &infrav1.OpenStackCluster{ + Spec: infrav1.OpenStackClusterSpec{ + APIServerLoadBalancer: infrav1.APIServerLoadBalancer{ + Enabled: true, + AdditionalPorts: []int{80, 443}, + }, + }, + }, + }, } for _, tt := range tests { @@ -121,6 +139,24 @@ func TestConvertFrom(t *testing.T) { }, }, }, + { + name: "APIServer LoadBalancer Configuration", + spoke: &OpenStackCluster{}, + hub: &infrav1.OpenStackCluster{ + Spec: infrav1.OpenStackClusterSpec{ + APIServerLoadBalancer: infrav1.APIServerLoadBalancer{ + Enabled: true, + AdditionalPorts: []int{80, 443}, + }, + }, + }, + want: &OpenStackCluster{ + Spec: OpenStackClusterSpec{ + ManagedAPIServerLoadBalancer: true, + APIServerLoadBalancerAdditionalPorts: []int{80, 443}, + }, + }, + }, } for _, tt := range tests { diff --git a/api/v1alpha4/openstackcluster_conversion.go b/api/v1alpha4/openstackcluster_conversion.go index 6d4ec3da2d..5d97000cb3 100644 --- a/api/v1alpha4/openstackcluster_conversion.go +++ b/api/v1alpha4/openstackcluster_conversion.go @@ -17,9 +17,13 @@ limitations under the License. package v1alpha4 import ( + unsafe "unsafe" + "k8s.io/apimachinery/pkg/conversion" clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + + infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" ) // Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint is an autogenerated conversion function. @@ -31,3 +35,17 @@ func Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in *clusterv1alpha4.API func Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in *clusterv1.APIEndpoint, out *clusterv1alpha4.APIEndpoint, s conversion.Scope) error { return clusterv1alpha4.Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in, out, s) } + +func Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s conversion.Scope) error { + out.APIServerLoadBalancer.Enabled = in.ManagedAPIServerLoadBalancer + out.APIServerLoadBalancer.AdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)) + + return autoConvert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s) +} + +func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *infrav1.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error { + out.ManagedAPIServerLoadBalancer = in.APIServerLoadBalancer.Enabled + out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancer.AdditionalPorts)) + + return autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in, out, s) +} diff --git a/api/v1alpha4/zz_generated.conversion.go b/api/v1alpha4/zz_generated.conversion.go index 83cfc3c9c3..ab72440d56 100644 --- a/api/v1alpha4/zz_generated.conversion.go +++ b/api/v1alpha4/zz_generated.conversion.go @@ -120,16 +120,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackClusterSpec)(nil), (*v1beta1.OpenStackClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(a.(*OpenStackClusterSpec), b.(*v1beta1.OpenStackClusterSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.OpenStackClusterSpec)(nil), (*OpenStackClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(a.(*v1beta1.OpenStackClusterSpec), b.(*OpenStackClusterSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackClusterStatus)(nil), (*v1beta1.OpenStackClusterStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_OpenStackClusterStatus_To_v1beta1_OpenStackClusterStatus(a.(*OpenStackClusterStatus), b.(*v1beta1.OpenStackClusterStatus), scope) }); err != nil { @@ -360,6 +350,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OpenStackClusterSpec)(nil), (*v1beta1.OpenStackClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(a.(*OpenStackClusterSpec), b.(*v1beta1.OpenStackClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*OpenStackMachineSpec)(nil), (*v1beta1.OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha4_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(a.(*OpenStackMachineSpec), b.(*v1beta1.OpenStackMachineSpec), scope) }); err != nil { @@ -400,6 +395,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.OpenStackClusterSpec)(nil), (*OpenStackClusterSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(a.(*v1beta1.OpenStackClusterSpec), b.(*OpenStackClusterSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.OpenStackMachineSpec)(nil), (*OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_OpenStackMachineSpec_To_v1alpha4_OpenStackMachineSpec(a.(*v1beta1.OpenStackMachineSpec), b.(*OpenStackMachineSpec), scope) }); err != nil { @@ -810,12 +810,12 @@ func autoConvert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(i out.ExternalRouterIPs = nil } out.ExternalNetworkID = in.ExternalNetworkID - out.ManagedAPIServerLoadBalancer = in.ManagedAPIServerLoadBalancer + // WARNING: in.ManagedAPIServerLoadBalancer requires manual conversion: does not exist in peer-type out.DisableAPIServerFloatingIP = in.DisableAPIServerFloatingIP out.APIServerFloatingIP = in.APIServerFloatingIP out.APIServerFixedIP = in.APIServerFixedIP out.APIServerPort = in.APIServerPort - out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)) + // WARNING: in.APIServerLoadBalancerAdditionalPorts requires manual conversion: does not exist in peer-type out.ManagedSecurityGroups = in.ManagedSecurityGroups out.AllowAllInClusterTraffic = in.AllowAllInClusterTraffic out.DisablePortSecurity = in.DisablePortSecurity @@ -835,11 +835,6 @@ func autoConvert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(i return nil } -// Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec is an autogenerated conversion function. -func Convert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *v1beta1.OpenStackClusterSpec, s conversion.Scope) error { - return autoConvert_v1alpha4_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s) -} - func autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *v1beta1.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error { out.CloudName = in.CloudName out.NodeCIDR = in.NodeCIDR @@ -862,12 +857,11 @@ func autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(i out.ExternalRouterIPs = nil } out.ExternalNetworkID = in.ExternalNetworkID - out.ManagedAPIServerLoadBalancer = in.ManagedAPIServerLoadBalancer + // WARNING: in.APIServerLoadBalancer requires manual conversion: does not exist in peer-type out.DisableAPIServerFloatingIP = in.DisableAPIServerFloatingIP out.APIServerFloatingIP = in.APIServerFloatingIP out.APIServerFixedIP = in.APIServerFixedIP out.APIServerPort = in.APIServerPort - out.APIServerLoadBalancerAdditionalPorts = *(*[]int)(unsafe.Pointer(&in.APIServerLoadBalancerAdditionalPorts)) out.ManagedSecurityGroups = in.ManagedSecurityGroups out.AllowAllInClusterTraffic = in.AllowAllInClusterTraffic out.DisablePortSecurity = in.DisablePortSecurity @@ -887,11 +881,6 @@ func autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(i return nil } -// Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec is an autogenerated conversion function. -func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in *v1beta1.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error { - return autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha4_OpenStackClusterSpec(in, out, s) -} - func autoConvert_v1alpha4_OpenStackClusterStatus_To_v1beta1_OpenStackClusterStatus(in *OpenStackClusterStatus, out *v1beta1.OpenStackClusterStatus, s conversion.Scope) error { out.Ready = in.Ready if in.Network != nil { diff --git a/api/v1beta1/openstackcluster_types.go b/api/v1beta1/openstackcluster_types.go index 2dd0ea526a..da33750ee3 100644 --- a/api/v1beta1/openstackcluster_types.go +++ b/api/v1beta1/openstackcluster_types.go @@ -57,10 +57,10 @@ type OpenStackClusterSpec struct { // +optional ExternalNetworkID string `json:"externalNetworkId,omitempty"` - // ManagedAPIServerLoadBalancer defines whether a LoadBalancer for the - // APIServer should be created. + // APIServerLoadBalancer configures the optional LoadBalancer for the APIServer. + // It must be activated by setting `enabled: true`. // +optional - ManagedAPIServerLoadBalancer bool `json:"managedAPIServerLoadBalancer"` + APIServerLoadBalancer APIServerLoadBalancer `json:"apiServerLoadBalancer,omitempty"` // DisableAPIServerFloatingIP determines whether or not to attempt to attach a floating // IP to the API server. This allows for the creation of clusters when attaching a floating @@ -97,9 +97,6 @@ type OpenStackClusterSpec struct { // will be created APIServerPort int `json:"apiServerPort,omitempty"` - // APIServerLoadBalancerAdditionalPorts adds additional ports to the APIServerLoadBalancer - APIServerLoadBalancerAdditionalPorts []int `json:"apiServerLoadBalancerAdditionalPorts,omitempty"` - // ManagedSecurityGroups determines whether OpenStack security groups for the cluster // will be managed by the OpenStack provider or whether pre-existing security groups will // be specified as part of the configuration. diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index 22c981dcf4..bf5d68aa24 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -296,3 +296,10 @@ type Bastion struct { //+optional AvailabilityZone string `json:"availabilityZone,omitempty"` } + +type APIServerLoadBalancer struct { + // Enabled defines whether a LoadBalancer should be created. + Enabled bool `json:"enabled,omitempty"` + // AdditionalPorts adds additional tcp ports to the Loadbalacner + AdditionalPorts []int `json:"additionalPorts,omitempty"` +} diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index d2c9de389f..98a8d24628 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -28,6 +28,26 @@ import ( "sigs.k8s.io/cluster-api/errors" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIServerLoadBalancer) DeepCopyInto(out *APIServerLoadBalancer) { + *out = *in + if in.AdditionalPorts != nil { + in, out := &in.AdditionalPorts, &out.AdditionalPorts + *out = make([]int, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIServerLoadBalancer. +func (in *APIServerLoadBalancer) DeepCopy() *APIServerLoadBalancer { + if in == nil { + return nil + } + out := new(APIServerLoadBalancer) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AddressPair) DeepCopyInto(out *AddressPair) { *out = *in @@ -317,11 +337,7 @@ func (in *OpenStackClusterSpec) DeepCopyInto(out *OpenStackClusterSpec) { *out = make([]ExternalRouterIPParam, len(*in)) copy(*out, *in) } - if in.APIServerLoadBalancerAdditionalPorts != nil { - in, out := &in.APIServerLoadBalancerAdditionalPorts, &out.APIServerLoadBalancerAdditionalPorts - *out = make([]int, len(*in)) - copy(*out, *in) - } + in.APIServerLoadBalancer.DeepCopyInto(&out.APIServerLoadBalancer) if in.Tags != nil { in, out := &in.Tags, &out.Tags *out = make([]string, len(*in)) 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 f5b3bd5898..5a56c11691 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -2499,12 +2499,21 @@ spec: already exist. If not specified, a new floatingIP is allocated. This field is not used if DisableAPIServerFloatingIP is set to true. type: string - apiServerLoadBalancerAdditionalPorts: - description: APIServerLoadBalancerAdditionalPorts adds additional - ports to the APIServerLoadBalancer - items: - type: integer - type: array + apiServerLoadBalancer: + description: 'APIServerLoadBalancer configures the optional LoadBalancer + for the APIServer. It must be activated by setting `enabled: true`.' + properties: + additionalPorts: + description: AdditionalPorts adds additional tcp ports to the + Loadbalacner + items: + type: integer + type: array + enabled: + description: Enabled defines whether a LoadBalancer should be + created. + type: boolean + type: object apiServerPort: description: APIServerPort is the port on which the listener on the APIServer will be created @@ -2999,10 +3008,6 @@ spec: - kind - name type: object - managedAPIServerLoadBalancer: - description: ManagedAPIServerLoadBalancer defines whether a LoadBalancer - for the APIServer should be created. - type: boolean managedSecurityGroups: description: ManagedSecurityGroups determines whether OpenStack security groups for the cluster will be managed by the OpenStack provider 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 e6b01f4b60..656eecf713 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -764,12 +764,22 @@ spec: a new floatingIP is allocated. This field is not used if DisableAPIServerFloatingIP is set to true. type: string - apiServerLoadBalancerAdditionalPorts: - description: APIServerLoadBalancerAdditionalPorts adds additional - ports to the APIServerLoadBalancer - items: - type: integer - type: array + apiServerLoadBalancer: + description: 'APIServerLoadBalancer configures the optional + LoadBalancer for the APIServer. It must be activated by + setting `enabled: true`.' + properties: + additionalPorts: + description: AdditionalPorts adds additional tcp ports + to the Loadbalacner + items: + type: integer + type: array + enabled: + description: Enabled defines whether a LoadBalancer should + be created. + type: boolean + type: object apiServerPort: description: APIServerPort is the port on which the listener on the APIServer will be created @@ -1283,10 +1293,6 @@ spec: - kind - name type: object - managedAPIServerLoadBalancer: - description: ManagedAPIServerLoadBalancer defines whether - a LoadBalancer for the APIServer should be created. - type: boolean managedSecurityGroups: description: ManagedSecurityGroups determines whether OpenStack security groups for the cluster will be managed by the OpenStack diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index ac23a9aa35..3f5460f7b1 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -141,7 +141,7 @@ func reconcileDelete(ctx context.Context, scope *scope.Scope, patchHelper *patch clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name) - if openStackCluster.Spec.ManagedAPIServerLoadBalancer { + if openStackCluster.Spec.APIServerLoadBalancer.Enabled { loadBalancerService, err := loadbalancer.NewService(scope) if err != nil { return reconcile.Result{}, err @@ -448,7 +448,7 @@ func reconcileNetworkComponents(scope *scope.Scope, cluster *clusterv1.Cluster, apiServerPort = 6443 } - if openStackCluster.Spec.ManagedAPIServerLoadBalancer { + if openStackCluster.Spec.APIServerLoadBalancer.Enabled { loadBalancerService, err := loadbalancer.NewService(scope) if err != nil { return err @@ -465,7 +465,7 @@ func reconcileNetworkComponents(scope *scope.Scope, cluster *clusterv1.Cluster, var host string // If there is a load balancer use the floating IP for it if set, falling back to the internal IP switch { - case openStackCluster.Spec.ManagedAPIServerLoadBalancer: + case openStackCluster.Spec.APIServerLoadBalancer.Enabled: if openStackCluster.Status.Network.APIServerLoadBalancer.IP != "" { host = openStackCluster.Status.Network.APIServerLoadBalancer.IP } else { diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index 37e3d609ad..f91a144aeb 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -212,7 +212,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(ctx context.Context, scope return ctrl.Result{}, err } - if openStackCluster.Spec.ManagedAPIServerLoadBalancer { + if openStackCluster.Spec.APIServerLoadBalancer.Enabled { loadBalancerService, err := loadbalancer.NewService(scope) if err != nil { return ctrl.Result{}, err @@ -228,7 +228,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(ctx context.Context, scope if err != nil { return ctrl.Result{}, err } - if !openStackCluster.Spec.ManagedAPIServerLoadBalancer && util.IsControlPlaneMachine(machine) && openStackCluster.Spec.APIServerFloatingIP == "" { + if !openStackCluster.Spec.APIServerLoadBalancer.Enabled && util.IsControlPlaneMachine(machine) && openStackCluster.Spec.APIServerFloatingIP == "" { if instanceStatus != nil { instanceNS, err := instanceStatus.NetworkStatus() if err != nil { @@ -351,7 +351,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope return ctrl.Result{RequeueAfter: waitForInstanceBecomeActiveToReconcile}, nil } - if openStackCluster.Spec.ManagedAPIServerLoadBalancer { + if openStackCluster.Spec.APIServerLoadBalancer.Enabled { err = r.reconcileLoadBalancerMember(scope, openStackCluster, machine, openStackMachine, instanceNS, clusterName) if err != nil { handleUpdateMachineError(scope.Logger, openStackMachine, errors.Errorf("LoadBalancerMember cannot be reconciled: %v", err)) diff --git a/pkg/cloud/services/loadbalancer/loadbalancer.go b/pkg/cloud/services/loadbalancer/loadbalancer.go index 42b53469f2..719ead1495 100644 --- a/pkg/cloud/services/loadbalancer/loadbalancer.go +++ b/pkg/cloud/services/loadbalancer/loadbalancer.go @@ -82,7 +82,7 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust } portList := []int{apiServerPort} - portList = append(portList, openStackCluster.Spec.APIServerLoadBalancerAdditionalPorts...) + portList = append(portList, openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts...) for _, port := range portList { lbPortObjectsName := fmt.Sprintf("%s-%d", loadBalancerName, port) listener, err := s.getOrCreateListener(openStackCluster, lbPortObjectsName, lb.ID, port) @@ -268,7 +268,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac lbID := openStackCluster.Status.Network.APIServerLoadBalancer.ID portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)} - portList = append(portList, openStackCluster.Spec.APIServerLoadBalancerAdditionalPorts...) + portList = append(portList, openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts...) for _, port := range portList { lbPortObjectsName := fmt.Sprintf("%s-%d", loadBalancerName, port) name := lbPortObjectsName + "-" + openStackMachine.Name @@ -392,7 +392,7 @@ func (s *Service) DeleteLoadBalancerMember(openStackCluster *infrav1.OpenStackCl lbID := lb.ID portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)} - portList = append(portList, openStackCluster.Spec.APIServerLoadBalancerAdditionalPorts...) + portList = append(portList, openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts...) for _, port := range portList { lbPortObjectsName := fmt.Sprintf("%s-%d", loadBalancerName, port) name := lbPortObjectsName + "-" + openStackMachine.Name diff --git a/templates/cluster-template-external-cloud-provider.yaml b/templates/cluster-template-external-cloud-provider.yaml index b7476163f3..be88a33234 100644 --- a/templates/cluster-template-external-cloud-provider.yaml +++ b/templates/cluster-template-external-cloud-provider.yaml @@ -26,7 +26,8 @@ spec: identityRef: name: ${CLUSTER_NAME}-cloud-config kind: Secret - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true nodeCidr: 10.6.0.0/24 dnsNameservers: diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml index d384524841..86fc41342d 100644 --- a/templates/cluster-template.yaml +++ b/templates/cluster-template.yaml @@ -26,7 +26,8 @@ spec: identityRef: name: ${CLUSTER_NAME}-cloud-config kind: Secret - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true nodeCidr: 10.6.0.0/24 dnsNameservers: diff --git a/test/e2e/data/infrastructure-openstack/cluster-template-external-cloud-provider.yaml b/test/e2e/data/infrastructure-openstack/cluster-template-external-cloud-provider.yaml index c7cc2067ea..d87eb4bc2d 100644 --- a/test/e2e/data/infrastructure-openstack/cluster-template-external-cloud-provider.yaml +++ b/test/e2e/data/infrastructure-openstack/cluster-template-external-cloud-provider.yaml @@ -31,7 +31,8 @@ spec: kind: Secret controlPlaneAvailabilityZones: - ${OPENSTACK_FAILURE_DOMAIN} - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true allowAllInClusterTraffic: true nodeCidr: 10.6.0.0/24 diff --git a/test/e2e/data/infrastructure-openstack/cluster-template-multi-az.yaml b/test/e2e/data/infrastructure-openstack/cluster-template-multi-az.yaml index 51ecf3d3d9..2a9278a9ca 100644 --- a/test/e2e/data/infrastructure-openstack/cluster-template-multi-az.yaml +++ b/test/e2e/data/infrastructure-openstack/cluster-template-multi-az.yaml @@ -31,7 +31,8 @@ spec: controlPlaneAvailabilityZones: - ${OPENSTACK_FAILURE_DOMAIN} - ${OPENSTACK_FAILURE_DOMAIN_ALT} - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true nodeCidr: 10.6.0.0/24 dnsNameservers: diff --git a/test/e2e/data/infrastructure-openstack/cluster-template-multi-network.yaml b/test/e2e/data/infrastructure-openstack/cluster-template-multi-network.yaml index 03bf1600e6..b6be426468 100644 --- a/test/e2e/data/infrastructure-openstack/cluster-template-multi-network.yaml +++ b/test/e2e/data/infrastructure-openstack/cluster-template-multi-network.yaml @@ -30,7 +30,8 @@ spec: kind: Secret controlPlaneAvailabilityZones: - ${OPENSTACK_FAILURE_DOMAIN} - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true nodeCidr: 10.6.0.0/24 dnsNameservers: diff --git a/test/e2e/data/infrastructure-openstack/cluster-template.yaml b/test/e2e/data/infrastructure-openstack/cluster-template.yaml index a99aa45a7d..5ad34089bd 100644 --- a/test/e2e/data/infrastructure-openstack/cluster-template.yaml +++ b/test/e2e/data/infrastructure-openstack/cluster-template.yaml @@ -32,7 +32,8 @@ spec: kind: Secret controlPlaneAvailabilityZones: - ${OPENSTACK_FAILURE_DOMAIN} - managedAPIServerLoadBalancer: true + apiServerLoadBalancer: + enabled: true managedSecurityGroups: true nodeCidr: 10.6.0.0/24 dnsNameservers: