fix: make azure disk URI case insensitive

This commit is contained in:
andyzhangx 2019-06-14 10:43:35 +00:00
parent 81e6441d49
commit 4a37d04f52
2 changed files with 7 additions and 1 deletions

View File

@ -262,7 +262,7 @@ func (c *ManagedDiskController) ResizeDisk(diskURI string, oldSize resource.Quan
// according to https://docs.microsoft.com/en-us/rest/api/compute/disks/get
func getResourceGroupFromDiskURI(diskURI string) (string, error) {
fields := strings.Split(diskURI, "/")
if len(fields) != 9 || fields[3] != "resourceGroups" {
if len(fields) != 9 || strings.ToLower(fields[3]) != "resourcegroups" {
return "", fmt.Errorf("invalid disk URI: %s", diskURI)
}
return fields[4], nil

View File

@ -2705,6 +2705,12 @@ func TestGetResourceGroupFromDiskURI(t *testing.T) {
expectedResult: "azure-k8s1102",
expectError: false,
},
{
// case insentive check
diskURL: "/subscriptions/4be8920b-2978-43d7-axyz-04d8549c1d05/resourcegroups/azure-k8s1102/providers/Microsoft.Compute/disks/andy-mghyb1102-dynamic-pvc-f7f014c9-49f4-11e8-ab5c-000d3af7b38e",
expectedResult: "azure-k8s1102",
expectError: false,
},
{
diskURL: "/4be8920b-2978-43d7-axyz-04d8549c1d05/resourceGroups/azure-k8s1102/providers/Microsoft.Compute/disks/andy-mghyb1102-dynamic-pvc-f7f014c9-49f4-11e8-ab5c-000d3af7b38e",
expectedResult: "",