Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Autorest with azcore #3536

Merged
merged 38 commits into from
Sep 25, 2024
Merged

Replace Autorest with azcore #3536

merged 38 commits into from
Sep 25, 2024

Conversation

thomas11
Copy link
Contributor

@thomas11 thomas11 commented Aug 22, 2024

This PR introduces a new implementation of AzureClient that's based on azcore instead of the deprecated autorest. It's part of [Epic] Replace deprecated REST and auth packages in Azure Native #3576. The initial commit is by @mikhailshilkov, thanks!

The PR is rather large. I've attempted to keep logically meaningful individual commits, so reviewing commit by commit might be helpful.

The high-level view of the changes is:

  • Implement a new AzureClient that uses azcore. The AzureClient interface remains unchanged.
    • azcore implements polling for long-running requests internally, using the Location header. That isn't always a qualified URL, as I've observed, so there's new code to make the Location qualified.
  • azcore wants to authenticate via the new azidentity package which we're not using yet. We do already have a bridge, however, that gets tokens from the current auth stack and serves them via azidentity's interface. We pass that bridge into the new Azure client.
  • Using the new client is a small change in provider.go. Since regressions of this change could be very impactful and blocking, there's an escape hatch PULUMI_USE_AUTOREST environment variable to revert to the old client.
  • "Fix older bug in CanCreate" and "TokenCredential bridge: use correct environment" are fixes for already existing bugs that I've found.

Integration testing is essentially provided by the existing test suite since all tests now use the new Azure client.

Unit testing is still rudimentary (although already better than the old client's) and will be extended.

Copy link

github-actions bot commented Aug 22, 2024

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 78.60082% with 52 lines in your changes missing coverage. Please review.

Project coverage is 58.97%. Comparing base (10f599c) to head (0968499).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
provider/pkg/azure/client_azcore.go 80.88% 22 Missing and 21 partials ⚠️
provider/pkg/provider/provider.go 56.25% 6 Missing and 1 partial ⚠️
provider/pkg/provider/auth.go 0.00% 1 Missing ⚠️
provider/pkg/provider/crud/crud.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3536      +/-   ##
==========================================
+ Coverage   58.39%   58.97%   +0.57%     
==========================================
  Files          67       68       +1     
  Lines        8418     8656     +238     
==========================================
+ Hits         4916     5105     +189     
- Misses       3054     3081      +27     
- Partials      448      470      +22     

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

Copy link
Member

@mikhailshilkov mikhailshilkov left a comment

Choose a reason for hiding this comment

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

This looks promising, also the code is quite easy to read! It's also nice how it's almost a drop-in replacement for the old client.

Some comments are below. I'm slightly concerned some of my findings don't result in test failures - it's hard to trust the test suite to catch all errors, it seems.

provider/pkg/provider/provider.go Outdated Show resolved Hide resolved
provider/pkg/provider/crud/crud.go Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Outdated Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Outdated Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Outdated Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Outdated Show resolved Hide resolved
provider/pkg/azure/client_azcore.go Show resolved Hide resolved
@thomas11 thomas11 force-pushed the tkappler/azcore branch 2 times, most recently from 11ec5ed to b2242bf Compare August 23, 2024 19:43
@thomas11 thomas11 force-pushed the tkappler/azcore branch 2 times, most recently from e6aee0a to ff8d746 Compare August 29, 2024 16:17
@mikhailshilkov
Copy link
Member

On the rollout strategy, I suggest we should start with the opt-in strategy: use the old auth by default unless the flag is supplied. We can then seek opportunities for deliberate testing of the feature internally and externally with users that benefit from this change (what are those scenarios?)

@thomas11 thomas11 force-pushed the tkappler/azcore branch 2 times, most recently from aac2fc4 to 2fc0807 Compare August 30, 2024 08:14
Copy link
Member

@danielrbradley danielrbradley left a comment

Choose a reason for hiding this comment

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

Overall looks great to me. Couple of minor questions inline.

provider/pkg/azure/client_azcore.go Outdated Show resolved Hide resolved
provider/pkg/provider/auth.go Show resolved Hide resolved
Comment on lines 87 to 90
// This client will be regnerated with correct environment and authorizer in Configure.
azureClient: azure.NewAzureClient(azureEnv.PublicCloud, nil, azure.BuildUserAgent(PulumiPartnerID)),
// This client will be regenerated with correct environment and authorizer in Configure.
azureClient: azure.NewAzCoreClient(nil, azure.BuildUserAgent(PulumiPartnerID), cloud.AzurePublic, nil),
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but perhaps azureClient should be a pointer and should not be created until we've called configure? Is there some reason we need a default client implementation for use before we've configured the provider that you know of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason I know is that azureClient would then be a pointer to an interface which is annoying to use: (*k.azureClient).Get.

provider/pkg/provider/crud/crud_test.go Show resolved Hide resolved
provider/pkg/azure/client_azcore_test.go Outdated Show resolved Hide resolved
@thomas11 thomas11 force-pushed the tkappler/azcore branch 3 times, most recently from dac0e76 to acdb285 Compare September 2, 2024 18:49
@thomas11
Copy link
Contributor Author

thomas11 commented Sep 3, 2024

We can then seek opportunities for deliberate testing of the feature internally and externally with users that benefit from this change (what are those scenarios?)

It might be a hard sell as the benefits are all internal - get off an unsupported dependency, receive security updates and bug fixes, etc.

The next step, basing the auth stack on the new and supported azidentity, should close some user-visible bugs: #2432, #2734, maybe #957.

@mikhailshilkov
Copy link
Member

It might be a hard sell as the benefits are all internal - get off an unsupported dependency, receive security updates and bug fixes, etc.

We'll have to keep the dependency for a while regardless of the default value. It there's little immediate user value (upside), we should probably be even more careful not to break anyone (downside).

The next step, basing the auth stack on the new and supported azidentity, should close some user-visible bugs: #2432, #2734, maybe #957.

Sounds like a great motivation to get somebody to try the new auth after those are shipped.

@thomas11 thomas11 force-pushed the tkappler/azcore branch 4 times, most recently from 6dbb72b to c9cb302 Compare September 19, 2024 16:35

// Some APIs are explicitly marked `x-ms-long-running-operation` and we should only do the
// poll for the deletion result in that case.
if asyncStyle != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's weird that asyncStyle is used like a boolean flag here; the value doesn't matter. It's the same in the autorest client.

@thomas11 thomas11 merged commit 8ca62bb into master Sep 25, 2024
23 checks passed
@thomas11 thomas11 deleted the tkappler/azcore branch September 25, 2024 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants