@@ -1132,7 +1132,7 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
1132
1132
}
1133
1133
}
1134
1134
1135
- func getTestLoadBalancer (name , clusterName , identifier * string , service v1.Service , lbSku string ) network.LoadBalancer {
1135
+ func getTestLoadBalancer (name , rgName , clusterName , identifier * string , service v1.Service , lbSku string ) network.LoadBalancer {
1136
1136
lb := network.LoadBalancer {
1137
1137
Name : name ,
1138
1138
Sku : & network.LoadBalancerSku {
@@ -1167,11 +1167,11 @@ func getTestLoadBalancer(name, clusterName, identifier *string, service v1.Servi
1167
1167
Protocol : network .TransportProtocol (strings .Title (
1168
1168
strings .ToLower (string (service .Spec .Ports [0 ].Protocol )))),
1169
1169
FrontendIPConfiguration : & network.SubResource {
1170
- ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/rg /providers/" +
1170
+ ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/" + * rgName + " /providers/" +
1171
1171
"Microsoft.Network/loadBalancers/" + * name + "/frontendIPConfigurations/atest1" ),
1172
1172
},
1173
1173
BackendAddressPool : & network.SubResource {
1174
- ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/rg /providers/" +
1174
+ ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/" + * rgName + " /providers/" +
1175
1175
"Microsoft.Network/loadBalancers/" + * name + "/backendAddressPools/" + * clusterName ),
1176
1176
},
1177
1177
LoadDistribution : network .LoadDistribution ("Default" ),
@@ -1180,7 +1180,7 @@ func getTestLoadBalancer(name, clusterName, identifier *string, service v1.Servi
1180
1180
EnableFloatingIP : to .BoolPtr (true ),
1181
1181
EnableTCPReset : to .BoolPtr (strings .EqualFold (lbSku , "standard" )),
1182
1182
Probe : & network.SubResource {
1183
- ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/rg /providers/Microsoft.Network/loadBalancers/testCluster/probes/atest1-TCP-80" ),
1183
+ ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/" + * rgName + " /providers/Microsoft.Network/loadBalancers/testCluster/probes/atest1-TCP-80" ),
1184
1184
},
1185
1185
},
1186
1186
},
@@ -1192,10 +1192,10 @@ func getTestLoadBalancer(name, clusterName, identifier *string, service v1.Servi
1192
1192
1193
1193
func TestReconcileLoadBalancer (t * testing.T ) {
1194
1194
service1 := getTestService ("test1" , v1 .ProtocolTCP , nil , 80 )
1195
- basicLb1 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service1 , "Basic" )
1195
+ basicLb1 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service1 , "Basic" )
1196
1196
1197
1197
service2 := getTestService ("test1" , v1 .ProtocolTCP , nil , 80 )
1198
- basicLb2 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("testCluster" ), to .StringPtr ("btest1" ), service2 , "Basic" )
1198
+ basicLb2 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("btest1" ), service2 , "Basic" )
1199
1199
basicLb2 .Name = to .StringPtr ("testCluster" )
1200
1200
basicLb2 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1201
1201
{
@@ -1207,7 +1207,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1207
1207
}
1208
1208
1209
1209
service3 := getTestService ("test1" , v1 .ProtocolTCP , nil , 80 )
1210
- modifiedLb1 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service3 , "Basic" )
1210
+ modifiedLb1 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service3 , "Basic" )
1211
1211
modifiedLb1 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1212
1212
{
1213
1213
Name : to .StringPtr ("atest1" ),
@@ -1238,7 +1238,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1238
1238
},
1239
1239
},
1240
1240
}
1241
- expectedLb1 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service3 , "Basic" )
1241
+ expectedLb1 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service3 , "Basic" )
1242
1242
(* expectedLb1 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].DisableOutboundSnat = to .BoolPtr (false )
1243
1243
(* expectedLb1 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].EnableTCPReset = nil
1244
1244
expectedLb1 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
@@ -1258,7 +1258,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1258
1258
}
1259
1259
1260
1260
service4 := getTestService ("test1" , v1 .ProtocolTCP , map [string ]string {"service.beta.kubernetes.io/azure-load-balancer-disable-tcp-reset" : "true" }, 80 )
1261
- existingSLB := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service4 , "Standard" )
1261
+ existingSLB := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service4 , "Standard" )
1262
1262
existingSLB .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1263
1263
{
1264
1264
Name : to .StringPtr ("atest1" ),
@@ -1290,7 +1290,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1290
1290
},
1291
1291
}
1292
1292
1293
- expectedSLb := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service4 , "Standard" )
1293
+ expectedSLb := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service4 , "Standard" )
1294
1294
(* expectedSLb .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].DisableOutboundSnat = to .BoolPtr (true )
1295
1295
(* expectedSLb .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].EnableTCPReset = to .BoolPtr (false )
1296
1296
expectedSLb .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
@@ -1310,7 +1310,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1310
1310
}
1311
1311
1312
1312
service5 := getTestService ("test1" , v1 .ProtocolTCP , nil , 80 )
1313
- slb5 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service5 , "Standard" )
1313
+ slb5 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service5 , "Standard" )
1314
1314
slb5 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1315
1315
{
1316
1316
Name : to .StringPtr ("atest1" ),
@@ -1345,7 +1345,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1345
1345
//change to false to test that reconcilication will fix it
1346
1346
(* slb5 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].EnableTCPReset = to .BoolPtr (false )
1347
1347
1348
- expectedSLb5 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service5 , "Standard" )
1348
+ expectedSLb5 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service5 , "Standard" )
1349
1349
(* expectedSLb5 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].DisableOutboundSnat = to .BoolPtr (true )
1350
1350
expectedSLb5 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1351
1351
{
@@ -1364,10 +1364,10 @@ func TestReconcileLoadBalancer(t *testing.T) {
1364
1364
}
1365
1365
1366
1366
service6 := getTestService ("test1" , v1 .ProtocolUDP , nil , 80 )
1367
- lb6 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service6 , "basic" )
1367
+ lb6 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service6 , "basic" )
1368
1368
lb6 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {}
1369
1369
lb6 .Probes = & []network.Probe {}
1370
- expectedLB6 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service6 , "basic" )
1370
+ expectedLB6 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service6 , "basic" )
1371
1371
expectedLB6 .Probes = & []network.Probe {}
1372
1372
(* expectedLB6 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].Probe = nil
1373
1373
(* expectedLB6 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].EnableTCPReset = nil
@@ -1385,10 +1385,10 @@ func TestReconcileLoadBalancer(t *testing.T) {
1385
1385
service7 := getTestService ("test1" , v1 .ProtocolUDP , nil , 80 )
1386
1386
service7 .Spec .HealthCheckNodePort = 10081
1387
1387
service7 .Spec .ExternalTrafficPolicy = v1 .ServiceExternalTrafficPolicyTypeLocal
1388
- lb7 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service7 , "basic" )
1388
+ lb7 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service7 , "basic" )
1389
1389
lb7 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {}
1390
1390
lb7 .Probes = & []network.Probe {}
1391
- expectedLB7 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service7 , "basic" )
1391
+ expectedLB7 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ), to .StringPtr ("atest1" ), service7 , "basic" )
1392
1392
(* expectedLB7 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].Probe = & network.SubResource {
1393
1393
ID : to .StringPtr ("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/probes/atest1-UDP-80" ),
1394
1394
}
@@ -1417,16 +1417,45 @@ func TestReconcileLoadBalancer(t *testing.T) {
1417
1417
},
1418
1418
}
1419
1419
1420
+ service8 := getTestService ("test1" , v1 .ProtocolTCP , nil , 80 )
1421
+ lb8 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("anotherRG" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service8 , "Standard" )
1422
+ lb8 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {}
1423
+ lb8 .Probes = & []network.Probe {}
1424
+ expectedLB8 := getTestLoadBalancer (to .StringPtr ("testCluster" ), to .StringPtr ("anotherRG" ), to .StringPtr ("testCluster" ), to .StringPtr ("atest1" ), service8 , "Standard" )
1425
+ (* expectedLB8 .LoadBalancerPropertiesFormat .LoadBalancingRules )[0 ].DisableOutboundSnat = to .BoolPtr (false )
1426
+ expectedLB8 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1427
+ {
1428
+ Name : to .StringPtr ("atest1" ),
1429
+ FrontendIPConfigurationPropertiesFormat : & network.FrontendIPConfigurationPropertiesFormat {
1430
+ PublicIPAddress : & network.PublicIPAddress {ID : to .StringPtr ("/subscriptions/subscription/" +
1431
+ "resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/pipName" )},
1432
+ },
1433
+ },
1434
+ }
1435
+ expectedLB8 .Probes = & []network.Probe {
1436
+ {
1437
+ Name : to .StringPtr ("atest1-" + string (service8 .Spec .Ports [0 ].Protocol ) +
1438
+ "-" + strconv .Itoa (int (service7 .Spec .Ports [0 ].Port ))),
1439
+ ProbePropertiesFormat : & network.ProbePropertiesFormat {
1440
+ Port : to .Int32Ptr (10080 ),
1441
+ Protocol : network .ProbeProtocolTCP ,
1442
+ IntervalInSeconds : to .Int32Ptr (5 ),
1443
+ NumberOfProbes : to .Int32Ptr (2 ),
1444
+ },
1445
+ },
1446
+ }
1447
+
1420
1448
testCases := []struct {
1421
- desc string
1422
- service v1.Service
1423
- loadBalancerSku string
1424
- preConfigLBType string
1425
- disableOutboundSnat * bool
1426
- wantLb bool
1427
- existingLB network.LoadBalancer
1428
- expectedLB network.LoadBalancer
1429
- expectedError error
1449
+ desc string
1450
+ service v1.Service
1451
+ loadBalancerSku string
1452
+ preConfigLBType string
1453
+ loadBalancerResourceGroup string
1454
+ disableOutboundSnat * bool
1455
+ wantLb bool
1456
+ existingLB network.LoadBalancer
1457
+ expectedLB network.LoadBalancer
1458
+ expectedError error
1430
1459
}{
1431
1460
{
1432
1461
desc : "reconcileLoadBalancer shall return the lb deeply equal to the existingLB if there's no " +
@@ -1505,6 +1534,16 @@ func TestReconcileLoadBalancer(t *testing.T) {
1505
1534
expectedLB : expectedLB7 ,
1506
1535
expectedError : nil ,
1507
1536
},
1537
+ {
1538
+ desc : "reconcileLoadBalancer in other resource group" ,
1539
+ loadBalancerSku : "standard" ,
1540
+ loadBalancerResourceGroup : "anotherRG" ,
1541
+ service : service8 ,
1542
+ existingLB : lb8 ,
1543
+ wantLb : true ,
1544
+ expectedLB : expectedLB8 ,
1545
+ expectedError : nil ,
1546
+ },
1508
1547
}
1509
1548
1510
1549
for i , test := range testCases {
@@ -1514,6 +1553,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1514
1553
if test .preConfigLBType != "" {
1515
1554
az .Config .PreConfiguredBackendPoolLoadBalancerTypes = test .preConfigLBType
1516
1555
}
1556
+ az .LoadBalancerResourceGroup = test .loadBalancerResourceGroup
1517
1557
1518
1558
clusterResources := getClusterResources (az , 3 , 3 )
1519
1559
test .service .Spec .LoadBalancerIP = "1.2.3.4"
@@ -1528,7 +1568,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
1528
1568
t .Fatalf ("TestCase[%d] meets unexpected error: %v" , i , err )
1529
1569
}
1530
1570
1531
- _ , err = az .LoadBalancerClient .CreateOrUpdate (context .TODO (), "rg" , "lb1" , test .existingLB , "" )
1571
+ _ , err = az .LoadBalancerClient .CreateOrUpdate (context .TODO (), az . getLoadBalancerResourceGroup () , "lb1" , test .existingLB , "" )
1532
1572
if err != nil {
1533
1573
t .Fatalf ("TestCase[%d] meets unexpected error: %v" , i , err )
1534
1574
}
@@ -1557,10 +1597,10 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
1557
1597
})
1558
1598
az .PublicIPAddressesClient = PIPClient
1559
1599
1560
- lb1 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("testCluster" ),
1600
+ lb1 := getTestLoadBalancer (to .StringPtr ("lb1" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1561
1601
to .StringPtr ("test1" ), internalService , "Basic" )
1562
1602
lb1 .FrontendIPConfigurations = nil
1563
- lb2 := getTestLoadBalancer (to .StringPtr ("lb2" ), to .StringPtr ("testCluster" ),
1603
+ lb2 := getTestLoadBalancer (to .StringPtr ("lb2" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1564
1604
to .StringPtr ("test1" ), internalService , "Basic" )
1565
1605
lb2 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1566
1606
{
@@ -1571,7 +1611,7 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
1571
1611
},
1572
1612
},
1573
1613
}
1574
- lb3 := getTestLoadBalancer (to .StringPtr ("lb3" ), to .StringPtr ("testCluster" ),
1614
+ lb3 := getTestLoadBalancer (to .StringPtr ("lb3" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1575
1615
to .StringPtr ("test1" ), internalService , "Basic" )
1576
1616
lb3 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1577
1617
{
@@ -1582,7 +1622,7 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
1582
1622
},
1583
1623
},
1584
1624
}
1585
- lb4 := getTestLoadBalancer (to .StringPtr ("lb4" ), to .StringPtr ("testCluster" ),
1625
+ lb4 := getTestLoadBalancer (to .StringPtr ("lb4" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1586
1626
to .StringPtr ("test1" ), service , "Basic" )
1587
1627
lb4 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1588
1628
{
@@ -1593,7 +1633,7 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
1593
1633
},
1594
1634
},
1595
1635
}
1596
- lb5 := getTestLoadBalancer (to .StringPtr ("lb5" ), to .StringPtr ("testCluster" ),
1636
+ lb5 := getTestLoadBalancer (to .StringPtr ("lb5" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1597
1637
to .StringPtr ("test1" ), service , "Basic" )
1598
1638
lb5 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1599
1639
{
@@ -1604,7 +1644,7 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
1604
1644
},
1605
1645
},
1606
1646
}
1607
- lb6 := getTestLoadBalancer (to .StringPtr ("lb6" ), to .StringPtr ("testCluster" ),
1647
+ lb6 := getTestLoadBalancer (to .StringPtr ("lb6" ), to .StringPtr ("rg" ), to . StringPtr ( " testCluster" ),
1608
1648
to .StringPtr ("test1" ), service , "Basic" )
1609
1649
lb6 .FrontendIPConfigurations = & []network.FrontendIPConfiguration {
1610
1650
{
0 commit comments