Skip to content

Commit

Permalink
Merge pull request #85509 from beautytiger/automated-cherry-pick-of-#…
Browse files Browse the repository at this point in the history
…83953-upstream-release-1.16

Automated cherry pick of #83953: fix string trim func isBackendPoolOnSameLB in azure
  • Loading branch information
k8s-ci-robot committed Nov 27, 2019
2 parents 5c651b7 + a40a172 commit ee59384
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ func isBackendPoolOnSameLB(newBackendPoolID string, existingBackendPools []strin
}

newLBName := matches[1]
newLBNameTrimmed := strings.TrimRight(newLBName, InternalLoadBalancerNameSuffix)
newLBNameTrimmed := strings.TrimSuffix(newLBName, InternalLoadBalancerNameSuffix)
for _, backendPool := range existingBackendPools {
matches := backendPoolIDRE.FindStringSubmatch(backendPool)
if len(matches) != 2 {
return false, "", fmt.Errorf("existing backendPoolID %q is in wrong format", backendPool)
}

lbName := matches[1]
if !strings.EqualFold(strings.TrimRight(lbName, InternalLoadBalancerNameSuffix), newLBNameTrimmed) {
if !strings.EqualFold(strings.TrimSuffix(lbName, InternalLoadBalancerNameSuffix), newLBNameTrimmed) {
return false, lbName, nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ func TestIsBackendPoolOnSameLB(t *testing.T) {
},
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 {
Expand Down

0 comments on commit ee59384

Please sign in to comment.