From aa4594ffae0fb910ef1a10a7cfebaab5e29ded4f Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 16 Aug 2018 08:59:26 +0000 Subject: [PATCH] add more sku support for azure disk add error msg update bazel --- pkg/volume/azure_dd/BUILD | 1 + pkg/volume/azure_dd/azure_common.go | 12 +++--- pkg/volume/azure_dd/azure_common_test.go | 53 ++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/pkg/volume/azure_dd/BUILD b/pkg/volume/azure_dd/BUILD index 6f3292fa52..c41804fc5d 100644 --- a/pkg/volume/azure_dd/BUILD +++ b/pkg/volume/azure_dd/BUILD @@ -75,6 +75,7 @@ go_test( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/client-go/util/testing:go_default_library", + "//vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library", ], ) diff --git a/pkg/volume/azure_dd/azure_common.go b/pkg/volume/azure_dd/azure_common.go index eeb95e6eb0..18c8250961 100644 --- a/pkg/volume/azure_dd/azure_common.go +++ b/pkg/volume/azure_dd/azure_common.go @@ -59,8 +59,6 @@ var ( string(api.AzureSharedBlobDisk), string(api.AzureDedicatedBlobDisk), string(api.AzureManagedDisk)) - - supportedStorageAccountTypes = sets.NewString("Premium_LRS", "Standard_LRS", "Standard_GRS", "Standard_RAGRS") ) func getPath(uid types.UID, volName string, host volume.VolumeHost) string { @@ -127,11 +125,15 @@ func normalizeStorageAccountType(storageAccountType string) (storage.SkuName, er return defaultStorageAccountType, nil } - if !supportedStorageAccountTypes.Has(storageAccountType) { - return "", fmt.Errorf("azureDisk - %s is not supported sku/storageaccounttype. Supported values are %s", storageAccountType, supportedStorageAccountTypes.List()) + sku := storage.SkuName(storageAccountType) + supportedSkuNames := storage.PossibleSkuNameValues() + for _, s := range supportedSkuNames { + if sku == s { + return sku, nil + } } - return storage.SkuName(storageAccountType), nil + return "", fmt.Errorf("azureDisk - %s is not supported sku/storageaccounttype. Supported values are %s", storageAccountType, supportedSkuNames) } func normalizeCachingMode(cachingMode v1.AzureDataDiskCachingMode) (v1.AzureDataDiskCachingMode, error) { diff --git a/pkg/volume/azure_dd/azure_common_test.go b/pkg/volume/azure_dd/azure_common_test.go index 508c24d094..debda512d7 100644 --- a/pkg/volume/azure_dd/azure_common_test.go +++ b/pkg/volume/azure_dd/azure_common_test.go @@ -24,6 +24,9 @@ import ( "testing" "time" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage" + "github.com/stretchr/testify/assert" + "k8s.io/kubernetes/pkg/util/mount" ) @@ -134,3 +137,53 @@ func TestIoHandler(t *testing.T) { } } } + +func TestNormalizeStorageAccountType(t *testing.T) { + tests := []struct { + storageAccountType string + expectedAccountType storage.SkuName + expectError bool + }{ + { + storageAccountType: "", + expectedAccountType: storage.StandardLRS, + expectError: false, + }, + { + storageAccountType: "NOT_EXISTING", + expectedAccountType: "", + expectError: true, + }, + { + storageAccountType: "Standard_LRS", + expectedAccountType: storage.StandardLRS, + expectError: false, + }, + { + storageAccountType: "Premium_LRS", + expectedAccountType: storage.PremiumLRS, + expectError: false, + }, + { + storageAccountType: "Standard_GRS", + expectedAccountType: storage.StandardGRS, + expectError: false, + }, + { + storageAccountType: "Standard_RAGRS", + expectedAccountType: storage.StandardRAGRS, + expectError: false, + }, + { + storageAccountType: "Standard_ZRS", + expectedAccountType: storage.StandardZRS, + expectError: false, + }, + } + + for _, test := range tests { + result, err := normalizeStorageAccountType(test.storageAccountType) + assert.Equal(t, result, test.expectedAccountType) + assert.Equal(t, err != nil, test.expectError, fmt.Sprintf("error msg: %v", err)) + } +}