Merge pull request #99825 from feiskyer/fix-ha-rule

Ensure only one LoadBalancer rule is created when HA mode is enabled
This commit is contained in:
Kubernetes Prow Robot 2021-03-10 19:04:23 -08:00 committed by GitHub
commit 20bc36c34d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View File

@ -1626,7 +1626,13 @@ func (az *Cloud) reconcileLoadBalancerRule(
var expectedProbes []network.Probe
var expectedRules []network.LoadBalancingRule
highAvailabilityPortsEnabled := false
for _, port := range ports {
if highAvailabilityPortsEnabled {
// Since the port is always 0 when enabling HA, only one rule should be configured.
break
}
lbRuleName := az.getLoadBalancerRuleName(service, port.Protocol, port.Port)
klog.V(2).Infof("reconcileLoadBalancerRule lb name (%s) rule name (%s)", lbName, lbRuleName)
@ -1714,6 +1720,7 @@ func (az *Cloud) reconcileLoadBalancerRule(
expectedRule.FrontendPort = to.Int32Ptr(0)
expectedRule.BackendPort = to.Int32Ptr(0)
expectedRule.Protocol = network.TransportProtocolAll
highAvailabilityPortsEnabled = true
}
// we didn't construct the probe objects for UDP or SCTP because they're not allowed on Azure.

View File

@ -1592,6 +1592,28 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
expectedProbes: getDefaultTestProbes("http", "/healthy"),
expectedRules: getDefaultTestRules(true),
},
{
desc: "reconcileLoadBalancerRule shall return corresponding probe and lbRule (slb with HA enabled)",
service: getTestService("test1", v1.ProtocolTCP, map[string]string{
"service.beta.kubernetes.io/azure-load-balancer-enable-high-availability-ports": "true",
"service.beta.kubernetes.io/azure-load-balancer-internal": "true",
}, false, 80),
loadBalancerSku: "standard",
wantLb: true,
expectedProbes: getDefaultTestProbes("Tcp", ""),
expectedRules: getHATestRules(true),
},
{
desc: "reconcileLoadBalancerRule shall return corresponding probe and lbRule (slb with HA enabled multi-ports services)",
service: getTestService("test1", v1.ProtocolTCP, map[string]string{
"service.beta.kubernetes.io/azure-load-balancer-enable-high-availability-ports": "true",
"service.beta.kubernetes.io/azure-load-balancer-internal": "true",
}, false, 80, 8080),
loadBalancerSku: "standard",
wantLb: true,
expectedProbes: getDefaultTestProbes("Tcp", ""),
expectedRules: getHATestRules(true),
},
}
for i, test := range testCases {
az := GetTestCloud(ctrl)
@ -1665,6 +1687,37 @@ func getDefaultTestRules(enableTCPReset bool) []network.LoadBalancingRule {
return expectedRules
}
func getHATestRules(enableTCPReset bool) []network.LoadBalancingRule {
expectedRules := []network.LoadBalancingRule{
{
Name: to.StringPtr("atest1-TCP-80"),
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocol("All"),
FrontendIPConfiguration: &network.SubResource{
ID: to.StringPtr("frontendIPConfigID"),
},
BackendAddressPool: &network.SubResource{
ID: to.StringPtr("backendPoolID"),
},
LoadDistribution: "Default",
FrontendPort: to.Int32Ptr(0),
BackendPort: to.Int32Ptr(0),
EnableFloatingIP: to.BoolPtr(true),
DisableOutboundSnat: to.BoolPtr(false),
IdleTimeoutInMinutes: to.Int32Ptr(0),
Probe: &network.SubResource{
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/" +
"Microsoft.Network/loadBalancers/lbname/probes/atest1-TCP-80"),
},
},
},
}
if enableTCPReset {
expectedRules[0].EnableTCPReset = to.BoolPtr(true)
}
return expectedRules
}
func getTestLoadBalancer(name, rgName, clusterName, identifier *string, service v1.Service, lbSku string) network.LoadBalancer {
lb := network.LoadBalancer{
Name: name,