diff --git a/pkg/volume/azure_file/azure_provision.go b/pkg/volume/azure_file/azure_provision.go index 6bc588fd6d4..b33db7c6aa9 100644 --- a/pkg/volume/azure_file/azure_provision.go +++ b/pkg/volume/azure_file/azure_provision.go @@ -47,7 +47,7 @@ var ( // azure cloud provider should implement it type azureCloudProvider interface { // create a file share - CreateFileShare(shareName, accountName, accountType, accountKind, resourceGroup, location string, requestGiB int) (string, string, error) + CreateFileShare(shareName, accountName, accountType, accountKind, resourceGroup, location string, protocol storage.EnabledProtocols, requestGiB int) (string, string, error) // delete a file share DeleteFileShare(resourceGroup, accountName, shareName string) error // resize a file share @@ -204,7 +204,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie if strings.HasPrefix(strings.ToLower(sku), "premium") { accountKind = string(storage.FileStorage) } - account, key, err := a.azureProvider.CreateFileShare(shareName, account, sku, accountKind, resourceGroup, location, requestGiB) + account, key, err := a.azureProvider.CreateFileShare(shareName, account, sku, accountKind, resourceGroup, location, storage.SMB, requestGiB) if err != nil { return nil, err } diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_blobDiskController.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_blobDiskController.go index e0d3b8a2dff..5ca0d4a287e 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_blobDiskController.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_blobDiskController.go @@ -84,7 +84,7 @@ func (c *BlobDiskController) initStorageAccounts() { // If no storage account is given, search all the storage accounts associated with the resource group and pick one that // fits storage type and location. func (c *BlobDiskController) CreateVolume(blobName, accountName, accountType, location string, requestGB int) (string, string, int, error) { - account, key, err := c.common.cloud.EnsureStorageAccount(accountName, accountType, string(defaultStorageAccountKind), c.common.resourceGroup, location, dedicatedDiskAccountNamePrefix) + account, key, err := c.common.cloud.EnsureStorageAccount(accountName, accountType, string(defaultStorageAccountKind), c.common.resourceGroup, location, dedicatedDiskAccountNamePrefix, true) if err != nil { return "", "", 0, fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) } diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go index d8109c20cea..dbb4c63dfae 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_file.go @@ -23,8 +23,8 @@ import ( ) // create file share -func (az *Cloud) createFileShare(resourceGroupName, accountName, name string, sizeGiB int) error { - return az.FileClient.CreateFileShare(resourceGroupName, accountName, name, sizeGiB) +func (az *Cloud) createFileShare(resourceGroupName, accountName, name string, protocol storage.EnabledProtocols, sizeGiB int) error { + return az.FileClient.CreateFileShare(resourceGroupName, accountName, name, protocol, sizeGiB) } func (az *Cloud) deleteFileShare(resourceGroupName, accountName, name string) error { diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage.go index 3a9d3435764..a8390c77450 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage.go @@ -36,17 +36,21 @@ const ( // CreateFileShare creates a file share, using a matching storage account type, account kind, etc. // storage account will be created if specified account is not found -func (az *Cloud) CreateFileShare(shareName, accountName, accountType, accountKind, resourceGroup, location string, requestGiB int) (string, string, error) { +func (az *Cloud) CreateFileShare(shareName, accountName, accountType, accountKind, resourceGroup, location string, protocol storage.EnabledProtocols, requestGiB int) (string, string, error) { if resourceGroup == "" { resourceGroup = az.resourceGroup } - account, key, err := az.EnsureStorageAccount(accountName, accountType, accountKind, resourceGroup, location, fileShareAccountNamePrefix) + enableHTTPSTrafficOnly := true + if protocol == storage.NFS { + enableHTTPSTrafficOnly = false + } + account, key, err := az.EnsureStorageAccount(accountName, accountType, accountKind, resourceGroup, location, fileShareAccountNamePrefix, enableHTTPSTrafficOnly) if err != nil { return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) } - if err := az.createFileShare(resourceGroup, account, shareName, requestGiB); err != nil { + if err := az.createFileShare(resourceGroup, account, shareName, protocol, requestGiB); err != nil { return "", "", fmt.Errorf("failed to create share %s in account %s: %v", shareName, account, err) } klog.V(4).Infof("created share %s in account %s", shareName, account) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage_test.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage_test.go index ed892526996..82a95becfbb 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage_test.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storage_test.go @@ -141,7 +141,7 @@ func TestCreateFileShare(t *testing.T) { for _, test := range tests { mockFileClient := mockfileclient.NewMockInterface(ctrl) cloud.FileClient = mockFileClient - mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(test.err).AnyTimes() + mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(test.err).AnyTimes() mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) cloud.StorageAccountClient = mockStorageAccountsClient @@ -149,7 +149,7 @@ func TestCreateFileShare(t *testing.T) { mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), "rg").Return(test.accounts, nil).AnyTimes() mockStorageAccountsClient.EXPECT().Create(gomock.Any(), "rg", gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - account, key, err := cloud.CreateFileShare(test.name, test.acct, test.acctType, test.acctKind, test.rg, test.loc, test.gb) + account, key, err := cloud.CreateFileShare(test.name, test.acct, test.acctType, test.acctKind, test.rg, test.loc, storage.SMB, test.gb) if test.expectErr && err == nil { t.Errorf("unexpected non-error") continue diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storageaccount.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storageaccount.go index 43030e4fc51..32a20efc37b 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storageaccount.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_storageaccount.go @@ -90,7 +90,7 @@ func (az *Cloud) GetStorageAccesskey(account, resourceGroup string) (string, err } // EnsureStorageAccount search storage account, create one storage account(with genAccountNamePrefix) if not found, return accountName, accountKey -func (az *Cloud) EnsureStorageAccount(accountName, accountType, accountKind, resourceGroup, location, genAccountNamePrefix string) (string, string, error) { +func (az *Cloud) EnsureStorageAccount(accountName, accountType, accountKind, resourceGroup, location, genAccountNamePrefix string, enableHTTPSTrafficOnly bool) (string, string, error) { if len(accountName) == 0 { // find a storage account that matches accountType accounts, err := az.getStorageAccounts(accountType, accountKind, resourceGroup, location) @@ -123,7 +123,7 @@ func (az *Cloud) EnsureStorageAccount(accountName, accountType, accountKind, res cp := storage.AccountCreateParameters{ Sku: &storage.Sku{Name: storage.SkuName(accountType)}, Kind: kind, - AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{EnableHTTPSTrafficOnly: to.BoolPtr(true)}, + AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly}, Tags: map[string]*string{"created-by": to.StringPtr("azure")}, Location: &location} diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/azure_fileclient.go b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/azure_fileclient.go index a51fb2da527..b9ca953af34 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/azure_fileclient.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/azure_fileclient.go @@ -46,7 +46,7 @@ func New(config *azclients.ClientConfig) *Client { } // CreateFileShare creates a file share -func (c *Client) CreateFileShare(resourceGroupName, accountName, name string, sizeGiB int) error { +func (c *Client) CreateFileShare(resourceGroupName, accountName, name string, protocol storage.EnabledProtocols, sizeGiB int) error { result, err := c.GetFileShare(resourceGroupName, accountName, name) if err == nil { klog.V(2).Infof("file share(%s) under account(%s) rg(%s) already exists", name, accountName, resourceGroupName) @@ -56,11 +56,15 @@ func (c *Client) CreateFileShare(resourceGroupName, accountName, name string, si } quota := int32(sizeGiB) + fileShareProperties := &storage.FileShareProperties{ + ShareQuota: "a, + } + if protocol == storage.NFS { + fileShareProperties.EnabledProtocols = protocol + } fileShare := storage.FileShare{ - Name: &name, - FileShareProperties: &storage.FileShareProperties{ - ShareQuota: "a, - }, + Name: &name, + FileShareProperties: fileShareProperties, } _, err = c.fileSharesClient.Create(context.Background(), resourceGroupName, accountName, name, fileShare) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/interface.go b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/interface.go index c2f99e6a6fd..f1f603143b2 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/interface.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/interface.go @@ -25,7 +25,7 @@ import ( // Interface is the client interface for creating file shares, interface for test injection. // mockgen -source=$GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/interface.go -package=mockfileclient Interface > $GOPATH/src/k8s.io/kubernetes/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/mockfileclient/interface.go type Interface interface { - CreateFileShare(resourceGroupName, accountName, name string, sizeGiB int) error + CreateFileShare(resourceGroupName, accountName, name string, protocol storage.EnabledProtocols, sizeGiB int) error DeleteFileShare(resourceGroupName, accountName, name string) error ResizeFileShare(resourceGroupName, accountName, name string, sizeGiB int) error GetFileShare(resourceGroupName, accountName, name string) (storage.FileShare, error) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/mockfileclient/interface.go b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/mockfileclient/interface.go index b6f0b21c31f..b48858bc9a6 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/mockfileclient/interface.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/clients/fileclient/mockfileclient/interface.go @@ -19,9 +19,10 @@ limitations under the License. package mockfileclient import ( + reflect "reflect" + storage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockInterface is a mock of Interface interface @@ -48,17 +49,17 @@ func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { } // CreateFileShare mocks base method -func (m *MockInterface) CreateFileShare(resourceGroupName, accountName, name string, sizeGiB int) error { +func (m *MockInterface) CreateFileShare(resourceGroupName, accountName, name string, protocol storage.EnabledProtocols, sizeGiB int) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateFileShare", resourceGroupName, accountName, name, sizeGiB) + ret := m.ctrl.Call(m, "CreateFileShare", resourceGroupName, accountName, name, protocol, sizeGiB) ret0, _ := ret[0].(error) return ret0 } // CreateFileShare indicates an expected call of CreateFileShare -func (mr *MockInterfaceMockRecorder) CreateFileShare(resourceGroupName, accountName, name, sizeGiB interface{}) *gomock.Call { +func (mr *MockInterfaceMockRecorder) CreateFileShare(resourceGroupName, accountName, name, protocol, sizeGiB interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateFileShare", reflect.TypeOf((*MockInterface)(nil).CreateFileShare), resourceGroupName, accountName, name, sizeGiB) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateFileShare", reflect.TypeOf((*MockInterface)(nil).CreateFileShare), resourceGroupName, accountName, name, protocol, sizeGiB) } // DeleteFileShare mocks base method