Skip to content

Commit

Permalink
Fix incorrect EnableTCPReset for non-TCP protocols
Browse files Browse the repository at this point in the history
Signed-off-by: Zhecheng Li <zhechengli@microsoft.com>
  • Loading branch information
lzhecheng committed Feb 11, 2022
1 parent fb26256 commit 874971c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
Expand Up @@ -1700,6 +1700,10 @@ func (az *Cloud) reconcileLoadBalancerRule(
loadDistribution = network.LoadDistributionSourceIP
}

tcpReset := enableTCPReset
if port.Protocol != v1.ProtocolTCP {
tcpReset = nil
}
expectedRule := network.LoadBalancingRule{
Name: &lbRuleName,
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
Expand All @@ -1714,7 +1718,7 @@ func (az *Cloud) reconcileLoadBalancerRule(
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 @@ -2409,14 +2413,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
Expand Up @@ -3909,3 +3909,48 @@ func TestEnsurePIPTagged(t *testing.T) {
assert.Equal(t, expectedPIP, pip)
})
}

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))
}
}

0 comments on commit 874971c

Please sign in to comment.