Skip to content

Commit

Permalink
Merge pull request kubernetes#103600 from nilo19/automated-cherry-pic…
Browse files Browse the repository at this point in the history
…k-of-#103470-upstream-release-1.20

Cherry pick of kubernetes#103470: fix: return empty VMAS name if using standalone VM
  • Loading branch information
k8s-ci-robot authored Jul 16, 2021
2 parents 4ce17f8 + d07de02 commit c0f757a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,11 @@ func (as *availabilitySet) EnsureBackendPoolDeleted(service *v1.Service, backend
}

func getAvailabilitySetNameByID(asID string) (string, error) {
// for standalone VM
if asID == "" {
return "", nil
}

matches := vmasIDRE.FindStringSubmatch(asID)
if len(matches) != 2 {
return "", fmt.Errorf("getAvailabilitySetNameByID: failed to parse the VMAS ID %s", asID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1747,3 +1747,25 @@ func TestStandardGetNodeNameByIPConfigurationID(t *testing.T) {
assert.Equal(t, "k8s-agentpool1-00000000-0", nodeName)
assert.Equal(t, "agentpool1-availabilityset-00000000", asName)
}

func TestGetAvailabilitySetNameByID(t *testing.T) {
t.Run("getAvailabilitySetNameByID should return empty string if the given ID is empty", func(t *testing.T) {
vmasName, err := getAvailabilitySetNameByID("")
assert.Nil(t, err)
assert.Empty(t, vmasName)
})

t.Run("getAvailabilitySetNameByID should report an error if the format of the given ID is wrong", func(t *testing.T) {
asID := "illegal-id"
vmasName, err := getAvailabilitySetNameByID(asID)
assert.Equal(t, fmt.Errorf("getAvailabilitySetNameByID: failed to parse the VMAS ID illegal-id"), err)
assert.Empty(t, vmasName)
})

t.Run("getAvailabilitySetNameByID should extract the VMAS name from the given ID", func(t *testing.T) {
asID := "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Compute/availabilitySets/as"
vmasName, err := getAvailabilitySetNameByID(asID)
assert.Nil(t, err)
assert.Equal(t, "as", vmasName)
})
}

0 comments on commit c0f757a

Please sign in to comment.