Skip to content

Commit 28060bc

Browse files
authored
Merge pull request #2448 from k8s-infra-cherrypick-robot/cherry-pick-2444-to-release-1.32
[release-1.32] cleanup: refine DataplaneClient
2 parents f72b063 + 2842dab commit 28060bc

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
)
@@ -42,7 +43,6 @@ var (
4243

4344
type azureFileDataplaneClient struct {
4445
accountName string
45-
accountKey string
4646
*service.Client
4747
}
4848

@@ -67,7 +67,6 @@ func newAzureFileClient(accountName, accountKey, storageEndpointSuffix string) (
6767

6868
return &azureFileDataplaneClient{
6969
accountName: accountName,
70-
accountKey: accountKey,
7170
Client: fileClient,
7271
}, nil
7372
}
@@ -76,15 +75,10 @@ func (f *azureFileDataplaneClient) CreateFileShare(ctx context.Context, shareOpt
7675
if shareOptions == nil {
7776
return fmt.Errorf("shareOptions of account(%s) is nil", f.accountName)
7877
}
79-
shareClient := f.Client.NewShareClient(shareOptions.Name)
80-
_, err := shareClient.Create(ctx, &share.CreateOptions{
78+
_, err := f.Client.NewShareClient(shareOptions.Name).Create(ctx, &share.CreateOptions{
8179
Quota: to.Ptr(int32(shareOptions.RequestGiB)),
8280
})
83-
84-
if err != nil {
85-
return fmt.Errorf("failed to create file share, err: %v", err)
86-
}
87-
return nil
81+
return err
8882
}
8983

9084
// delete a file share
@@ -114,10 +108,9 @@ func (f *azureFileDataplaneClient) ResizeFileShare(ctx context.Context, shareNam
114108
}
115109

116110
func (f *azureFileDataplaneClient) GetFileShareQuota(ctx context.Context, name string) (int, error) {
117-
shareClient := f.Client.NewShareClient(name)
118-
shareProps, err := shareClient.GetProperties(ctx, nil)
111+
shareProps, err := f.Client.NewShareClient(name).GetProperties(ctx, nil)
119112
if err != nil {
120113
return -1, err
121114
}
122-
return int(*shareProps.Quota), nil
115+
return int(ptr.Deref(shareProps.Quota, 0)), nil
123116
}

pkg/azurefile/azurefile_dataplane_client_test.go

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

0 commit comments

Comments
 (0)