Skip to content

Conversation

@jackfrancis
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This PR updates the async.CreateOrUpdateAsync method signature so that it takes a single strongly typed structure to express various configurations, to accommodate for the fact that across the various implementations of this interface we use a combination of those configurations. This makes it easier to implement the interface method in a variety of ways without having to ignore the parameter input variable (_), or declaring a function parameter variable + not using it, and then declaring //nolint:revive to avoid a source code lint violation.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests
  • cherry-pick candidate

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 4, 2025
@k8s-ci-robot k8s-ci-robot requested review from marosset and nojnhuh April 4, 2025 17:40
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jackfrancis. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 4, 2025
@jackfrancis jackfrancis force-pushed the revive-lint-exceptions branch from b6c6b98 to 89adeac Compare April 4, 2025 18:14
c.Get(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType)).Return(nil, &azcore.ResponseError{StatusCode: http.StatusNotFound}),
r.Parameters(gomockinternal.AContext(), nil).Return(fakeParameters, nil),
c.CreateOrUpdateAsync(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType), "", gomock.Any()).Return(nil, fakePoller[MockCreator](g, http.StatusAccepted), context.DeadlineExceeded),
c.CreateOrUpdateAsync(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType), gomock.Any()).Return(nil, fakePoller[MockCreator](g, http.StatusAccepted), context.DeadlineExceeded),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nojnhuh this is the only way I could get this test to pass, I tried using:

azure.CreateOrUpdateAsyncOpts{ResumeToken: "", Parameters: gomock.Any()}

as the 3rd argument to c.CreateOrUpdateAsync and it was complaining:

            Got: { {<nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> map[] <nil> <nil> <nil>}} (azure.CreateOrUpdateAsyncOpts)
            Want: is equal to { is anything} (azure.CreateOrUpdateAsyncOpts)

Using gomock.Any() to represent the now-current azure.CreateOrUpdateAsyncOpts type seems like cheating...

@codecov
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 8.92857% with 102 lines in your changes missing coverage. Please review.

Project coverage is 52.92%. Comparing base (b32f0c6) to head (10c1fe6).

Files with missing lines Patch % Lines
azure/services/networkinterfaces/client.go 0.00% 10 Missing ⚠️
azure/services/inboundnatrules/client.go 0.00% 7 Missing ⚠️
azure/services/loadbalancers/client.go 0.00% 6 Missing ⚠️
azure/services/privatedns/link_client.go 0.00% 6 Missing ⚠️
azure/services/privatedns/zone_client.go 0.00% 6 Missing ⚠️
azure/services/publicips/client.go 0.00% 6 Missing ⚠️
azure/services/routetables/client.go 0.00% 6 Missing ⚠️
azure/services/scalesets/client.go 0.00% 6 Missing ⚠️
azure/services/securitygroups/client.go 0.00% 6 Missing ⚠️
azure/services/virtualmachines/client.go 0.00% 6 Missing ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5542      +/-   ##
==========================================
- Coverage   52.93%   52.92%   -0.01%     
==========================================
  Files         272      272              
  Lines       29485    29484       -1     
==========================================
- Hits        15607    15604       -3     
- Misses      13061    13063       +2     
  Partials      817      817              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jackfrancis jackfrancis force-pushed the revive-lint-exceptions branch from 89adeac to 7ee0380 Compare April 4, 2025 18:50
// CreateOrUpdateAsync creates or updates an availability set asynchronously.
// It sends a PUT request to Azure and if accepted without error, the func will return a Poller which can be used to track the ongoing
// progress of the operation.
func (ac *AzureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.ResourceSpecGetter, _resumeToken string, parameters interface{}) (result interface{}, poller *runtime.Poller[armcompute.AvailabilitySetsClientCreateOrUpdateResponse], err error) { //nolint:revive // keeping _resumeToken for understanding purposes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That this is called CreateOrUpdateAsync but isn't actually async at all is the bigger smell to me than an unused parameter. Passing both parameters in a single struct and then only using one field of the struct is just sweeping the problem under the rug IMO.

I get that the SDK simply doesn't give async variants for some types so this is the lowest common denominator, but a more "proper" fix to me would be to have some way to classify services as either "async" or "not async" so the "not async" services like this one are never even passed a resume token at all, not even an empty placeholder. Or do a wholesale rewrite of all the service clients to be pure generic ARM like ASO where everything really is handled the same way.

This may be one reason to prefer ASO long-term. K8s resources defined by ASO are overall way more homogenous than SDK objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting this probably wouldn't be that much work:

Or we could wrap the clients that don't have native asynchronous SDK interfaces in our own async business logic.

In any event these are all good considerations for how to proceed going forward. Calculated using a conventional effort * return formula.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I can convince myself that the "Async" part of "CreateOrUpdateAsync" describes CAPZ's higher-level behavior rather than reflecting exactly what's being done here, so I'm not too hung up on the name.

Overall I think if we do anything here for now we change the parameters to _ and remove the //nolints. Anything more I think isn't worth sacrificing how all the SDK services are currently set up more or less the same way.

make networkinterfaces.AzureClient exportable so that it can be hygienically used as a return value for the exported NewClient func

Signed-off-by: Jack Francis <[email protected]>
@jackfrancis jackfrancis force-pushed the revive-lint-exceptions branch from 7ee0380 to 10c1fe6 Compare April 4, 2025 18:56
@jackfrancis
Copy link
Contributor Author

use #5543 instead

@jackfrancis jackfrancis closed this Apr 4, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in CAPZ Planning Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants