Skip to content

Commit 0d2bbb9

Browse files
authored
Merge pull request #2714 from Fedosin/backendpool
Allow to set custom backend pool names for load balancers
2 parents 405b0ac + 379123e commit 0d2bbb9

10 files changed

Lines changed: 468 additions & 5 deletions

api/v1alpha3/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/v1alpha4/azurecluster_conversion.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error {
9191
dst.Spec.BastionSpec.AzureBastion.Subnet.ServiceEndpoints = restored.Spec.BastionSpec.AzureBastion.Subnet.ServiceEndpoints
9292
}
9393

94+
// Restore load balancers' backend pool name
95+
if restored.Spec.NetworkSpec.APIServerLB.BackendPool.Name != "" {
96+
dst.Spec.NetworkSpec.APIServerLB.BackendPool.Name = restored.Spec.NetworkSpec.APIServerLB.BackendPool.Name
97+
}
98+
99+
if restored.Spec.NetworkSpec.NodeOutboundLB != nil && restored.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name != "" {
100+
dst.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name = restored.Spec.NetworkSpec.NodeOutboundLB.BackendPool.Name
101+
}
102+
103+
if restored.Spec.NetworkSpec.ControlPlaneOutboundLB != nil && restored.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name != "" {
104+
dst.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name = restored.Spec.NetworkSpec.ControlPlaneOutboundLB.BackendPool.Name
105+
}
106+
94107
return nil
95108
}
96109

api/v1alpha4/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/azurecluster_default.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
193193
}
194194
}
195195
}
196+
197+
if lb.BackendPool.Name == "" {
198+
lb.BackendPool.Name = generateBackendAddressPoolName(lb.Name)
199+
}
196200
}
197201

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

226-
lb.Name = c.ObjectMeta.Name
230+
if lb.Name == "" {
231+
lb.Name = c.ObjectMeta.Name
232+
}
227233

228234
if lb.FrontendIPsCount == nil {
229235
lb.FrontendIPsCount = pointer.Int32Ptr(1)
230236
}
231237

232238
c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)
239+
240+
if lb.BackendPool.Name == "" {
241+
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(lb.Name)
242+
}
233243
}
234244

235245
// SetControlPlaneOutboundLBDefaults sets the default values for the control plane's outbound LB.
@@ -248,6 +258,10 @@ func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
248258
lb.FrontendIPsCount = pointer.Int32Ptr(1)
249259
}
250260
c.setOutboundLBFrontendIPs(lb, generateControlPlaneOutboundIPName)
261+
262+
if lb.BackendPool.Name == "" {
263+
lb.BackendPool.Name = generateOutboundBackendAddressPoolName(generateControlPlaneOutboundLBName(c.ObjectMeta.Name))
264+
}
251265
}
252266

