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

Add support for discontinuous property conversions #3641

Merged
merged 31 commits into from
Jan 23, 2024

Conversation

theunrepentantgeek
Copy link
Member

What this PR does / why we need it:

We've had the assumption that two properties needing conversion would have line-of-sight to each other in the storage conversion graph constructed by the generator. To this point this has been true, but with a recent attempt to import another preview version of ManagedCluster we discovered that this was not so.

To support these conversions, I've added another conversion handler, one that looks for a commonly visible pivot type that can be used to build the conversion required.

Special notes for your reviewer:

I've also refactored creation of test cases for property conversions - the existing test case factory method was too large and complicated to comprehend; now the various groups of test cases are split up.

How does this PR make you feel:
gif

If applicable:

  • this PR contains tests

@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2023

Codecov Report

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

Comparison is base (69cf318) 53.58% compared to head (04edf40) 53.45%.
Report is 7 commits behind head on main.

Files Patch % Lines
...rator/internal/conversions/property_conversions.go 54.54% 36 Missing and 14 partials ⚠️
...rator/internal/codegen/storage/conversion_graph.go 83.33% 1 Missing and 1 partial ⚠️
...nternal/conversions/property_conversion_context.go 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3641      +/-   ##
==========================================
- Coverage   53.58%   53.45%   -0.14%     
==========================================
  Files        1411     1417       +6     
  Lines      483451   484060     +609     
==========================================
- Hits       259079   258731     -348     
- Misses     185153   186094     +941     
- Partials    39219    39235      +16     

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

@theunrepentantgeek theunrepentantgeek force-pushed the fix/discontinuous-object-conversion branch from 1671f7b to 1fca1b7 Compare January 17, 2024 20:09
// Require a path from one name to the next, and work out an intermediate step to break down the conversion
var intermediateName astmodel.InternalTypeName
if conversionContext.PathExists(sourceName, destinationName) {
var err error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can move this(and below) var outside the if statements and to the error checking after the if-else blocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I prefer keeping things tightly scoped.

We need intermediateName after the if, but we don't need either of the potential errors later on. Moving the err variable outside implies a need to access the error again, which isn't correct.


next, err := graph.FindNextType(current, nil)
if err != nil {
break
Copy link
Member

Choose a reason for hiding this comment

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

Should we be doing something with this error?

Copy link
Member Author

Choose a reason for hiding this comment

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

If there's an actual problem (other than no next type) that'll be reported elsewhere. So I think this one is safe to ignore.

c.start,
func(t astmodel.InternalTypeName) bool {
count++
return t == c.end
Copy link
Member

Choose a reason for hiding this comment

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

Should we be using .Equals here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need to - we're comparing InternalTypeName instances, which are value types, not reference - and we don't need any of the special support from .Equals.

}

if intermediateName.IsEmpty() || astmodel.TypeEquals(intermediateName, sourceName) {
if intermediateName.IsEmpty() ||
astmodel.TypeEquals(intermediateName, sourceName) ||
Copy link
Member

Choose a reason for hiding this comment

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

minor: Should there be a comment here explaining the situations where the intermediate name is the source or destination?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

//
// Note the actual steps are generated by nested conversions; this handler works by finding the two conversions needed
// given our intermediate type and chaining them together.
func assignNoninlineObjectsViaPivotObject(
Copy link
Member

Choose a reason for hiding this comment

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

minor, should this be:

Suggested change
func assignNoninlineObjectsViaPivotObject(
func assignNonInlineObjectsViaPivotObject(

Since I think non-inline would be cased like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

@theunrepentantgeek theunrepentantgeek added this pull request to the merge queue Jan 23, 2024
Merged via the queue into main with commit 2a92146 Jan 23, 2024
8 checks passed
@theunrepentantgeek theunrepentantgeek deleted the fix/discontinuous-object-conversion branch January 23, 2024 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants