chore: add azure file protocol parameter

fix typo

fix e2e test failure

fix comments
This commit is contained in:
andyzhangx 2020-06-20 10:09:04 +00:00
parent 0a91893126
commit 42e378f86f
9 changed files with 32 additions and 23 deletions

View File

@ -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
}

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
// 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)
}

View File

@ -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 {

View File

@ -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)

View File

@ -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

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
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}

View File

@ -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: &quota,
}
if protocol == storage.NFS {
fileShareProperties.EnabledProtocols = protocol
}
fileShare := storage.FileShare{
Name: &name,
FileShareProperties: &storage.FileShareProperties{
ShareQuota: &quota,
},
Name: &name,
FileShareProperties: fileShareProperties,
}
_, 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.
// 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)

View File

@ -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