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

Allow maintaining nested sub-resources at arbitrary depth #2950

Merged
merged 15 commits into from
Dec 21, 2023

Conversation

thomas11
Copy link
Contributor

@thomas11 thomas11 commented Dec 18, 2023

This PR is a generalization of #2755, and groundwork for #594. I recommend reading their descriptions first.

The properties pointing to sub-resources that can be maintained as stand-alone resources can now be at any level, with #/type references being followed. Traversal methods have been added to resources.AzureAPIProperty that can gather the paths leading to sub-resource properties (and can also be used for other traversals).

In the provider, a new function findUnsetSubResourceProperties uses the collected sub-resource paths to look up these properties in API-shaped objects and collects the ones that are not set. In Read(), we remove them from outputs so they are not projected into inputs. In Update(), we use them to determine where we need to insert cloud state to preserve values not set in our inputs.

In order to be able to unit test code that looks up types, this PR also introduces an abstraction resources.TypeLookupFunc over the previous direct access to azureNativeProvider.resourceMap.Types which is hard to mock.

Copy link

Does the PR have any schema changes?

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

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.

Minor comments inline. Update test snapshot to fix failing test.

provider/pkg/resources/resources.go Outdated Show resolved Hide resolved
provider/pkg/resources/resources.go Outdated Show resolved Hide resolved
provider/pkg/resources/resources.go Show resolved Hide resolved
@thomas11 thomas11 force-pushed the tkappler/MaintainSubResource-path branch from e3461ed to 99cc16c Compare December 19, 2023 12:59
@thomas11 thomas11 marked this pull request as ready for review December 19, 2023 17:01
@thomas11 thomas11 requested a review from a team December 19, 2023 17:10
@thomas11 thomas11 force-pushed the tkappler/MaintainSubResource-path branch from 62982a7 to 1b4f1ef Compare December 19, 2023 20:49
Copy link

codecov bot commented Dec 19, 2023

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (b7e9d3a) 59.93% compared to head (45da4ee) 60.18%.

Files Patch % Lines
provider/pkg/provider/provider.go 81.48% 11 Missing and 4 partials ⚠️
provider/pkg/resources/resources.go 95.08% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2950      +/-   ##
==========================================
+ Coverage   59.93%   60.18%   +0.25%     
==========================================
  Files          64       64              
  Lines       10296    10361      +65     
==========================================
+ Hits         6171     6236      +65     
+ Misses       3602     3601       -1     
- Partials      523      524       +1     

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

@thomas11 thomas11 force-pushed the tkappler/MaintainSubResource-path branch from 1b4f1ef to 340fa94 Compare December 20, 2023 09:45
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.

Looks good to go once we've resolved the failing test.

@thomas11 thomas11 requested a review from a team December 20, 2023 19:14
@thomas11 thomas11 force-pushed the tkappler/MaintainSubResource-path branch from 340fa94 to b2dc7c9 Compare December 20, 2023 20:02
@thomas11 thomas11 force-pushed the tkappler/MaintainSubResource-path branch from b2dc7c9 to 45da4ee Compare December 20, 2023 21:33
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.

Everything's green, all the discussed changes seem to be there and working. Let's ship it! :shipit:

@thomas11 thomas11 merged commit b109c4a into master Dec 21, 2023
15 checks passed
@thomas11 thomas11 deleted the tkappler/MaintainSubResource-path branch December 21, 2023 14:49
thomas11 added a commit that referenced this pull request Feb 3, 2024
This PR fixes a defect introduced by #2950. When handling sub-resource
properties that may be maintained as stand-alone resources, we need to
overwrite them in several code paths. Before, we set them to their
default value `[]` on Create, but removed them entirely on Read. This
causes unnecessary diffs on Refresh. This PR standardizes the handling
on resetting to the default value `[]`.

Resolves #3049
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.

None yet

2 participants