-
Notifications
You must be signed in to change notification settings - Fork 40
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
Cleanup Empty AutoAliasing Objects #1064
Conversation
Diff for pulumi-azuread with merge commit 16a4ff2 |
Diff for pulumi-random with merge commit 16a4ff2 |
Diff for pulumi-gcp with merge commit 16a4ff2 |
Diff for pulumi-azure with merge commit 16a4ff2 |
How does this connect to the user problem prompting this PR, would it be possible to elaborate? The tests are at a level of indirection, no elucidating new tests are added, and it's not obvious how the problem is being fixed.
After this PR do we believe that the order of p.SetAutonaming and x.AutoAliasing does not matter anymore? Does editing the existing test not weaken the MaxItems one test strength? I'm going to be able to review tomorrow morning but it's not an obvious fix to review in a tired state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like some comments that describe the recursion pattern, and the purpose of each inline function.
Can we also link the Docker PR that failed, with an explanation of why that happened?
Thank you for the quick turnaround.
pkg/tfbridge/x/tokens.go
Outdated
} | ||
|
||
var walk func(*fieldHistory, *b.SchemaInfo, shim.Schema) | ||
walk = func(h *fieldHistory, info *b.SchemaInfo, schema shim.Schema) { | ||
walk = func(h *fieldHistory, info *b.SchemaInfo, schema shim.Schema) (hasH bool, hasI bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a lot of state context here that gets confusing because the variable names are so similar.
For example, we return hasH
and hasI
here but on line 667 we assign them to keepH
and keepI
and it would be great to know what is prompting us to "keep" info or history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that comment.
pkg/tfbridge/x/tokens.go
Outdated
f(k, v) | ||
h, hasH := getNonNil(hist, k) | ||
i, hasI := getNonNil(info, k) | ||
keepH, keepI := walk(h, i, v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what is being kept here.
Should we keep history/info?
Are we checking whether history or info are being kept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep it when (1) it already existed or (2) we stored useful information in it. I added some comments explaining what we are trying to do that will hopefully clarify.
Diff for pulumi-azuread with merge commit dd58726 |
Diff for pulumi-random with merge commit dd58726 |
Diff for pulumi-gcp with merge commit dd58726 |
Diff for pulumi-azure with merge commit dd58726 |
Diff for pulumi-azuread with merge commit 1a05aa0 |
Diff for pulumi-random with merge commit 1a05aa0 |
5a895da
to
ecab2c4
Compare
Diff for pulumi-azuread with merge commit 4c501ad |
Diff for pulumi-azuread with merge commit 5ea397d |
Diff for pulumi-random with merge commit 4c501ad |
Diff for pulumi-random with merge commit 5ea397d |
Diff for pulumi-gcp with merge commit 1a05aa0 |
After this PR we do believe that The test was more specific than necessary. Specifically, it was testing for a property that was not necessary for the desired behavior that we want to change: - assert.Nil(t, info.Resources["pkg_r1"].Fields["f2"].MaxItemsOne)
+ assert.Nil(t, info.Resources["pkg_r1"].Fields["f2"]) Previously, What we actually cared about is this property (expressed in TS style pseudo-code):
Because of how painful it is to express this in go, I abbreviated to asserting Footnotes
|
pkg/tfbridge/x/token_test.go
Outdated
// (*ProviderInfo).SetAutonaming only applies to fields that are not present in their | ||
// resource's property map. We need to make sure that unless we mark a field as | ||
// `MaxItemsOne: nonNil` for some non-nil value, we don't leave that field entry behind | ||
// since that will disable SetAutonaming. | ||
func TestMaxItemsOneAliasingWithAutoNaming(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guineveresaenger @t0yv0 Sorry for the confusing PR. I have added our motivating example as a test case with an explanation of the underlying logic for the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant. Oof, so SetAutonaming does look at whether the SchemaInfo is present or no.
Saw this code:
if _, hasfield := res.Fields[nameProperty]; !hasfield {
if res.Fields == nil {
res.Fields = make(map[string]*SchemaInfo)
}
res.Fields[nameProperty] = AutoName(nameProperty, maxLength, separator)
}
I would rephrase
(*ProviderInfo).SetAutonaming only applies to fields that are not present in their
// resource's property map.
With
(*ProviderInfo).SetAutonaming skips fields that have a SchemaInfo already defined in ResourceInfo.Fields
I always confuse the Info things with he provider maps from shim.SchemaMap.
Diff for pulumi-azure with merge commit 1a05aa0 |
Diff for pulumi-gcp with merge commit 4c501ad |
Diff for pulumi-gcp with merge commit 5ea397d |
Diff for pulumi-azure with merge commit 4c501ad |
Diff for pulumi-azure with merge commit 5ea397d |
ecab2c4
to
2b93875
Compare
Diff for pulumi-azuread with merge commit 78dbc7b |
Diff for pulumi-random with merge commit 78dbc7b |
Diff for pulumi-gcp with merge commit 78dbc7b |
Diff for pulumi-azure with merge commit 78dbc7b |
Yes that's true. Yes. I think we try not to care anywhere about the different flavors of "missing", not to attach semantics to nil vs missing key here, so what could work is getter functions that isolate the caller from nils, like this:
But perhaps for another day. |
Well this is interesting, it works around the immediate problem but looks a tad error prone. I'm a bit worried about this quirk we found in SetAutonaming behavior, and perhaps there's still conditions where the order of application matters. Consider this:
To the end user this looks like we accidentally disabled auto naming. Could we do better? Could we enforce the order so SetAutonaming is always before aliasing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, especially with the new test
2b93875
to
7747fa1
Compare
Diff for pulumi-random with merge commit 07fcd2f |
Diff for pulumi-azuread with merge commit 07fcd2f |
Diff for pulumi-gcp with merge commit 07fcd2f |
Unfortunately, I think the quirk is here to stay. I've seen plenty of AutoNaming should have been more selective by checking if
If If The end user will never observe
We could enforce the ordering, but I don't think we should.
|
Diff for pulumi-azure with merge commit 07fcd2f |
Brilliant, so the cases don't overlap based on type. Autonaming is interested in name type=string and maxitems=1 aliasing is looking at type=list[x] or type=set[x]. That's great.
I like that. Care to backlog and label say impact/breaking? We can then find all those things when contemplating 4.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the extra comments and improved varnames! 💟
Follow up issue is #1069. |
This PR modifies token mapping to not add extra fields for otherwise empty objects. This is necessary because
AutoName
sets a fulltfbridge.SchemaInfo
, it does not modify one.