Skip to content

Update $ref references in metadata when parameterizing#4031

Merged
thomas11 merged 1 commit into
masterfrom
tkappler/parameterize-metadata
Mar 18, 2025
Merged

Update $ref references in metadata when parameterizing#4031
thomas11 merged 1 commit into
masterfrom
tkappler/parameterize-metadata

Conversation

@thomas11

@thomas11 thomas11 commented Mar 17, 2025

Copy link
Copy Markdown
Contributor

This fixes an omission in #4010. Metadata contains $ref's that need to be updated when parameterizing because all the tokens change, like in the schema.

This fixes this error I had brought up elsewhere:

error: azure-native_storage_v20240101:storage/v20240101:StorageAccount resource 'sa' has a problem: schema type 'azure-native:storage/v20240101:Sku' not found

@thomas11 thomas11 requested review from a team and danielrbradley March 17, 2025 15:58
@github-actions

Copy link
Copy Markdown
Contributor

Does the PR have any schema changes?

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

@danielrbradley danielrbradley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we using the approach of serializing then doing the matching on the string rather than iterating through the objects and replacing the values within the objects? Have you tried recursing through the objects to do the ref replacement?

I can't immediately see why this should break with the strings, but I'm also not super-confident that there wouldn't be some case where it doesn't work.

@codecov

codecov Bot commented Mar 17, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 63.63636% with 12 lines in your changes missing coverage. Please review.

Project coverage is 57.88%. Comparing base (27fbdaf) to head (8914ce9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
provider/pkg/provider/provider_parameterize.go 62.50% 6 Missing and 3 partials ⚠️
provider/pkg/resources/resources.go 66.66% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4031      +/-   ##
==========================================
+ Coverage   57.85%   57.88%   +0.03%     
==========================================
  Files          83       83              
  Lines       13391    13422      +31     
==========================================
+ Hits         7747     7769      +22     
- Misses       5045     5051       +6     
- Partials      599      602       +3     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thomas11

Copy link
Copy Markdown
Contributor Author

Why are we using the approach of serializing then doing the matching on the string rather than iterating through the objects and replacing the values within the objects? Have you tried recursing through the objects to do the ref replacement?

I can't immediately see why this should break with the strings, but I'm also not super-confident that there wouldn't be some case where it doesn't work.

The string approach is not elegant but

  1. much less code
  2. much safer IMO - it's easy to forget some place when iterating properties, and references have a well-defined serialization
  3. we need to do it anyway for the schema, unless we want to unmarshaler the raw schema, traverse it as well (requiring a different implementation), and marshaling it again.

To avoid these downsides, we could use a generic walker based on reflection that visits every property. But that's no safer than string replacement and probably slower as well.

@danielrbradley danielrbradley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Happy with the rationalization 👍

@thomas11 thomas11 merged commit 1bf7e9b into master Mar 18, 2025
@thomas11 thomas11 deleted the tkappler/parameterize-metadata branch March 18, 2025 13:51
@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v2.89.2.

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