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

Fix incorrect EnableTCPReset for non-TCP protocols #1090

Merged
merged 1 commit into from
Feb 7, 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
21 changes: 16 additions & 5 deletions pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ func (az *Cloud) getExpectedLBRules(
ports = []v1.ServicePort{}
}

var enableTCPReset *bool
var enableTCPReset, nilTCPReset *bool
if az.useStandardLoadBalancer() {
enableTCPReset = to.BoolPtr(true)
}
Expand Down Expand Up @@ -2076,6 +2076,10 @@ func (az *Cloud) getExpectedLBRules(
loadDistribution = network.LoadDistributionSourceIP
}

tcpReset := enableTCPReset
if port.Protocol != v1.ProtocolTCP {
tcpReset = nilTCPReset
}
expectedRule := network.LoadBalancingRule{
Name: &lbRuleName,
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
Expand All @@ -2090,7 +2094,7 @@ func (az *Cloud) getExpectedLBRules(
FrontendPort: to.Int32Ptr(port.Port),
BackendPort: to.Int32Ptr(port.Port),
DisableOutboundSnat: to.BoolPtr(az.disableLoadBalancerOutboundSNAT()),
EnableTCPReset: enableTCPReset,
EnableTCPReset: tcpReset,
EnableFloatingIP: to.BoolPtr(true),
},
}
Expand Down Expand Up @@ -2874,14 +2878,21 @@ func equalLoadBalancingRulePropertiesFormat(s *network.LoadBalancingRuleProperti
return false
}

properties := reflect.DeepEqual(s.Protocol, t.Protocol) &&
reflect.DeepEqual(s.FrontendIPConfiguration, t.FrontendIPConfiguration) &&
properties := reflect.DeepEqual(s.Protocol, t.Protocol)
if !properties {
return false
}

if reflect.DeepEqual(s.Protocol, network.TransportProtocolTCP) {
properties = properties && reflect.DeepEqual(to.Bool(s.EnableTCPReset), to.Bool(t.EnableTCPReset))
}

properties = properties && reflect.DeepEqual(s.FrontendIPConfiguration, t.FrontendIPConfiguration) &&
reflect.DeepEqual(s.BackendAddressPool, t.BackendAddressPool) &&
reflect.DeepEqual(s.LoadDistribution, t.LoadDistribution) &&
reflect.DeepEqual(s.FrontendPort, t.FrontendPort) &&
reflect.DeepEqual(s.BackendPort, t.BackendPort) &&
reflect.DeepEqual(s.EnableFloatingIP, t.EnableFloatingIP) &&
reflect.DeepEqual(to.Bool(s.EnableTCPReset), to.Bool(t.EnableTCPReset)) &&
reflect.DeepEqual(to.Bool(s.DisableOutboundSnat), to.Bool(t.DisableOutboundSnat))

if wantLB && s.IdleTimeoutInMinutes != nil && t.IdleTimeoutInMinutes != nil {
Expand Down
47 changes: 46 additions & 1 deletion pkg/provider/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
}, false, 80),
loadBalancerSku: "standard",
wantLb: true,
expectedRules: getHATestRules(true, false, v1.ProtocolSCTP),
expectedRules: getHATestRules(false, false, v1.ProtocolSCTP),
},
{
desc: "getExpectedLBRules shall return corresponding probe and lbRule (slb with HA enabled multi-ports services)",
Expand Down Expand Up @@ -4890,3 +4890,48 @@ func Test_getProbeIntervalInSecondsAndNumOfProbe(t *testing.T) {
})
}
}

func TestEqualLoadBalancingRulePropertiesFormat(t *testing.T) {
var enableTCPReset, disableTCPReset *bool = to.BoolPtr(true), to.BoolPtr(false)
var frontPort *int32 = to.Int32Ptr(80)

testcases := []struct {
s *network.LoadBalancingRulePropertiesFormat
t *network.LoadBalancingRulePropertiesFormat
wantLb bool
expected bool
}{
{
s: &network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocolTCP,
EnableTCPReset: enableTCPReset,
FrontendPort: frontPort,
},
t: &network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocolTCP,
EnableTCPReset: enableTCPReset,
FrontendPort: frontPort,
},
wantLb: true,
expected: true,
},
{
s: &network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocolUDP,
EnableTCPReset: disableTCPReset,
FrontendPort: frontPort,
},
t: &network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocolUDP,
EnableTCPReset: enableTCPReset,
FrontendPort: frontPort,
},
wantLb: true,
expected: true,
},
}

for _, tc := range testcases {
assert.Equal(t, tc.expected, equalLoadBalancingRulePropertiesFormat(tc.s, tc.t, tc.wantLb))
}
}