Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set custom backend pool names for load balancers #2714

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/v1alpha4/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.BastionSpec.AzureBastion.Subnet.ServiceEndpoints = restored.Spec.BastionSpec.AzureBastion.Subnet.ServiceEndpoints
}

// Restore load balancers' backend pool name
if restored.Spec.NetworkSpec.APIServerLB.BackendPool.Name != "" {
dst.Spec.NetworkSpec.APIServerLB.BackendPool.Name = restored.Spec.NetworkSpec.APIServerLB.BackendPool.Name
}

if restored.Spec.NetworkSpec.NodeOutboundLB != nil && restored.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name != "" {
dst.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name = restored.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name
}

if restored.Spec.NetworkSpec.ControlPlaneOutboundLB != nil && restored.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name != "" {
dst.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name = restored.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
}
}
}

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateBackendAddressPoolName(lb.Name)
}
}

// SetNodeOutboundLBDefaults sets the default values for the NodeOutboundLB.
Expand Down Expand Up @@ -223,13 +227,19 @@ func (c *AzureCluster) SetNodeOutboundLBDefaults() {
lb := c.Spec.NetworkSpec.NodeOutboundLB
lb.LoadBalancerClassSpec.setNodeOutboundLBDefaults()

lb.Name = c.ObjectMeta.Name
if lb.Name == "" {
lb.Name = c.ObjectMeta.Name
}

if lb.FrontendIPsCount == nil {
lb.FrontendIPsCount = pointer.Int32Ptr(1)
}

c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(lb.Name)
}
}

// SetControlPlaneOutboundLBDefaults sets the default values for the control plane's outbound LB.
Expand All @@ -248,6 +258,10 @@ func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
lb.FrontendIPsCount = pointer.Int32Ptr(1)
}
c.setOutboundLBFrontendIPs(lb, generateControlPlaneOutboundIPName)

if lb.BackendPool.Name == "" {
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
}
}

// setOutboundLBFrontendIPs sets the frontend ips for the given load balancer.
Expand Down Expand Up @@ -431,3 +445,13 @@ func generateNatGatewayIPName(clusterName, subnetName string) string {
func withIndex(name string, n int) string {
return fmt.Sprintf("%s-%d", name, n)
}

// generateBackendAddressPoolName generates a load balancer backend address pool name.
func generateBackendAddressPoolName(lbName string) string {
return fmt.Sprintf("%s-%s", lbName, "backendPool")
}

// generateOutboundBackendAddressPoolName generates a load balancer outbound backend address pool name.
func generateOutboundBackendAddressPoolName(lbName string) string {
return fmt.Sprintf("%s-%s", lbName, "outboundBackendPool")
}
225 changes: 224 additions & 1 deletion api/v1beta1/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@ func TestAPIServerLBDefaults(t *testing.T) {
},
},
},
BackendPool: BackendPool{
Name: "cluster-test-public-lb-backendPool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
Expand Down Expand Up @@ -903,6 +906,57 @@ func TestAPIServerLBDefaults(t *testing.T) {
},
},
},
BackendPool: BackendPool{
Name: "cluster-test-internal-lb-backendPool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Internal,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
},
Name: "cluster-test-internal-lb",
},
},
},
},
},
{
name: "with custom backend pool name",
cluster: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
LoadBalancerClassSpec: LoadBalancerClassSpec{
Type: Internal,
},
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
},
},
},
},
output: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
FrontendIPs: []FrontendIP{
{
Name: "cluster-test-internal-lb-frontEnd",
FrontendIPClass: FrontendIPClass{
PrivateIPAddress: DefaultInternalLBIPAddress,
},
},
},
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Internal,
Expand Down Expand Up @@ -1086,6 +1140,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
Name: "pip-cluster-test-node-outbound",
},
}},
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Expand Down Expand Up @@ -1264,6 +1321,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
Name: "pip-cluster-test-node-outbound",
},
}},
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Expand Down Expand Up @@ -1374,6 +1434,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
},
}},
FrontendIPsCount: to.Int32Ptr(1),
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
Expand Down Expand Up @@ -1544,7 +1607,7 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
},
},
{
name: "NodeOutboundLB declared as input with non-default IdleTimeoutInMinutes and FrontendIPsCount values",
name: "NodeOutboundLB declared as input with non-default IdleTimeoutInMinutes, FrontendIPsCount, BackendPool values",
cluster: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
Expand All @@ -1554,6 +1617,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Public}},
NodeOutboundLB: &LoadBalancerSpec{
FrontendIPsCount: to.Int32Ptr(2),
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
},
Expand Down Expand Up @@ -1587,6 +1653,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
},
},
},
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
FrontendIPsCount: to.Int32Ptr(2), // we expect the original value to be respected here
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Expand All @@ -1599,6 +1668,102 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
},
},
},
{
name: "ensure that existing lb names are not overwritten",
cluster: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
Name: "user-defined-name",
LoadBalancerClassSpec: LoadBalancerClassSpec{
Type: Public,
},
},
Subnets: Subnets{
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetControlPlane,
Name: "control-plane-subnet",
},
SecurityGroup: SecurityGroup{},
RouteTable: RouteTable{},
},
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetNode,
Name: "node-subnet",
},
SecurityGroup: SecurityGroup{},
RouteTable: RouteTable{},
},
},
ControlPlaneOutboundLB: &LoadBalancerSpec{
Name: "user-defined-name",
},
NodeOutboundLB: &LoadBalancerSpec{
Name: "user-defined-name",
},
},
},
},
output: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
Subnets: Subnets{
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetControlPlane,
Name: "control-plane-subnet",
},
SecurityGroup: SecurityGroup{},
RouteTable: RouteTable{},
},
{
SubnetClassSpec: SubnetClassSpec{
Role: SubnetNode,
Name: "node-subnet",
},
SecurityGroup: SecurityGroup{},
RouteTable: RouteTable{},
},
},
APIServerLB: LoadBalancerSpec{
Name: "user-defined-name",
LoadBalancerClassSpec: LoadBalancerClassSpec{
Type: Public,
},
},
NodeOutboundLB: &LoadBalancerSpec{
Name: "user-defined-name",
FrontendIPs: []FrontendIP{{
Name: "user-defined-name-frontEnd",
PublicIP: &PublicIPSpec{
Name: "pip-cluster-test-node-outbound",
},
}},
BackendPool: BackendPool{
Name: "user-defined-name-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
ControlPlaneOutboundLB: &LoadBalancerSpec{
Name: "user-defined-name",
},
},
},
},
},
}

for _, c := range cases {
Expand Down Expand Up @@ -1706,6 +1871,9 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
},
ControlPlaneOutboundLB: &LoadBalancerSpec{
Name: "cluster-test-outbound-lb",
BackendPool: BackendPool{
Name: "cluster-test-outbound-lb-outboundBackendPool",
},
FrontendIPs: []FrontendIP{
{
Name: "cluster-test-outbound-lb-frontEnd-1",
Expand All @@ -1731,6 +1899,61 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
},
},
},
{
name: "custom outbound lb backend pool",
cluster: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Internal}},
ControlPlaneOutboundLB: &LoadBalancerSpec{
BackendPool: BackendPool{
Name: "custom-outbound-lb",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
},
},
},
},
},
output: &AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
LoadBalancerClassSpec: LoadBalancerClassSpec{
Type: Internal,
},
},
ControlPlaneOutboundLB: &LoadBalancerSpec{
Name: "cluster-test-outbound-lb",
BackendPool: BackendPool{
Name: "custom-outbound-lb",
},
FrontendIPs: []FrontendIP{
{
Name: "cluster-test-outbound-lb-frontEnd",
PublicIP: &PublicIPSpec{
Name: "pip-cluster-test-controlplane-outbound",
},
},
},
FrontendIPsCount: to.Int32Ptr(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(15),
},
},
},
},
},
},
}

for _, c := range cases {
Expand Down
Loading