Merge pull request #107981 from lzhecheng/fix-enabletcpreset
Cherry-pick: Fix incorrect EnableTCPReset for non-TCP protocols
This commit is contained in:
		| @@ -1700,6 +1700,10 @@ func (az *Cloud) reconcileLoadBalancerRule( | |||||||
| 			loadDistribution = network.LoadDistributionSourceIP | 			loadDistribution = network.LoadDistributionSourceIP | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		tcpReset := enableTCPReset | ||||||
|  | 		if port.Protocol != v1.ProtocolTCP { | ||||||
|  | 			tcpReset = nil | ||||||
|  | 		} | ||||||
| 		expectedRule := network.LoadBalancingRule{ | 		expectedRule := network.LoadBalancingRule{ | ||||||
| 			Name: &lbRuleName, | 			Name: &lbRuleName, | ||||||
| 			LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ | 			LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ | ||||||
| @@ -1714,7 +1718,7 @@ func (az *Cloud) reconcileLoadBalancerRule( | |||||||
| 				FrontendPort:        to.Int32Ptr(port.Port), | 				FrontendPort:        to.Int32Ptr(port.Port), | ||||||
| 				BackendPort:         to.Int32Ptr(port.Port), | 				BackendPort:         to.Int32Ptr(port.Port), | ||||||
| 				DisableOutboundSnat: to.BoolPtr(az.disableLoadBalancerOutboundSNAT()), | 				DisableOutboundSnat: to.BoolPtr(az.disableLoadBalancerOutboundSNAT()), | ||||||
| 				EnableTCPReset:      enableTCPReset, | 				EnableTCPReset:      tcpReset, | ||||||
| 				EnableFloatingIP:    to.BoolPtr(true), | 				EnableFloatingIP:    to.BoolPtr(true), | ||||||
| 			}, | 			}, | ||||||
| 		} | 		} | ||||||
| @@ -2409,14 +2413,21 @@ func equalLoadBalancingRulePropertiesFormat(s *network.LoadBalancingRuleProperti | |||||||
| 		return false | 		return false | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	properties := reflect.DeepEqual(s.Protocol, t.Protocol) && | 	properties := reflect.DeepEqual(s.Protocol, t.Protocol) | ||||||
| 		reflect.DeepEqual(s.FrontendIPConfiguration, t.FrontendIPConfiguration) && | 	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.BackendAddressPool, t.BackendAddressPool) && | ||||||
| 		reflect.DeepEqual(s.LoadDistribution, t.LoadDistribution) && | 		reflect.DeepEqual(s.LoadDistribution, t.LoadDistribution) && | ||||||
| 		reflect.DeepEqual(s.FrontendPort, t.FrontendPort) && | 		reflect.DeepEqual(s.FrontendPort, t.FrontendPort) && | ||||||
| 		reflect.DeepEqual(s.BackendPort, t.BackendPort) && | 		reflect.DeepEqual(s.BackendPort, t.BackendPort) && | ||||||
| 		reflect.DeepEqual(s.EnableFloatingIP, t.EnableFloatingIP) && | 		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)) | 		reflect.DeepEqual(to.Bool(s.DisableOutboundSnat), to.Bool(t.DisableOutboundSnat)) | ||||||
|  |  | ||||||
| 	if wantLB && s.IdleTimeoutInMinutes != nil && t.IdleTimeoutInMinutes != nil { | 	if wantLB && s.IdleTimeoutInMinutes != nil && t.IdleTimeoutInMinutes != nil { | ||||||
|   | |||||||
| @@ -3909,3 +3909,48 @@ func TestEnsurePIPTagged(t *testing.T) { | |||||||
| 		assert.Equal(t, expectedPIP, pip) | 		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)) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot