diff --git a/pkg/azclient/fileshareclient/custom.go b/pkg/azclient/fileshareclient/custom.go index 8ce6bb2667..b001802f98 100644 --- a/pkg/azclient/fileshareclient/custom.go +++ b/pkg/azclient/fileshareclient/custom.go @@ -69,3 +69,19 @@ func (client *Client) List(ctx context.Context, resourceGroupName string, accoun } return result, nil } + +const GetOperationName = "FileSharesClient.Get" + +// Get gets the FileShare +func (client *Client) Get(ctx context.Context, resourceGroupName string, accountName string, fileshareName string, option *armstorage.FileSharesClientGetOptions) (result *armstorage.FileShare, err error) { + metricsCtx := metrics.BeginARMRequest(client.subscriptionID, resourceGroupName, "FileShare", "get") + defer func() { metricsCtx.Observe(ctx, err) }() + ctx, endSpan := runtime.StartSpan(ctx, GetOperationName, client.tracer, nil) + defer endSpan(err) + resp, err := client.FileSharesClient.Get(ctx, resourceGroupName, accountName, fileshareName, option) + if err != nil { + return nil, err + } + //handle statuscode + return &resp.FileShare, nil +} diff --git a/pkg/azclient/fileshareclient/custom_test.go b/pkg/azclient/fileshareclient/custom_test.go index 0a6be1fdcd..5187983a89 100644 --- a/pkg/azclient/fileshareclient/custom_test.go +++ b/pkg/azclient/fileshareclient/custom_test.go @@ -71,6 +71,20 @@ func init() { gomega.Expect(resourceList).To(gomega.BeNil()) }) }) + ginkgo.When("get requests are raised", func() { + ginkgo.It("should not return error", func(ctx context.Context) { + newResource, err := realClient.Get(ctx, resourceGroupName, accountName, resourceName, nil) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + gomega.Expect(newResource).NotTo(gomega.BeNil()) + }) + }) + ginkgo.When("invalid get requests are raised", func() { + ginkgo.It("should return 404 error", func(ctx context.Context) { + newResource, err := realClient.Get(ctx, resourceGroupName, accountName, resourceName+"notfound", nil) + gomega.Expect(err).To(gomega.HaveOccurred()) + gomega.Expect(newResource).To(gomega.BeNil()) + }) + }) } beforeAllFunc = func(ctx context.Context) { diff --git a/pkg/azclient/fileshareclient/fileshareclient_test.go b/pkg/azclient/fileshareclient/fileshareclient_test.go index e7eba7cb7d..56b9526131 100644 --- a/pkg/azclient/fileshareclient/fileshareclient_test.go +++ b/pkg/azclient/fileshareclient/fileshareclient_test.go @@ -21,7 +21,6 @@ import ( "context" "github.com/onsi/ginkgo/v2" - "github.com/onsi/gomega" ) var beforeAllFunc func(context.Context) @@ -38,21 +37,6 @@ var _ = ginkgo.Describe("FileSharesClient", ginkgo.Ordered, func() { additionalTestCases() } - ginkgo.When("get requests are raised", func() { - ginkgo.It("should not return error", func(ctx context.Context) { - newResource, err := realClient.Get(ctx, resourceGroupName, accountName, resourceName, nil) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect(newResource).NotTo(gomega.BeNil()) - }) - }) - ginkgo.When("invalid get requests are raised", func() { - ginkgo.It("should return 404 error", func(ctx context.Context) { - newResource, err := realClient.Get(ctx, resourceGroupName, accountName, resourceName+"notfound", nil) - gomega.Expect(err).To(gomega.HaveOccurred()) - gomega.Expect(newResource).To(gomega.BeNil()) - }) - }) - if afterAllFunc != nil { ginkgo.AfterAll(afterAllFunc) } diff --git a/pkg/azclient/fileshareclient/interface.go b/pkg/azclient/fileshareclient/interface.go index adb559cdbf..b9404aff1d 100644 --- a/pkg/azclient/fileshareclient/interface.go +++ b/pkg/azclient/fileshareclient/interface.go @@ -21,13 +21,11 @@ import ( "context" armstorage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" - - "sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils" ) -// +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=true,crossSubFactory=true +// +azure:client:resource=Account,subResource=FileShare,packageName=github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage,packageAlias=armstorage,clientName=FileSharesClient,expand=true,crossSubFactory=true type Interface interface { - utils.SubResourceGetWithExpandFunc[armstorage.FileShare] + Get(ctx context.Context, resourceGroupName string, accountName string, resourceName string, option *armstorage.FileSharesClientGetOptions) (result *armstorage.FileShare, rerr error) List(ctx context.Context, resourceGroupName string, accountName string, option *armstorage.FileSharesClientListOptions) (result []*armstorage.FileShareItem, err error) Create(ctx context.Context, resourceGroupName string, resourceName string, parentResourceName string, resource armstorage.FileShare, expand *string) (*armstorage.FileShare, error) Update(ctx context.Context, resourceGroupName string, resourceName string, parentResourceName string, resource armstorage.FileShare) (*armstorage.FileShare, error) diff --git a/pkg/azclient/fileshareclient/mock_fileshareclient/interface.go b/pkg/azclient/fileshareclient/mock_fileshareclient/interface.go index 0f800c0402..9edb24eb80 100644 --- a/pkg/azclient/fileshareclient/mock_fileshareclient/interface.go +++ b/pkg/azclient/fileshareclient/mock_fileshareclient/interface.go @@ -138,18 +138,18 @@ func (c *MockInterfaceDeleteCall) DoAndReturn(f func(context.Context, string, st } // Get mocks base method. -func (m *MockInterface) Get(ctx context.Context, resourceGroupName, parentResourceName, resourceName string, expand *string) (*armstorage.FileShare, error) { +func (m *MockInterface) Get(ctx context.Context, resourceGroupName, accountName, resourceName string, option *armstorage.FileSharesClientGetOptions) (*armstorage.FileShare, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", ctx, resourceGroupName, parentResourceName, resourceName, expand) + ret := m.ctrl.Call(m, "Get", ctx, resourceGroupName, accountName, resourceName, option) ret0, _ := ret[0].(*armstorage.FileShare) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get. -func (mr *MockInterfaceMockRecorder) Get(ctx, resourceGroupName, parentResourceName, resourceName, expand any) *MockInterfaceGetCall { +func (mr *MockInterfaceMockRecorder) Get(ctx, resourceGroupName, accountName, resourceName, option any) *MockInterfaceGetCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), ctx, resourceGroupName, parentResourceName, resourceName, expand) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), ctx, resourceGroupName, accountName, resourceName, option) return &MockInterfaceGetCall{Call: call} } @@ -165,13 +165,13 @@ func (c *MockInterfaceGetCall) Return(result *armstorage.FileShare, rerr error) } // Do rewrite *gomock.Call.Do -func (c *MockInterfaceGetCall) Do(f func(context.Context, string, string, string, *string) (*armstorage.FileShare, error)) *MockInterfaceGetCall { +func (c *MockInterfaceGetCall) Do(f func(context.Context, string, string, string, *armstorage.FileSharesClientGetOptions) (*armstorage.FileShare, error)) *MockInterfaceGetCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockInterfaceGetCall) DoAndReturn(f func(context.Context, string, string, string, *string) (*armstorage.FileShare, error)) *MockInterfaceGetCall { +func (c *MockInterfaceGetCall) DoAndReturn(f func(context.Context, string, string, string, *armstorage.FileSharesClientGetOptions) (*armstorage.FileShare, error)) *MockInterfaceGetCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/pkg/azclient/fileshareclient/zz_generated_client.go b/pkg/azclient/fileshareclient/zz_generated_client.go index cea9850c61..926c08ce79 100644 --- a/pkg/azclient/fileshareclient/zz_generated_client.go +++ b/pkg/azclient/fileshareclient/zz_generated_client.go @@ -18,15 +18,11 @@ package fileshareclient import ( - "context" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/tracing" armstorage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" - "sigs.k8s.io/cloud-provider-azure/pkg/azclient/metrics" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils" ) @@ -52,23 +48,3 @@ func New(subscriptionID string, credential azcore.TokenCredential, options *arm. tracer: tr, }, nil } - -const GetOperationName = "FileSharesClient.Get" - -// Get gets the FileShare -func (client *Client) Get(ctx context.Context, resourceGroupName string, accountName string, fileshareName string, expand *string) (result *armstorage.FileShare, err error) { - var ops *armstorage.FileSharesClientGetOptions - if expand != nil { - ops = &armstorage.FileSharesClientGetOptions{Expand: expand} - } - metricsCtx := metrics.BeginARMRequest(client.subscriptionID, resourceGroupName, "FileShare", "get") - defer func() { metricsCtx.Observe(ctx, err) }() - ctx, endSpan := runtime.StartSpan(ctx, GetOperationName, client.tracer, nil) - defer endSpan(err) - resp, err := client.FileSharesClient.Get(ctx, resourceGroupName, accountName, fileshareName, ops) - if err != nil { - return nil, err - } - //handle statuscode - return &resp.FileShare, nil -}