253267
// setOutboundLBFrontendIPs sets the frontend ips for the given load balancer.
@@ -431,3 +445,13 @@ func generateNatGatewayIPName(clusterName, subnetName string) string {
431445
func withIndex(name string, n int) string {
432446
return fmt.Sprintf("%s-%d", name, n)
433447
}
448+
449+
// generateBackendAddressPoolName generates a load balancer backend address pool name.
450+
func generateBackendAddressPoolName(lbName string) string {
451+
return fmt.Sprintf("%s-%s", lbName, "backendPool")
452+
}
453+
454+
// generateOutboundBackendAddressPoolName generates a load balancer outbound backend address pool name.
455+
func generateOutboundBackendAddressPoolName(lbName string) string {
456+
return fmt.Sprintf("%s-%s", lbName, "outboundBackendPool")
457+
}

api/v1beta1/azurecluster_default_test.go

Lines changed: 224 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,9 @@ func TestAPIServerLBDefaults(t *testing.T) {
862862
},
863863
},
864864
},
865+
BackendPool: BackendPool{
866+
Name: "cluster-test-public-lb-backendPool",
867+
},
865868
LoadBalancerClassSpec: LoadBalancerClassSpec{
866869
SKU: SKUStandard,
867870
Type: Public,
@@ -903,6 +906,57 @@ func TestAPIServerLBDefaults(t *testing.T) {
903906
},
904907
},
905908
},
909+
BackendPool: BackendPool{
910+
Name: "cluster-test-internal-lb-backendPool",
911+
},
912+
LoadBalancerClassSpec: LoadBalancerClassSpec{
913+
SKU: SKUStandard,
914+
Type: Internal,
915+
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
916+
},
917+
Name: "cluster-test-internal-lb",
918+
},
919+
},
920+
},
921+
},
922+
},
923+
{
924+
name: "with custom backend pool name",
925+
cluster: &AzureCluster{
926+
ObjectMeta: metav1.ObjectMeta{
927+
Name: "cluster-test",
928+
},
929+
Spec: AzureClusterSpec{
930+
NetworkSpec: NetworkSpec{
931+
APIServerLB: LoadBalancerSpec{
932+
LoadBalancerClassSpec: LoadBalancerClassSpec{
933+
Type: Internal,
934+
},
935+
BackendPool: BackendPool{
936+
Name: "custom-backend-pool",
937+
},
938+
},
939+
},
940+
},
941+
},
942+
output: &AzureCluster{
943+
ObjectMeta: metav1.ObjectMeta{
944+
Name: "cluster-test",
945+
},
946+
Spec: AzureClusterSpec{
947+
NetworkSpec: NetworkSpec{
948+
APIServerLB: LoadBalancerSpec{
949+
FrontendIPs: []FrontendIP{
950+
{
951+
Name: "cluster-test-internal-lb-frontEnd",
952+
FrontendIPClass: FrontendIPClass{
953+
PrivateIPAddress: DefaultInternalLBIPAddress,
954+
},
955+
},
956+
},
957+
BackendPool: BackendPool{
958+
Name: "custom-backend-pool",
959+
},
906960
LoadBalancerClassSpec: LoadBalancerClassSpec{
907961
SKU: SKUStandard,
908962
Type: Internal,
@@ -1086,6 +1140,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
10861140
Name: "pip-cluster-test-node-outbound",
10871141
},
10881142
}},
1143+
BackendPool: BackendPool{
1144+
Name: "cluster-test-outboundBackendPool",
1145+
},
10891146
FrontendIPsCount: to.Int32Ptr(1),
10901147
LoadBalancerClassSpec: LoadBalancerClassSpec{
10911148
SKU: SKUStandard,
@@ -1264,6 +1321,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
12641321
Name: "pip-cluster-test-node-outbound",
12651322
},
12661323
}},
1324+
BackendPool: BackendPool{
1325+
Name: "cluster-test-outboundBackendPool",
1326+
},
12671327
FrontendIPsCount: to.Int32Ptr(1),
12681328
LoadBalancerClassSpec: LoadBalancerClassSpec{
12691329
SKU: SKUStandard,
@@ -1374,6 +1434,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
13741434
},
13751435
}},
13761436
FrontendIPsCount: to.Int32Ptr(1),
1437+
BackendPool: BackendPool{
1438+
Name: "cluster-test-outboundBackendPool",
1439+
},
13771440
LoadBalancerClassSpec: LoadBalancerClassSpec{
13781441
SKU: SKUStandard,
13791442
Type: Public,
@@ -1544,7 +1607,7 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
15441607
},
15451608
},
15461609
{
1547-
name: "NodeOutboundLB declared as input with non-default IdleTimeoutInMinutes and FrontendIPsCount values",
1610+
name: "NodeOutboundLB declared as input with non-default IdleTimeoutInMinutes, FrontendIPsCount, BackendPool values",
15481611
cluster: &AzureCluster{
15491612
ObjectMeta: metav1.ObjectMeta{
15501613
Name: "cluster-test",
@@ -1554,6 +1617,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
15541617
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Public}},
15551618
NodeOutboundLB: &LoadBalancerSpec{
15561619
FrontendIPsCount: to.Int32Ptr(2),
1620+
BackendPool: BackendPool{
1621+
Name: "custom-backend-pool",
1622+
},
15571623
LoadBalancerClassSpec: LoadBalancerClassSpec{
15581624
IdleTimeoutInMinutes: to.Int32Ptr(15),
15591625
},
@@ -1587,6 +1653,9 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
15871653
},
15881654
},
15891655
},
1656+
BackendPool: BackendPool{
1657+
Name: "custom-backend-pool",
1658+
},
15901659
FrontendIPsCount: to.Int32Ptr(2), // we expect the original value to be respected here
15911660
LoadBalancerClassSpec: LoadBalancerClassSpec{
15921661
SKU: SKUStandard,
@@ -1599,6 +1668,102 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
15991668
},
16001669
},
16011670
},
1671+
{
1672+
name: "ensure that existing lb names are not overwritten",
1673+
cluster: &AzureCluster{
1674+
ObjectMeta: metav1.ObjectMeta{
1675+
Name: "cluster-test",
1676+
},
1677+
Spec: AzureClusterSpec{
1678+
NetworkSpec: NetworkSpec{
1679+
APIServerLB: LoadBalancerSpec{
1680+
Name: "user-defined-name",
1681+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1682+
Type: Public,
1683+
},
1684+
},
1685+
Subnets: Subnets{
1686+
{
1687+
SubnetClassSpec: SubnetClassSpec{
1688+
Role: SubnetControlPlane,
1689+
Name: "control-plane-subnet",
1690+
},
1691+
SecurityGroup: SecurityGroup{},
1692+
RouteTable: RouteTable{},
1693+
},
1694+
{
1695+
SubnetClassSpec: SubnetClassSpec{
1696+
Role: SubnetNode,
1697+
Name: "node-subnet",
1698+
},
1699+
SecurityGroup: SecurityGroup{},
1700+
RouteTable: RouteTable{},
1701+
},
1702+
},
1703+
ControlPlaneOutboundLB: &LoadBalancerSpec{
1704+
Name: "user-defined-name",
1705+
},
1706+
NodeOutboundLB: &LoadBalancerSpec{
1707+
Name: "user-defined-name",
1708+
},
1709+
},
1710+
},
1711+
},
1712+
output: &AzureCluster{
1713+
ObjectMeta: metav1.ObjectMeta{
1714+
Name: "cluster-test",
1715+
},
1716+
Spec: AzureClusterSpec{
1717+
NetworkSpec: NetworkSpec{
1718+
Subnets: Subnets{
1719+
{
1720+
SubnetClassSpec: SubnetClassSpec{
1721+
Role: SubnetControlPlane,
1722+
Name: "control-plane-subnet",
1723+
},
1724+
SecurityGroup: SecurityGroup{},
1725+
RouteTable: RouteTable{},
1726+
},
1727+
{
1728+
SubnetClassSpec: SubnetClassSpec{
1729+
Role: SubnetNode,
1730+
Name: "node-subnet",
1731+
},
1732+
SecurityGroup: SecurityGroup{},
1733+
RouteTable: RouteTable{},
1734+
},
1735+
},
1736+
APIServerLB: LoadBalancerSpec{
1737+
Name: "user-defined-name",
1738+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1739+
Type: Public,
1740+
},
1741+
},
1742+
NodeOutboundLB: &LoadBalancerSpec{
1743+
Name: "user-defined-name",
1744+
FrontendIPs: []FrontendIP{{
1745+
Name: "user-defined-name-frontEnd",
1746+
PublicIP: &PublicIPSpec{
1747+
Name: "pip-cluster-test-node-outbound",
1748+
},
1749+
}},
1750+
BackendPool: BackendPool{
1751+
Name: "user-defined-name-outboundBackendPool",
1752+
},
1753+
FrontendIPsCount: to.Int32Ptr(1),
1754+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1755+
SKU: SKUStandard,
1756+
Type: Public,
1757+
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
1758+
},
1759+
},
1760+
ControlPlaneOutboundLB: &LoadBalancerSpec{
1761+
Name: "user-defined-name",
1762+
},
1763+
},
1764+
},
1765+
},
1766+
},
16021767
}
16031768

