Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4e3b4a7f
Commit
4e3b4a7f
authored
Aug 31, 2018
by
andyzhangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support cross resource group for azure file
fix test failure
parent
c1e37a5f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
19 deletions
+25
-19
azure_blobDiskController.go
...cloudprovider/providers/azure/azure_blobDiskController.go
+2
-2
azure_storage.go
pkg/cloudprovider/providers/azure/azure_storage.go
+6
-2
azure_storage_test.go
pkg/cloudprovider/providers/azure/azure_storage_test.go
+1
-1
azure_storageaccount.go
pkg/cloudprovider/providers/azure/azure_storageaccount.go
+10
-10
azure_storageaccount_test.go
...loudprovider/providers/azure/azure_storageaccount_test.go
+1
-1
azure_provision.go
pkg/volume/azure_file/azure_provision.go
+5
-3
No files found.
pkg/cloudprovider/providers/azure/azure_blobDiskController.go
View file @
4e3b4a7f
...
@@ -80,7 +80,7 @@ func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error
...
@@ -80,7 +80,7 @@ func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error
// 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
,
location
,
dedicatedDiskAccountNamePrefix
)
account
,
key
,
err
:=
c
.
common
.
cloud
.
ensureStorageAccount
(
accountName
,
accountType
,
c
.
common
.
resourceGroup
,
location
,
dedicatedDiskAccountNamePrefix
)
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
)
}
}
...
@@ -108,7 +108,7 @@ func (c *BlobDiskController) DeleteVolume(diskURI string) error {
...
@@ -108,7 +108,7 @@ func (c *BlobDiskController) DeleteVolume(diskURI string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to parse vhd URI %v"
,
err
)
return
fmt
.
Errorf
(
"failed to parse vhd URI %v"
,
err
)
}
}
key
,
err
:=
c
.
common
.
cloud
.
getStorageAccesskey
(
accountName
)
key
,
err
:=
c
.
common
.
cloud
.
getStorageAccesskey
(
accountName
,
c
.
common
.
resourceGroup
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"no key for storage account %s, err %v"
,
accountName
,
err
)
return
fmt
.
Errorf
(
"no key for storage account %s, err %v"
,
accountName
,
err
)
}
}
...
...
pkg/cloudprovider/providers/azure/azure_storage.go
View file @
4e3b4a7f
...
@@ -31,8 +31,12 @@ const (
...
@@ -31,8 +31,12 @@ const (
)
)
// CreateFileShare creates a file share, using a matching storage account
// CreateFileShare creates a file share, using a matching storage account
func
(
az
*
Cloud
)
CreateFileShare
(
shareName
,
accountName
,
accountType
,
location
string
,
requestGiB
int
)
(
string
,
string
,
error
)
{
func
(
az
*
Cloud
)
CreateFileShare
(
shareName
,
accountName
,
accountType
,
resourceGroup
,
location
string
,
requestGiB
int
)
(
string
,
string
,
error
)
{
account
,
key
,
err
:=
az
.
ensureStorageAccount
(
accountName
,
accountType
,
location
,
fileShareAccountNamePrefix
)
if
resourceGroup
==
""
{
resourceGroup
=
az
.
resourceGroup
}
account
,
key
,
err
:=
az
.
ensureStorageAccount
(
accountName
,
accountType
,
resourceGroup
,
location
,
fileShareAccountNamePrefix
)
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
)
}
}
...
...
pkg/cloudprovider/providers/azure/azure_storage_test.go
View file @
4e3b4a7f
...
@@ -116,7 +116,7 @@ func TestCreateFileShare(t *testing.T) {
...
@@ -116,7 +116,7 @@ func TestCreateFileShare(t *testing.T) {
fake
.
Keys
=
test
.
keys
fake
.
Keys
=
test
.
keys
fake
.
Err
=
test
.
err
fake
.
Err
=
test
.
err
account
,
key
,
err
:=
cloud
.
CreateFileShare
(
test
.
name
,
test
.
acct
,
test
.
acctType
,
test
.
loc
,
test
.
gb
)
account
,
key
,
err
:=
cloud
.
CreateFileShare
(
test
.
name
,
test
.
acct
,
test
.
acctType
,
"rg"
,
test
.
loc
,
test
.
gb
)
if
test
.
expectErr
&&
err
==
nil
{
if
test
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
t
.
Errorf
(
"unexpected non-error"
)
continue
continue
...
...
pkg/cloudprovider/providers/azure/azure_storageaccount.go
View file @
4e3b4a7f
...
@@ -30,15 +30,15 @@ type accountWithLocation struct {
...
@@ -30,15 +30,15 @@ type accountWithLocation struct {
}
}
// getStorageAccounts gets name, type, location of all storage accounts in a resource group which matches matchingAccountType, matchingLocation
// getStorageAccounts gets name, type, location of all storage accounts in a resource group which matches matchingAccountType, matchingLocation
func
(
az
*
Cloud
)
getStorageAccounts
(
matchingAccountType
,
matchingLocation
string
)
([]
accountWithLocation
,
error
)
{
func
(
az
*
Cloud
)
getStorageAccounts
(
matchingAccountType
,
resourceGroup
,
matchingLocation
string
)
([]
accountWithLocation
,
error
)
{
ctx
,
cancel
:=
getContextWithCancel
()
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
defer
cancel
()
result
,
err
:=
az
.
StorageAccountClient
.
ListByResourceGroup
(
ctx
,
az
.
R
esourceGroup
)
result
,
err
:=
az
.
StorageAccountClient
.
ListByResourceGroup
(
ctx
,
r
esourceGroup
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
result
.
Value
==
nil
{
if
result
.
Value
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unexpected error when listing storage accounts from resource group %s"
,
az
.
R
esourceGroup
)
return
nil
,
fmt
.
Errorf
(
"unexpected error when listing storage accounts from resource group %s"
,
r
esourceGroup
)
}
}
accounts
:=
[]
accountWithLocation
{}
accounts
:=
[]
accountWithLocation
{}
...
@@ -61,11 +61,11 @@ func (az *Cloud) getStorageAccounts(matchingAccountType, matchingLocation string
...
@@ -61,11 +61,11 @@ func (az *Cloud) getStorageAccounts(matchingAccountType, matchingLocation string
}
}
// getStorageAccesskey gets the storage account access key
// getStorageAccesskey gets the storage account access key
func
(
az
*
Cloud
)
getStorageAccesskey
(
account
string
)
(
string
,
error
)
{
func
(
az
*
Cloud
)
getStorageAccesskey
(
account
,
resourceGroup
string
)
(
string
,
error
)
{
ctx
,
cancel
:=
getContextWithCancel
()
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
defer
cancel
()
result
,
err
:=
az
.
StorageAccountClient
.
ListKeys
(
ctx
,
az
.
R
esourceGroup
,
account
)
result
,
err
:=
az
.
StorageAccountClient
.
ListKeys
(
ctx
,
r
esourceGroup
,
account
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -86,10 +86,10 @@ func (az *Cloud) getStorageAccesskey(account string) (string, error) {
...
@@ -86,10 +86,10 @@ func (az *Cloud) getStorageAccesskey(account string) (string, error) {
}
}
// 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
,
location
,
genAccountNamePrefix
string
)
(
string
,
string
,
error
)
{
func
(
az
*
Cloud
)
ensureStorageAccount
(
accountName
,
accountType
,
resourceGroup
,
location
,
genAccountNamePrefix
string
)
(
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
,
location
)
accounts
,
err
:=
az
.
getStorageAccounts
(
accountType
,
resourceGroup
,
location
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
fmt
.
Errorf
(
"could not list storage accounts for account type %s: %v"
,
accountType
,
err
)
return
""
,
""
,
fmt
.
Errorf
(
"could not list storage accounts for account type %s: %v"
,
accountType
,
err
)
}
}
...
@@ -110,7 +110,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
...
@@ -110,7 +110,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
}
}
glog
.
V
(
2
)
.
Infof
(
"azure - no matching account found, begin to create a new account %s in resource group %s, location: %s, accountType: %s"
,
glog
.
V
(
2
)
.
Infof
(
"azure - no matching account found, begin to create a new account %s in resource group %s, location: %s, accountType: %s"
,
accountName
,
az
.
R
esourceGroup
,
location
,
accountType
)
accountName
,
r
esourceGroup
,
location
,
accountType
)
cp
:=
storage
.
AccountCreateParameters
{
cp
:=
storage
.
AccountCreateParameters
{
Sku
:
&
storage
.
Sku
{
Name
:
storage
.
SkuName
(
accountType
)},
Sku
:
&
storage
.
Sku
{
Name
:
storage
.
SkuName
(
accountType
)},
// switch to use StorageV2 as it's recommended according to https://docs.microsoft.com/en-us/azure/storage/common/storage-account-options
// switch to use StorageV2 as it's recommended according to https://docs.microsoft.com/en-us/azure/storage/common/storage-account-options
...
@@ -121,7 +121,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
...
@@ -121,7 +121,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
ctx
,
cancel
:=
getContextWithCancel
()
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
defer
cancel
()
_
,
err
:=
az
.
StorageAccountClient
.
Create
(
ctx
,
az
.
R
esourceGroup
,
accountName
,
cp
)
_
,
err
:=
az
.
StorageAccountClient
.
Create
(
ctx
,
r
esourceGroup
,
accountName
,
cp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
fmt
.
Errorf
(
fmt
.
Sprintf
(
"Failed to create storage account %s, error: %s"
,
accountName
,
err
))
return
""
,
""
,
fmt
.
Errorf
(
fmt
.
Sprintf
(
"Failed to create storage account %s, error: %s"
,
accountName
,
err
))
}
}
...
@@ -129,7 +129,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
...
@@ -129,7 +129,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc
}
}
// find the access key with this account
// find the access key with this account
accountKey
,
err
:=
az
.
getStorageAccesskey
(
accountName
)
accountKey
,
err
:=
az
.
getStorageAccesskey
(
accountName
,
resourceGroup
)
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
)
}
}
...
...
pkg/cloudprovider/providers/azure/azure_storageaccount_test.go
View file @
4e3b4a7f
...
@@ -64,7 +64,7 @@ func TestGetStorageAccessKeys(t *testing.T) {
...
@@ -64,7 +64,7 @@ func TestGetStorageAccessKeys(t *testing.T) {
expectedKey
:=
test
.
expectedKey
expectedKey
:=
test
.
expectedKey
fake
.
Keys
=
test
.
results
fake
.
Keys
=
test
.
results
fake
.
Err
=
test
.
err
fake
.
Err
=
test
.
err
key
,
err
:=
cloud
.
getStorageAccesskey
(
"acct"
)
key
,
err
:=
cloud
.
getStorageAccesskey
(
"acct"
,
"rg"
)
if
test
.
expectErr
&&
err
==
nil
{
if
test
.
expectErr
&&
err
==
nil
{
t
.
Errorf
(
"Unexpected non-error"
)
t
.
Errorf
(
"Unexpected non-error"
)
continue
continue
...
...
pkg/volume/azure_file/azure_provision.go
View file @
4e3b4a7f
...
@@ -38,7 +38,7 @@ var _ volume.ProvisionableVolumePlugin = &azureFilePlugin{}
...
@@ -38,7 +38,7 @@ var _ volume.ProvisionableVolumePlugin = &azureFilePlugin{}
// 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
,
location
string
,
requestGiB
int
)
(
string
,
string
,
error
)
CreateFileShare
(
shareName
,
accountName
,
accountType
,
resourceGroup
,
location
string
,
requestGiB
int
)
(
string
,
string
,
error
)
// delete a file share
// delete a file share
DeleteFileShare
(
accountName
,
accountKey
,
shareName
string
)
error
DeleteFileShare
(
accountName
,
accountKey
,
shareName
string
)
error
// resize a file share
// resize a file share
...
@@ -139,7 +139,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -139,7 +139,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
return
nil
,
fmt
.
Errorf
(
"%s does not support block volume provisioning"
,
a
.
plugin
.
GetPluginName
())
return
nil
,
fmt
.
Errorf
(
"%s does not support block volume provisioning"
,
a
.
plugin
.
GetPluginName
())
}
}
var
sku
,
location
,
account
string
var
sku
,
resourceGroup
,
location
,
account
string
// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
name
:=
util
.
GenerateVolumeName
(
a
.
options
.
ClusterName
,
a
.
options
.
PVName
,
63
)
name
:=
util
.
GenerateVolumeName
(
a
.
options
.
ClusterName
,
a
.
options
.
PVName
,
63
)
...
@@ -160,6 +160,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -160,6 +160,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
account
=
v
account
=
v
case
"secretnamespace"
:
case
"secretnamespace"
:
secretNamespace
=
v
secretNamespace
=
v
case
"resourcegroup"
:
resourceGroup
=
v
default
:
default
:
return
nil
,
fmt
.
Errorf
(
"invalid option %q for volume plugin %s"
,
k
,
a
.
plugin
.
GetPluginName
())
return
nil
,
fmt
.
Errorf
(
"invalid option %q for volume plugin %s"
,
k
,
a
.
plugin
.
GetPluginName
())
}
}
...
@@ -169,7 +171,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -169,7 +171,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
return
nil
,
fmt
.
Errorf
(
"claim.Spec.Selector is not supported for dynamic provisioning on Azure file"
)
return
nil
,
fmt
.
Errorf
(
"claim.Spec.Selector is not supported for dynamic provisioning on Azure file"
)
}
}
account
,
key
,
err
:=
a
.
azureProvider
.
CreateFileShare
(
name
,
account
,
sku
,
location
,
requestGiB
)
account
,
key
,
err
:=
a
.
azureProvider
.
CreateFileShare
(
name
,
account
,
sku
,
resourceGroup
,
location
,
requestGiB
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment