Skip to content

Commit 05f9b73

Browse files
authored
Merge pull request #2450 from k8s-infra-cherrypick-robot/cherry-pick-2444-to-release-1.31
[release-1.31] cleanup: refine DataplaneClient
2 parents f5a4255 + 022ece5 commit 05f9b73

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

pkg/azurefile/azurefile_dataplane_client.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
2626
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
2727
"k8s.io/klog/v2"
28+
"k8s.io/utils/ptr"
2829

2930
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils"
3031
"sigs.k8s.io/cloud-provider-azure/pkg/retry"
@@ -43,7 +44,6 @@ var (
4344

4445
type azureFileDataplaneClient struct {
4546
accountName string
46-
accountKey string
4747
*service.Client
4848
}
4949

@@ -71,7 +71,6 @@ func newAzureFileClient(accountName, accountKey, storageEndpointSuffix string, b
7171

7272
return &azureFileDataplaneClient{
7373
accountName: accountName,
74-
accountKey: accountKey,
7574
Client: fileClient,
7675
}, nil
7776
}
@@ -80,15 +79,10 @@ func (f *azureFileDataplaneClient) CreateFileShare(ctx context.Context, shareOpt
8079
if shareOptions == nil {
8180
return fmt.Errorf("shareOptions of account(%s) is nil", f.accountName)
8281
}
83-
shareClient := f.Client.NewShareClient(shareOptions.Name)
84-
_, err := shareClient.Create(ctx, &share.CreateOptions{
82+
_, err := f.Client.NewShareClient(shareOptions.Name).Create(ctx, &share.CreateOptions{
8583
Quota: to.Ptr(int32(shareOptions.RequestGiB)),
8684
})
87-
88-
if err != nil {
89-
return fmt.Errorf("failed to create file share, err: %v", err)
90-
}
91-
return nil
85+
return err
9286
}
9387

9488
// delete a file share
@@ -118,10 +112,9 @@ func (f *azureFileDataplaneClient) ResizeFileShare(ctx context.Context, shareNam
118112
}
119113

120114
func (f *azureFileDataplaneClient) GetFileShareQuota(ctx context.Context, name string) (int, error) {
121-
shareClient := f.Client.NewShareClient(name)
122-
shareProps, err := shareClient.GetProperties(ctx, nil)
115+
shareProps, err := f.Client.NewShareClient(name).GetProperties(ctx, nil)
123116
if err != nil {
124117
return -1, err
125118
}
126-
return int(*shareProps.Quota), nil
119+
return int(ptr.Deref(shareProps.Quota, 0)), nil
127120
}

pkg/azurefile/azurefile_dataplane_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestCreateFileShare(t *testing.T) {
4242
t.Errorf("error creating azure client: %v", err)
4343
}
4444
actualErr := f.CreateFileShare(context.Background(), options)
45-
expectedErr := fmt.Errorf("failed to create file share, err: ")
45+
expectedErr := fmt.Errorf("")
4646
if !strings.HasPrefix(actualErr.Error(), expectedErr.Error()) {
4747
t.Errorf("actualErr: (%v), expectedErr: (%v)", actualErr, expectedErr)
4848
}

0 commit comments

Comments
 (0)