Skip to content

Commit fe15307

Browse files
committed
chore: fix build error using cloud provider lib
1 parent 649bd37 commit fe15307

File tree

3 files changed

+105
-5
lines changed

3 files changed

+105
-5
lines changed

pkg/blobfuse/blobfuse.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ const (
4444
defaultDirMode = "0777"
4545
defaultVers = "3.0"
4646
serverNameField = "server"
47+
tagsField = "tags"
4748

4849
// See https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names
4950
containerNameMinLength = 3
5051
containerNameMaxLength = 63
52+
53+
accountNotProvisioned = "StorageAccountIsNotProvisioned"
54+
tooManyRequests = "TooManyRequests"
55+
shareNotFound = "The specified share does not exist"
56+
shareBeingDeleted = "The specified share is being deleted"
57+
clientThrottled = "client throttled"
58+
)
59+
60+
var (
61+
retriableErrors = []string{accountNotProvisioned, tooManyRequests, shareNotFound, shareBeingDeleted, clientThrottled}
5162
)
5263

5364
// Driver implements all interfaces of CSI drivers
@@ -395,3 +406,14 @@ func IsCorruptedDir(dir string) bool {
395406
fmt.Printf("IsCorruptedDir(%s) returned with error: (%v, %v)\\n", dir, pathExists, pathErr)
396407
return pathErr != nil && mount.IsCorruptedMnt(pathErr)
397408
}
409+
410+
func isRetriableError(err error) bool {
411+
if err != nil {
412+
for _, v := range retriableErrors {
413+
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(v)) {
414+
return true
415+
}
416+
}
417+
}
418+
return false
419+
}

pkg/blobfuse/blobfuse_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package blobfuse
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"io/ioutil"
2223
"os"
@@ -136,6 +137,53 @@ func TestGetContainerInfo(t *testing.T) {
136137
}
137138
}
138139

140+
func TestIsRetriableError(t *testing.T) {
141+
tests := []struct {
142+
desc string
143+
rpcErr error
144+
expectedBool bool
145+
}{
146+
{
147+
desc: "non-retriable error",
148+
rpcErr: nil,
149+
expectedBool: false,
150+
},
151+
{
152+
desc: "accountNotProvisioned",
153+
rpcErr: errors.New("could not get storage key for storage account : could not get storage key for storage account f233333: Retriable: true, RetryAfter: 0001-01-01 00:00:00 +0000 UTC, HTTPStatusCode: 409, RawError: storage.AccountsClient#ListKeys: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code=\"StorageAccountIsNotProvisioned\" Message=\"The storage account provisioning state must be 'Succeeded' before executing the operation.\""),
154+
expectedBool: true,
155+
},
156+
{
157+
desc: "tooManyRequests",
158+
rpcErr: errors.New("could not get storage key for storage account : could not list storage accounts for account type Premium_LRS: Retriable: true, RetryAfter: 0001-01-01 00:00:00 +0000 UTC m=+231.866923225, HTTPStatusCode: 429, RawError: storage.AccountsClient#ListByResourceGroup: Failure responding to request: StatusCode=429 -- Original Error: autorest/azure: Service returned an error. Status=429 Code=\"TooManyRequests\" Message=\"The request is being throttled as the limit has been reached for operation type - List. For more information, see - https://aka.ms/srpthrottlinglimits\""),
159+
expectedBool: true,
160+
},
161+
{
162+
desc: "shareNotFound",
163+
rpcErr: errors.New("storage.FileSharesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code=\"ShareNotFound\" Message=\"The specified share does not exist\""),
164+
expectedBool: true,
165+
},
166+
{
167+
desc: "shareBeingDeleted",
168+
rpcErr: errors.New("storage.FileSharesClient#Create: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code=\"ShareBeingDeleted\" Message=\"The specified share is being deleted. Try operation later.\""),
169+
expectedBool: true,
170+
},
171+
{
172+
desc: "clientThrottled",
173+
rpcErr: errors.New("could not list storage accounts for account type : Retriable: true, RetryAfter: 16s, HTTPStatusCode: 0, RawError: azure cloud provider throttled for operation StorageAccountListByResourceGroup with reason \"client throttled\""),
174+
expectedBool: true,
175+
},
176+
}
177+
178+
for _, test := range tests {
179+
result := isRetriableError(test.rpcErr)
180+
if result != test.expectedBool {
181+
t.Errorf("desc: (%s), input: rpcErr(%v), isRetriableError returned with bool(%v), not equal to expectedBool(%v)",
182+
test.desc, test.rpcErr, result, test.expectedBool)
183+
}
184+
}
185+
}
186+
139187
func TestGetValidContainerName(t *testing.T) {
140188
tests := []struct {
141189
volumeName string

pkg/blobfuse/controllerserver.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"google.golang.org/grpc/status"
3131
"k8s.io/apimachinery/pkg/util/wait"
3232
"k8s.io/klog/v2"
33+
"k8s.io/legacy-cloud-providers/azure"
3334
)
3435

3536
const blobfuseAccountNamePrefix = "fuse"
@@ -54,7 +55,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
5455
requestGiB := int(util.RoundUpGiB(volSizeBytes))
5556

5657
parameters := req.GetParameters()
57-
var storageAccountType, resourceGroup, location, accountName, containerName string
58+
var storageAccountType, resourceGroup, location, account, containerName, customTags string
5859

5960
// Apply ProvisionerParameters (case-insensitive). We leave validation of
6061
// the values to the cloud provider.
@@ -67,11 +68,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
6768
case "location":
6869
location = v
6970
case "storageaccount":
70-
accountName = v
71+
account = v
7172
case "resourcegroup":
7273
resourceGroup = v
7374
case "containername":
7475
containerName = v
76+
case tagsField:
77+
customTags = v
7578
}
7679
}
7780

@@ -83,11 +86,38 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
8386
if strings.HasPrefix(strings.ToLower(storageAccountType), "premium") {
8487
accountKind = string(storage.BlockBlobStorage)
8588
}
86-
account, accountKey, err := d.cloud.EnsureStorageAccount(accountName, storageAccountType, accountKind, resourceGroup, location, blobfuseAccountNamePrefix, false)
89+
90+
enableHTTPSTrafficOnly := true
91+
92+
tags, err := azure.ConvertTagsToMap(customTags)
93+
if err != nil {
94+
return nil, err
95+
}
96+
97+
accountOptions := &azure.AccountOptions{
98+
Name: account,
99+
Type: storageAccountType,
100+
Kind: accountKind,
101+
ResourceGroup: resourceGroup,
102+
Location: location,
103+
EnableHTTPSTrafficOnly: enableHTTPSTrafficOnly,
104+
Tags: tags,
105+
}
106+
107+
var accountName, accountKey string
108+
err = wait.ExponentialBackoff(d.cloud.RequestBackoff(), func() (bool, error) {
109+
var retErr error
110+
accountName, accountKey, retErr = d.cloud.EnsureStorageAccount(accountOptions, blobfuseAccountNamePrefix)
111+
if isRetriableError(retErr) {
112+
klog.Warningf("EnsureStorageAccount(%s) failed with error(%v), waiting for retrying", account, retErr)
113+
return false, nil
114+
}
115+
return true, retErr
116+
})
117+
87118
if err != nil {
88-
return nil, fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err)
119+
return nil, status.Errorf(codes.Internal, "failed to ensure storage account: %v", err)
89120
}
90-
accountName = account
91121

92122
if containerName == "" {
93123
containerName = getValidContainerName(name)

0 commit comments

Comments
 (0)