mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #103470 from nilo19/bug/cherry-pick-679
fix: return empty VMAS name if using standalone VM
This commit is contained in:
commit
103212febc
@ -1034,6 +1034,11 @@ func (as *availabilitySet) EnsureBackendPoolDeleted(service *v1.Service, backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAvailabilitySetNameByID(asID string) (string, error) {
|
func getAvailabilitySetNameByID(asID string) (string, error) {
|
||||||
|
// for standalone VM
|
||||||
|
if asID == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
matches := vmasIDRE.FindStringSubmatch(asID)
|
matches := vmasIDRE.FindStringSubmatch(asID)
|
||||||
if len(matches) != 2 {
|
if len(matches) != 2 {
|
||||||
return "", fmt.Errorf("getAvailabilitySetNameByID: failed to parse the VMAS ID %s", asID)
|
return "", fmt.Errorf("getAvailabilitySetNameByID: failed to parse the VMAS ID %s", asID)
|
||||||
|
@ -1747,3 +1747,25 @@ func TestStandardGetNodeNameByIPConfigurationID(t *testing.T) {
|
|||||||
assert.Equal(t, "k8s-agentpool1-00000000-0", nodeName)
|
assert.Equal(t, "k8s-agentpool1-00000000-0", nodeName)
|
||||||
assert.Equal(t, "agentpool1-availabilityset-00000000", asName)
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user