Merge pull request #92336 from andyzhangx/azurefile-protocol

add azurefile protocol  parameter in azure cloud provider lib
This commit is contained in:
Kubernetes Prow Robot 2020-06-21 22:22:39 -07:00 committed by GitHub
commit 0c571629ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 23 deletions

View File

@ -47,7 +47,7 @@ var (
// azure cloud provider should implement it // azure cloud provider should implement it
type azureCloudProvider interface { type azureCloudProvider interface {
// create a file share // 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 // delete a file share
DeleteFileShare(resourceGroup, accountName, shareName string) error DeleteFileShare(resourceGroup, accountName, shareName string) error
// resize a file share // resize a file share
@ -204,7 +204,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
if strings.HasPrefix(strings.ToLower(sku), "premium") { if strings.HasPrefix(strings.ToLower(sku), "premium") {
accountKind = string(storage.FileStorage) 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -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 // 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. // fits storage type and location.
func (c *BlobDiskController) CreateVolume(blobName, accountName, accountType, location string, requestGB int) (string, string, int, error) { 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 { if err != nil {
return "", "", 0, fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) return "", "", 0, fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err)
} }

View File

@ -23,8 +23,8 @@ import (
) )
// create file share // create file share
func (az *Cloud) createFileShare(resourceGroupName, accountName, name string, sizeGiB int) error { func (az *Cloud) createFileShare(resourceGroupName, accountName, name string, protocol storage.EnabledProtocols, sizeGiB int) error {
return az.FileClient.CreateFileShare(resourceGroupName, accountName, name, sizeGiB) return az.FileClient.CreateFileShare(resourceGroupName, accountName, name, protocol, sizeGiB)
} }
func (az *Cloud) deleteFileShare(resourceGroupName, accountName, name string) error { func (az *Cloud) deleteFileShare(resourceGroupName, accountName, name string) error {

View File

@ -36,17 +36,21 @@ const (
// CreateFileShare creates a file share, using a matching storage account type, account kind, etc. // 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 // 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 == "" { if resourceGroup == "" {
resourceGroup = az.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 { if err != nil {
return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) 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) 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) klog.V(4).Infof("created share %s in account %s", shareName, account)

View File

@ -141,7 +141,7 @@ func TestCreateFileShare(t *testing.T) {
for _, test := range tests { for _, test := range tests {
mockFileClient := mockfileclient.NewMockInterface(ctrl) mockFileClient := mockfileclient.NewMockInterface(ctrl)
cloud.FileClient = mockFileClient 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) mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
cloud.StorageAccountClient = mockStorageAccountsClient 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().ListByResourceGroup(gomock.Any(), "rg").Return(test.accounts, nil).AnyTimes()
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), "rg", gomock.Any(), gomock.Any()).Return(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 { if test.expectErr && err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
continue continue

View File

@ -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 // 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 { if len(accountName) == 0 {
// find a storage account that matches accountType // find a storage account that matches accountType
accounts, err := az.getStorageAccounts(accountType, accountKind, resourceGroup, location) accounts, err := az.getStorageAccounts(accountType, accountKind, resourceGroup, location)
@ -123,7 +123,7 @@ func (az *Cloud) EnsureStorageAccount(accountName, accountType, accountKind, res
cp := storage.AccountCreateParameters{ cp := storage.AccountCreateParameters{
Sku: &storage.Sku{Name: storage.SkuName(accountType)}, Sku: &storage.Sku{Name: storage.SkuName(accountType)},
Kind: kind, Kind: kind,
AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{EnableHTTPSTrafficOnly: to.BoolPtr(true)}, AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly},
Tags: map[string]*string{"created-by": to.StringPtr("azure")}, Tags: map[string]*string{"created-by": to.StringPtr("azure")},
Location: &location} Location: &location}

View File

@ -46,7 +46,7 @@ func New(config *azclients.ClientConfig) *Client {
} }
// CreateFileShare creates a file share // 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) result, err := c.GetFileShare(resourceGroupName, accountName, name)
if err == nil { if err == nil {
klog.V(2).Infof("file share(%s) under account(%s) rg(%s) already exists", name, accountName, resourceGroupName) 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) quota := int32(sizeGiB)
fileShareProperties := &storage.FileShareProperties{
ShareQuota: &quota,
}
if protocol == storage.NFS {
fileShareProperties.EnabledProtocols = protocol
}
fileShare := storage.FileShare{ fileShare := storage.FileShare{
Name: &name, Name: &name,
FileShareProperties: &storage.FileShareProperties{ FileShareProperties: fileShareProperties,
ShareQuota: &quota,
},
} }
_, err = c.fileSharesClient.Create(context.Background(), resourceGroupName, accountName, name, fileShare) _, err = c.fileSharesClient.Create(context.Background(), resourceGroupName, accountName, name, fileShare)

View File

@ -25,7 +25,7 @@ import (
// Interface is the client interface for creating file shares, interface for test injection. // 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 // 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 { 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 DeleteFileShare(resourceGroupName, accountName, name string) error
ResizeFileShare(resourceGroupName, accountName, name string, sizeGiB int) error ResizeFileShare(resourceGroupName, accountName, name string, sizeGiB int) error
GetFileShare(resourceGroupName, accountName, name string) (storage.FileShare, error) GetFileShare(resourceGroupName, accountName, name string) (storage.FileShare, error)

View File

@ -19,9 +19,10 @@ limitations under the License.
package mockfileclient package mockfileclient
import ( import (
reflect "reflect"
storage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" storage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
reflect "reflect"
) )
// MockInterface is a mock of Interface interface // MockInterface is a mock of Interface interface
@ -48,17 +49,17 @@ func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder {
} }
// CreateFileShare mocks base method // 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() 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) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// CreateFileShare indicates an expected call of CreateFileShare // 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() 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 // DeleteFileShare mocks base method