mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
adding support for VM name with extra Separator String
This commit is contained in:
parent
d9ba054901
commit
a8de002952
@ -47,13 +47,19 @@ func (ss *scaleSet) makeVmssVMName(scaleSetName, instanceID string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extractVmssVMName(name string) (string, string, error) {
|
func extractVmssVMName(name string) (string, string, error) {
|
||||||
ret := strings.Split(name, vmssNameSeparator)
|
split := strings.SplitAfter(name, vmssNameSeparator)
|
||||||
if len(ret) != 2 {
|
if len(split) < 2 {
|
||||||
glog.Errorf("Failed to extract vmssVMName %q", name)
|
glog.Errorf("Failed to extract vmssVMName %q", name)
|
||||||
return "", "", ErrorNotVmssInstance
|
return "", "", ErrorNotVmssInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret[0], ret[1], nil
|
ssName := strings.Join(split[0:len(split)-1], "")
|
||||||
|
// removing the trailing `vmssNameSeparator` since we used SplitAfter
|
||||||
|
ssName = ssName[:len(ssName)-1]
|
||||||
|
|
||||||
|
instanceID := split[len(split)-1]
|
||||||
|
|
||||||
|
return ssName, instanceID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *scaleSet) newVmssCache() (*timedCache, error) {
|
func (ss *scaleSet) newVmssCache() (*timedCache, error) {
|
||||||
|
@ -46,6 +46,12 @@ func TestExtractVmssVMName(t *testing.T) {
|
|||||||
expectedScaleSet: "vm",
|
expectedScaleSet: "vm",
|
||||||
expectedInstanceID: "1234",
|
expectedInstanceID: "1234",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "correct vmss VM name with Extra Separator should return correct scaleSet and instanceID",
|
||||||
|
vmName: "vm_test_1234",
|
||||||
|
expectedScaleSet: "vm_test",
|
||||||
|
expectedInstanceID: "1234",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
Loading…
Reference in New Issue
Block a user