Skip to content

Commit

Permalink
Merge pull request #679 from nilo19/bug/standalone-vm-id
Browse files Browse the repository at this point in the history
fix: return empty VMAS name if using standalone VM
  • Loading branch information
k8s-ci-robot committed Jun 28, 2021
2 parents 13f66db + abccd9a commit 878897e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/provider/azure_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,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
22 changes: 22 additions & 0 deletions pkg/provider/azure_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1952,3 +1952,25 @@ func TestGetNodeCIDRMasksByProviderIDAvailabilitySet(t *testing.T) {
})
}
}

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 878897e

Please sign in to comment.