Merge pull request #83953 from beautytiger/dev-191015-azure_wrap

fix string trim func isBackendPoolOnSameLB in azure
This commit is contained in:
Kubernetes Prow Robot 2019-11-07 09:03:55 -08:00 committed by GitHub
commit dc255c6093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -350,7 +350,7 @@ func isBackendPoolOnSameLB(newBackendPoolID string, existingBackendPools []strin
} }
newLBName := matches[1] newLBName := matches[1]
newLBNameTrimmed := strings.TrimRight(newLBName, InternalLoadBalancerNameSuffix) newLBNameTrimmed := strings.TrimSuffix(newLBName, InternalLoadBalancerNameSuffix)
for _, backendPool := range existingBackendPools { for _, backendPool := range existingBackendPools {
matches := backendPoolIDRE.FindStringSubmatch(backendPool) matches := backendPoolIDRE.FindStringSubmatch(backendPool)
if len(matches) != 2 { if len(matches) != 2 {
@ -358,7 +358,7 @@ func isBackendPoolOnSameLB(newBackendPoolID string, existingBackendPools []strin
} }
lbName := matches[1] lbName := matches[1]
if !strings.EqualFold(strings.TrimRight(lbName, InternalLoadBalancerNameSuffix), newLBNameTrimmed) { if !strings.EqualFold(strings.TrimSuffix(lbName, InternalLoadBalancerNameSuffix), newLBNameTrimmed) {
return false, lbName, nil return false, lbName, nil
} }
} }

View File

@ -263,6 +263,14 @@ func TestIsBackendPoolOnSameLB(t *testing.T) {
}, },
expectError: true, expectError: true,
}, },
{
backendPoolID: "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/malformed-lb1-internal/backendAddressPools/pool1",
existingBackendPools: []string{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/malformed-lb1-lanretni/backendAddressPools/pool2",
},
expected: false,
expectedLBName: "malformed-lb1-lanretni",
},
} }
for _, test := range tests { for _, test := range tests {