mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
fix: address test failure and review comments
This commit is contained in:
parent
c6a2c4fa79
commit
d7f14fb38e
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user