From d7f14fb38e43bd605a6335b514f69e612dd8c5be Mon Sep 17 00:00:00 2001 From: Anders Liu Date: Sat, 14 Dec 2019 22:19:05 -0800 Subject: [PATCH] fix: address test failure and review comments --- .../legacy-cloud-providers/azure/azure_standard.go | 10 ++++++---- .../azure/azure_standard_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go index 57c24954797..fab3e4f112f 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go @@ -66,6 +66,8 @@ const ( nicFailedState = "Failed" storageAccountNameMaxLength = 24 + frontendIPConfigNameMaxLength = 80 + loadBalancerRuleNameMaxLength = 80 ) var errNotInVMSet = errors.New("vm is not in the vmset") @@ -283,8 +285,8 @@ func (az *Cloud) getLoadBalancerRuleName(service *v1.Service, protocol v1.Protoc // Load balancer rule name must be less or equal to 80 charactors, so excluding the hyphen two segments cannot exceed 79 subnetSegment := *subnet - if len(ruleName) + len(subnetSegment) > 79 { - subnetSegment = subnetSegment[:79 - len(ruleName)] + if len(ruleName) + len(subnetSegment) + 1 > loadBalancerRuleNameMaxLength { + subnetSegment = subnetSegment[:loadBalancerRuleNameMaxLength - len(ruleName) - 1] } return fmt.Sprintf("%s-%s-%s-%d", prefix, subnetSegment, protocol, port) @@ -332,8 +334,8 @@ func (az *Cloud) getFrontendIPConfigName(service *v1.Service) string { ipcName := fmt.Sprintf("%s-%s", baseName, *subnetName) // Azure lb front end configuration name must not exceed 80 charactors - if len(ipcName) > 80 { - ipcName = ipcName[:80] + if len(ipcName) > frontendIPConfigNameMaxLength { + ipcName = ipcName[:frontendIPConfigNameMaxLength] } return ipcName } diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard_test.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard_test.go index d1af5ba7193..c8805fb75d3 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard_test.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard_test.go @@ -336,7 +336,7 @@ func TestGetLoadBalancingRuleName(t *testing.T) { } } -func TestgetFrontendIPConfigName(t *testing.T) { +func TestGetFrontendIPConfigName(t *testing.T) { az := getTestCloud() az.PrimaryAvailabilitySetName = "primary" @@ -369,14 +369,14 @@ func TestgetFrontendIPConfigName(t *testing.T) { subnetName: "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet", isInternal: true, useStandardLB: true, - expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg", + expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg", }, { description: "internal basic lb should have subnet name on the frontend ip configuration name but truncated to 80 charactors", subnetName: "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet", isInternal: true, useStandardLB: false, - expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg", + expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg", }, { description: "external standard lb should not have subnet name on the frontend ip configuration name", @@ -403,7 +403,7 @@ func TestgetFrontendIPConfigName(t *testing.T) { svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = c.subnetName svc.Annotations[ServiceAnnotationLoadBalancerInternal] = strconv.FormatBool(c.isInternal) - loadbalancerName := az.getFrontendIPConfigName(svc) - assert.Equal(t, c.expected, loadbalancerName, c.description) + ipconfigName := az.getFrontendIPConfigName(svc) + assert.Equal(t, c.expected, ipconfigName, c.description) } }