Skip to content

Commit d7f14fb

Browse files
committed
fix: address test failure and review comments
1 parent c6a2c4f commit d7f14fb

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666
nicFailedState = "Failed"
6767

6868
storageAccountNameMaxLength = 24
69+
frontendIPConfigNameMaxLength = 80
70+
loadBalancerRuleNameMaxLength = 80
6971
)
7072

7173
var errNotInVMSet = errors.New("vm is not in the vmset")
@@ -283,8 +285,8 @@ func (az *Cloud) getLoadBalancerRuleName(service *v1.Service, protocol v1.Protoc
283285

284286
// Load balancer rule name must be less or equal to 80 charactors, so excluding the hyphen two segments cannot exceed 79
285287
subnetSegment := *subnet
286-
if len(ruleName) + len(subnetSegment) > 79 {
287-
subnetSegment = subnetSegment[:79 - len(ruleName)]
288+
if len(ruleName) + len(subnetSegment) + 1 > loadBalancerRuleNameMaxLength {
289+
subnetSegment = subnetSegment[:loadBalancerRuleNameMaxLength - len(ruleName) - 1]
288290
}
289291

290292
return fmt.Sprintf("%s-%s-%s-%d", prefix, subnetSegment, protocol, port)
@@ -332,8 +334,8 @@ func (az *Cloud) getFrontendIPConfigName(service *v1.Service) string {
332334
ipcName := fmt.Sprintf("%s-%s", baseName, *subnetName)
333335

334336
// Azure lb front end configuration name must not exceed 80 charactors
335-
if len(ipcName) > 80 {
336-
ipcName = ipcName[:80]
337+
if len(ipcName) > frontendIPConfigNameMaxLength {
338+
ipcName = ipcName[:frontendIPConfigNameMaxLength]
337339
}
338340
return ipcName
339341
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_standard_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func TestGetLoadBalancingRuleName(t *testing.T) {
336336
}
337337
}
338338

339-
func TestgetFrontendIPConfigName(t *testing.T) {
339+
func TestGetFrontendIPConfigName(t *testing.T) {
340340
az := getTestCloud()
341341
az.PrimaryAvailabilitySetName = "primary"
342342

@@ -369,14 +369,14 @@ func TestgetFrontendIPConfigName(t *testing.T) {
369369
subnetName: "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet",
370370
isInternal: true,
371371
useStandardLB: true,
372-
expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg",
372+
expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg",
373373
},
374374
{
375375
description: "internal basic lb should have subnet name on the frontend ip configuration name but truncated to 80 charactors",
376376
subnetName: "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet",
377377
isInternal: true,
378378
useStandardLB: false,
379-
expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg",
379+
expected: "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg",
380380
},
381381
{
382382
description: "external standard lb should not have subnet name on the frontend ip configuration name",
@@ -403,7 +403,7 @@ func TestgetFrontendIPConfigName(t *testing.T) {
403403
svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = c.subnetName
404404
svc.Annotations[ServiceAnnotationLoadBalancerInternal] = strconv.FormatBool(c.isInternal)
405405

406-
loadbalancerName := az.getFrontendIPConfigName(svc)
407-
assert.Equal(t, c.expected, loadbalancerName, c.description)
406+
ipconfigName := az.getFrontendIPConfigName(svc)
407+
assert.Equal(t, c.expected, ipconfigName, c.description)
408408
}
409409
}

0 commit comments

Comments
 (0)