mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
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:
commit
20bc36c34d
@ -1626,7 +1626,13 @@ func (az *Cloud) reconcileLoadBalancerRule(
|
|||||||
|
|
||||||
var expectedProbes []network.Probe
|
var expectedProbes []network.Probe
|
||||||
var expectedRules []network.LoadBalancingRule
|
var expectedRules []network.LoadBalancingRule
|
||||||
|
highAvailabilityPortsEnabled := false
|
||||||
for _, port := range ports {
|
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)
|
lbRuleName := az.getLoadBalancerRuleName(service, port.Protocol, port.Port)
|
||||||
klog.V(2).Infof("reconcileLoadBalancerRule lb name (%s) rule name (%s)", lbName, lbRuleName)
|
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.FrontendPort = to.Int32Ptr(0)
|
||||||
expectedRule.BackendPort = to.Int32Ptr(0)
|
expectedRule.BackendPort = to.Int32Ptr(0)
|
||||||
expectedRule.Protocol = network.TransportProtocolAll
|
expectedRule.Protocol = network.TransportProtocolAll
|
||||||
|
highAvailabilityPortsEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// we didn't construct the probe objects for UDP or SCTP because they're not allowed on Azure.
|
// we didn't construct the probe objects for UDP or SCTP because they're not allowed on Azure.
|
||||||
|
@ -1592,6 +1592,28 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
|
|||||||
expectedProbes: getDefaultTestProbes("http", "/healthy"),
|
expectedProbes: getDefaultTestProbes("http", "/healthy"),
|
||||||
expectedRules: getDefaultTestRules(true),
|
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 {
|
for i, test := range testCases {
|
||||||
az := GetTestCloud(ctrl)
|
az := GetTestCloud(ctrl)
|
||||||
@ -1665,6 +1687,37 @@ func getDefaultTestRules(enableTCPReset bool) []network.LoadBalancingRule {
|
|||||||
return expectedRules
|
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 {
|
func getTestLoadBalancer(name, rgName, clusterName, identifier *string, service v1.Service, lbSku string) network.LoadBalancer {
|
||||||
lb := network.LoadBalancer{
|
lb := network.LoadBalancer{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
Loading…
Reference in New Issue
Block a user