Skip to content

Commit

Permalink
add list function to fileshareclient
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Dec 23, 2024
1 parent f71c9b6 commit 35f6db7
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 22 deletions.
22 changes: 22 additions & 0 deletions pkg/azclient/fileshareclient/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package fileshareclient
import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
armstorage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"

"sigs.k8s.io/cloud-provider-azure/pkg/azclient/metrics"
)

func (client *Client) Create(ctx context.Context, resourceGroupName string, resourceName string, parentResourceName string, resource armstorage.FileShare) (*armstorage.FileShare, error) {
Expand All @@ -43,3 +46,22 @@ func (client *Client) Delete(ctx context.Context, resourceGroupName string, pare
_, err := client.FileSharesClient.Delete(ctx, resourceGroupName, parentResourceName, resourceName, nil)
return err
}

const ListOperationName = "FileSharesClient.List"

// List gets a list of FileShare in the resource group.
func (client *Client) List(ctx context.Context, resourceGroupName string, accountName string) (result []*armstorage.FileShareItem, err error) {
metricsCtx := metrics.BeginARMRequest(client.subscriptionID, resourceGroupName, "FileShare", "list")
defer func() { metricsCtx.Observe(ctx, err) }()
ctx, endSpan := runtime.StartSpan(ctx, ListOperationName, client.tracer, nil)
defer endSpan(err)
pager := client.FileSharesClient.NewListPager(resourceGroupName, accountName, nil)
for pager.More() {
nextResult, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
result = append(result, nextResult.Value...)
}
return result, nil
}
42 changes: 29 additions & 13 deletions pkg/azclient/fileshareclient/custom_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/azclient/fileshareclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
// +azure:client:verbs=get,resource=Account,subResource=FileShare,packageName=github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage,packageAlias=armstorage,clientName=FileSharesClient,expand=false,crossSubFactory=true
type Interface interface {
utils.SubResourceGetFunc[armstorage.FileShare]
List(ctx context.Context, resourceGroupName string, accountName string) (result []*armstorage.FileShareItem, err error)
Create(ctx context.Context, resourceGroupName string, resourceName string, parentResourceName string, resource armstorage.FileShare) (*armstorage.FileShare, error)
Update(ctx context.Context, resourceGroupName string, resourceName string, parentResourceName string, resource armstorage.FileShare) (*armstorage.FileShare, error)
Delete(ctx context.Context, resourceGroupName string, parentResourceName string, resourceName string) error
Expand Down
39 changes: 39 additions & 0 deletions pkg/azclient/fileshareclient/mock_fileshareclient/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 111 additions & 9 deletions pkg/azclient/fileshareclient/testdata/FileShare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ interactions:
Content-Type:
- application/json
Etag:
- '"0x8DD1F27D1637675"'
- '"0x8DD230FA81FB564"'
Expires:
- "-1"
Pragma:
Expand All @@ -220,6 +220,108 @@ interactions:
code: 201
duration: 200ms
- id: 4
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: management.azure.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
User-Agent:
- ccm-FileShare-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux)
url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-FileShare/providers/Microsoft.Storage/storageAccounts/akscitacctsdktest/fileServices/default/shares?api-version=2023-05-01
method: GET
response:
proto: HTTP/2.0
proto_major: 2
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 586
uncompressed: false
body: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-FileShare/providers/Microsoft.Storage/storageAccounts/akscitacctsdktest/fileServices/default/shares/akscitaccountfilesharetest","name":"akscitaccountfilesharetest","type":"Microsoft.Storage/storageAccounts/fileServices/shares","etag":"\"0x8DD230FA81FB564\"","properties":{"leaseStatus":"unlocked","leaseState":"available","accessTier":"Cool","accessTierChangeTime":"2001-02-03T04:05:06Z","lastModifiedTime":"2001-02-03T04:05:06Z","shareQuota":102400,"enabledProtocols":"SMB"}}]}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "586"
Content-Type:
- application/json
Expires:
- "-1"
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Cache:
- CONFIG_NOCACHE
X-Content-Type-Options:
- nosniff
X-Ms-Ratelimit-Remaining-Subscription-Global-Reads:
- "16499"
status: 200 OK
code: 200
duration: 200ms
- id: 5
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 0
transfer_encoding: []
trailer: {}
host: management.azure.com
remote_addr: ""
request_uri: ""
body: ""
form: {}
headers:
Accept:
- application/json
User-Agent:
- ccm-FileShare-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux)
url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-FileSharenotfound/providers/Microsoft.Storage/storageAccounts/akscitacctsdktest/fileServices/default/shares?api-version=2023-05-01
method: GET
response:
proto: HTTP/2.0
proto_major: 2
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 117
uncompressed: false
body: '{"error":{"code":"ResourceGroupNotFound","message":"Resource group ''aks-cit-FileSharenotfound'' could not be found."}}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "117"
Content-Type:
- application/json; charset=utf-8
Expires:
- "-1"
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Cache:
- CONFIG_NOCACHE
X-Content-Type-Options:
- nosniff
X-Ms-Failure-Cause:
- gateway
status: 404 Not Found
code: 404
duration: 200ms
- id: 6
request:
proto: HTTP/1.1
proto_major: 1
Expand Down Expand Up @@ -247,7 +349,7 @@ interactions:
trailer: {}
content_length: 572
uncompressed: false
body: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-FileShare/providers/Microsoft.Storage/storageAccounts/akscitacctsdktest/fileServices/default/shares/akscitaccountfilesharetest","name":"akscitaccountfilesharetest","type":"Microsoft.Storage/storageAccounts/fileServices/shares","etag":"\"0x8DD1F27D1637675\"","properties":{"leaseStatus":"unlocked","leaseState":"available","signedIdentifiers":[],"accessTier":"Cool","accessTierChangeTime":"2001-02-03T04:05:06Z","lastModifiedTime":"2001-02-03T04:05:06Z","shareQuota":102400}}'
body: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-FileShare/providers/Microsoft.Storage/storageAccounts/akscitacctsdktest/fileServices/default/shares/akscitaccountfilesharetest","name":"akscitaccountfilesharetest","type":"Microsoft.Storage/storageAccounts/fileServices/shares","etag":"\"0x8DD230FA81FB564\"","properties":{"leaseStatus":"unlocked","leaseState":"available","signedIdentifiers":[],"accessTier":"Cool","accessTierChangeTime":"2001-02-03T04:05:06Z","lastModifiedTime":"2001-02-03T04:05:06Z","shareQuota":102400}}'
headers:
Cache-Control:
- no-cache
Expand All @@ -256,7 +358,7 @@ interactions:
Content-Type:
- application/json
Etag:
- '"0x8DD1F27D1637675"'
- '"0x8DD230FA81FB564"'
Expires:
- "-1"
Pragma:
Expand All @@ -268,11 +370,11 @@ interactions:
X-Content-Type-Options:
- nosniff
X-Ms-Ratelimit-Remaining-Subscription-Global-Reads:
- "16498"
- "16499"
status: 200 OK
code: 200
duration: 200ms
- id: 5
- id: 7
request:
proto: HTTP/1.1
proto_major: 1
Expand Down Expand Up @@ -323,7 +425,7 @@ interactions:
status: 404 Not Found
code: 404
duration: 200ms
- id: 6
- id: 8
request:
proto: HTTP/1.1
proto_major: 1
Expand Down Expand Up @@ -374,7 +476,7 @@ interactions:
status: 200 OK
code: 200
duration: 200ms
- id: 7
- id: 9
request:
proto: HTTP/1.1
proto_major: 1
Expand Down Expand Up @@ -423,7 +525,7 @@ interactions:
status: 200 OK
code: 200
duration: 200ms
- id: 8
- id: 10
request:
proto: HTTP/1.1
proto_major: 1
Expand Down Expand Up @@ -474,7 +576,7 @@ interactions:
status: 202 Accepted
code: 202
duration: 200ms
- id: 9
- id: 11
request:
proto: HTTP/1.1
proto_major: 1
Expand Down

0 comments on commit 35f6db7

Please sign in to comment.