From a5c9ef56ba09abde244257b591a13c6517e4588d Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Fri, 6 Dec 2019 16:07:46 +0800 Subject: [PATCH] Fix LoadBalancer rule checking so that no unexpected LoadBalancer updates are made --- .../azure/azure_loadbalancer.go | 2 +- .../azure/azure_loadbalancer_test.go | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go index 001e772e6530..0ffa057edbca 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go @@ -1643,7 +1643,7 @@ func equalLoadBalancingRulePropertiesFormat(s *network.LoadBalancingRuleProperti reflect.DeepEqual(s.EnableTCPReset, t.EnableTCPReset) && reflect.DeepEqual(s.DisableOutboundSnat, t.DisableOutboundSnat) - if wantLB { + if wantLB && s.IdleTimeoutInMinutes != nil && t.IdleTimeoutInMinutes != nil { return properties && reflect.DeepEqual(s.IdleTimeoutInMinutes, t.IdleTimeoutInMinutes) } return properties diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer_test.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer_test.go index 5a5bf4fe59b5..5f4febbea8c4 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer_test.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer_test.go @@ -173,6 +173,40 @@ func TestFindRule(t *testing.T) { }, expected: false, }, + { + msg: "rule names match while idletimeout unmatch should return false", + existingRule: []network.LoadBalancingRule{ + { + Name: to.StringPtr("httpRule"), + LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ + IdleTimeoutInMinutes: to.Int32Ptr(1), + }, + }, + }, + curRule: network.LoadBalancingRule{ + Name: to.StringPtr("httpRule"), + LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ + IdleTimeoutInMinutes: to.Int32Ptr(2), + }, + }, + expected: false, + }, + { + msg: "rule names match while idletimeout nil should return true", + existingRule: []network.LoadBalancingRule{ + { + Name: to.StringPtr("httpRule"), + LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{}, + }, + }, + curRule: network.LoadBalancingRule{ + Name: to.StringPtr("httpRule"), + LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{ + IdleTimeoutInMinutes: to.Int32Ptr(2), + }, + }, + expected: true, + }, { msg: "rule names match while LoadDistribution unmatch should return false", existingRule: []network.LoadBalancingRule{