16041769
for _, c := range cases {
@@ -1706,6 +1871,9 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
17061871
},
17071872
ControlPlaneOutboundLB: &LoadBalancerSpec{
17081873
Name: "cluster-test-outbound-lb",
1874+
BackendPool: BackendPool{
1875+
Name: "cluster-test-outbound-lb-outboundBackendPool",
1876+
},
17091877
FrontendIPs: []FrontendIP{
17101878
{
17111879
Name: "cluster-test-outbound-lb-frontEnd-1",
@@ -1731,6 +1899,61 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
17311899
},
17321900
},
17331901
},
1902+
{
1903+
name: "custom outbound lb backend pool",
1904+
cluster: &AzureCluster{
1905+
ObjectMeta: metav1.ObjectMeta{
1906+
Name: "cluster-test",
1907+
},
1908+
Spec: AzureClusterSpec{
1909+
NetworkSpec: NetworkSpec{
1910+
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Internal}},
1911+
ControlPlaneOutboundLB: &LoadBalancerSpec{
1912+
BackendPool: BackendPool{
1913+
Name: "custom-outbound-lb",
1914+
},
1915+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1916+
IdleTimeoutInMinutes: to.Int32Ptr(15),
1917+
},
1918+
},
1919+
},
1920+
},
1921+
},
1922+
output: &AzureCluster{
1923+
ObjectMeta: metav1.ObjectMeta{
1924+
Name: "cluster-test",
1925+
},
1926+
Spec: AzureClusterSpec{
1927+
NetworkSpec: NetworkSpec{
1928+
APIServerLB: LoadBalancerSpec{
1929+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1930+
Type: Internal,
1931+
},
1932+
},
1933+
ControlPlaneOutboundLB: &LoadBalancerSpec{
1934+
Name: "cluster-test-outbound-lb",
1935+
BackendPool: BackendPool{
1936+
Name: "custom-outbound-lb",
1937+
},
1938+
FrontendIPs: []FrontendIP{
1939+
{
1940+
Name: "cluster-test-outbound-lb-frontEnd",
1941+
PublicIP: &PublicIPSpec{
1942+
Name: "pip-cluster-test-controlplane-outbound",
1943+
},
1944+
},
1945+
},
1946+
FrontendIPsCount: to.Int32Ptr(1),
1947+
LoadBalancerClassSpec: LoadBalancerClassSpec{
1948+
SKU: SKUStandard,
1949+
Type: Public,
1950+
IdleTimeoutInMinutes: to.Int32Ptr(15),
1951+
},
1952+
},
1953+
},
1954+
},
1955+
},
1956+
},
17341957
}
17351958

17361959
for _, c := range cases {

0 commit comments

Comments
 (0)