Skip to content

Commit d2705b6

Browse files
nguyenhuukhoidulek
authored andcommitted
Add opt to use AZ for APISeverLoadBalancer
1 parent 626738a commit d2705b6

13 files changed

+75
-10
lines changed

api/v1alpha5/zz_generated.conversion.go

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

api/v1alpha6/openstackcluster_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
232232
optional.RestoreBool(&previous.DisableAPIServerFloatingIP, &dst.DisableAPIServerFloatingIP)
233233
optional.RestoreBool(&previous.ControlPlaneOmitAvailabilityZone, &dst.ControlPlaneOmitAvailabilityZone)
234234
optional.RestoreBool(&previous.DisablePortSecurity, &dst.DisablePortSecurity)
235+
236+
restorev1beta1APIServerLoadBalancer(previous.APIServerLoadBalancer, dst.APIServerLoadBalancer)
235237
}
236238

237239
func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s apiconversion.Scope) error {

api/v1alpha6/types_conversion.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ func Convert_v1alpha6_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityG
497497
}
498498

499499
/* SecurityGroupRule */
500-
/* APIServerLoadBalancer */
501500
/* ValueSpec */
502501
/* OpenStackIdentityReference */
503502

@@ -510,6 +509,17 @@ func Convert_v1beta1_OpenStackIdentityReference_To_v1alpha6_OpenStackIdentityRef
510509
return nil
511510
}
512511

512+
/* APIServerLoadBalancer */
513+
514+
func restorev1beta1APIServerLoadBalancer(previous *infrav1.APIServerLoadBalancer, dst *infrav1.APIServerLoadBalancer) {
515+
if dst == nil || previous == nil {
516+
return
517+
}
518+
519+
// AZ doesn't exist in v1alpha6, so always restore.
520+
dst.AvailabilityZone = previous.AvailabilityZone
521+
}
522+
513523
/* Placeholders */
514524

515525
// conversion-gen registers these functions so we must provider stubs, but

api/v1alpha6/zz_generated.conversion.go

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

api/v1alpha7/openstackcluster_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
239239
optional.RestoreBool(&previous.DisableAPIServerFloatingIP, &dst.DisableAPIServerFloatingIP)
240240
optional.RestoreBool(&previous.ControlPlaneOmitAvailabilityZone, &dst.ControlPlaneOmitAvailabilityZone)
241241
optional.RestoreBool(&previous.DisablePortSecurity, &dst.DisablePortSecurity)
242+
243+
restorev1beta1APIServerLoadBalancer(previous.APIServerLoadBalancer, dst.APIServerLoadBalancer)
242244
}
243245

244246
func Convert_v1alpha7_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s apiconversion.Scope) error {

api/v1alpha7/types_conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,17 @@ func Convert_v1beta1_OpenStackIdentityReference_To_v1alpha7_OpenStackIdentityRef
510510
return nil
511511
}
512512

513+
/* APIServerLoadBalancer */
514+
515+
func restorev1beta1APIServerLoadBalancer(previous *infrav1.APIServerLoadBalancer, dst *infrav1.APIServerLoadBalancer) {
516+
if dst == nil || previous == nil {
517+
return
518+
}
519+
520+
// AZ doesn't exist in v1alpha6, so always restore.
521+
dst.AvailabilityZone = previous.AvailabilityZone
522+
}
523+
513524
/* Placeholders */
514525

515526
// conversion-gen registers these functions so we must provider stubs, but

api/v1alpha7/zz_generated.conversion.go

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

api/v1beta1/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,18 @@ type APIServerLoadBalancer struct {
812812
// Network defines which network should the load balancer be allocated on.
813813
//+optional
814814
Network *NetworkParam `json:"network,omitempty"`
815+
815816
// Subnets define which subnets should the load balancer be allocated on.
816817
// It is expected that subnets are located on the network specified in this resource.
817818
// Only the first element is taken into account.
818819
// +optional
819820
// +listType=atomic
820821
// kubebuilder:validation:MaxLength:=2
821822
Subnets []SubnetParam `json:"subnets,omitempty"`
823+
824+
// AvailabilityZone is the failure domain that will be used to create the APIServerLoadBalancer Spec.
825+
//+optional
826+
AvailabilityZone optional.String `json:"availabilityZone,omitempty"`
822827
}
823828

824829
func (s *APIServerLoadBalancer) IsZero() bool {

api/v1beta1/zz_generated.deepcopy.go

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

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

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

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

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

docs/book/src/api/v1beta1/api.md

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

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,21 @@ func (s *Service) getOrCreateAPILoadBalancer(openStackCluster *infrav1.OpenStack
306306

307307
// Choose the selected provider if it is set in cluster spec, if not, omit the field and Octavia will use the default provider.
308308
lbProvider := ""
309-
if openStackCluster.Spec.APIServerLoadBalancer != nil && openStackCluster.Spec.APIServerLoadBalancer.Provider != nil {
310-
for _, v := range providers {
311-
if v.Name == *openStackCluster.Spec.APIServerLoadBalancer.Provider {
312-
lbProvider = v.Name
313-
break
309+
var availabilityZone *string
310+
if openStackCluster.Spec.APIServerLoadBalancer != nil {
311+
if openStackCluster.Spec.APIServerLoadBalancer.Provider != nil {
312+
for _, v := range providers {
313+
if v.Name == *openStackCluster.Spec.APIServerLoadBalancer.Provider {
314+
lbProvider = v.Name
315+
break
316+
}
317+
}
318+
if lbProvider == "" {
319+
record.Warnf(openStackCluster, "OctaviaProviderNotFound", "Provider specified for Octavia not found.")
320+
record.Eventf(openStackCluster, "OctaviaProviderNotFound", "Provider %s specified for Octavia not found, using the default provider.", openStackCluster.Spec.APIServerLoadBalancer.Provider)
314321
}
315322
}
316-
if lbProvider == "" {
317-
record.Warnf(openStackCluster, "OctaviaProviderNotFound", "Provider specified for Octavia not found.")
318-
record.Eventf(openStackCluster, "OctaviaProviderNotFound", "Provider %s specified for Octavia not found, using the default provider.", openStackCluster.Spec.APIServerLoadBalancer.Provider)
319-
}
323+
availabilityZone = openStackCluster.Spec.APIServerLoadBalancer.AvailabilityZone
320324
}
321325

322326
vipAddress, err := getAPIServerVIPAddress(openStackCluster)
@@ -332,6 +336,9 @@ func (s *Service) getOrCreateAPILoadBalancer(openStackCluster *infrav1.OpenStack
332336
Provider: lbProvider,
333337
Tags: openStackCluster.Spec.Tags,
334338
}
339+
if availabilityZone != nil {
340+
lbCreateOpts.AvailabilityZone = *availabilityZone
341+
}
335342
if vipAddress != nil {
336343
lbCreateOpts.VipAddress = *vipAddress
337344
}

0 commit comments

Comments
 (0)