Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

*: fixed broken template and metadata #1520

Merged
merged 4 commits into from
Mar 31, 2016

Conversation

kayrus
Copy link
Contributor

@kayrus kayrus commented Mar 29, 2016

Resolves #1514

The problem was caused by the code optimization. Before that each unit was stored in its own variable. Then this code was optimized and units became stored in hash map (getAllUnitsHashMap). Each hash was assigned to the unit's pointer. And when template unit was checked by requirements() function, its content was modified by values[i] = unitPrintf(v, *uni) code. Once templated unit was modified, all related units (which have same hash) were modified too, because they are related to one pointer.

Now we don't modify source contents.

@jonboulle jonboulle added this to the v0.13.0 milestone Mar 29, 2016
@jonboulle
Copy link
Contributor

Great catch, and gross. requirements() shouldn't have any side effects. Can you add a unit test for that?

@kayrus kayrus force-pushed the kayrus/fixed_template_metadata branch from 2d2f4f0 to bbea486 Compare March 29, 2016 18:18
@kayrus
Copy link
Contributor Author

kayrus commented Mar 29, 2016

Added test and it has failed. Now, let's apply the fix...

@kayrus kayrus force-pushed the kayrus/fixed_template_metadata branch from 416ac85 to 1c96e6a Compare March 29, 2016 18:25
@kayrus
Copy link
Contributor Author

kayrus commented Mar 29, 2016

@jonboulle done

@kayrus kayrus self-assigned this Mar 29, 2016
values[i] = unitPrintf(v, *uni)
processedValues := make([]string, len(values))

for i, v := range values {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kayrus thanks for the catch! you can put this inside the same previous loop:
if uni != nil { processedvalues := make() for ... { ...} requirements[key] = processedvalues } else { requirements[key] = values }

Otherwise it's ok too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@tixxdz
Copy link
Contributor

tixxdz commented Mar 30, 2016

@kayrus perhaps also improve the commit log of the 4th patch (the fix), same wording as for this PR ? otherwise lgtm. Thank you!

@kayrus kayrus force-pushed the kayrus/fixed_template_metadata branch from 1c96e6a to 0a13c7b Compare March 30, 2016 09:32
Resolves coreos#1514

The problem was caused by the [code optimization](coreos#1376). Before that each unit was stored in its own variable. Then this code was optimized and units became stored in hash map (`getAllUnitsHashMap`). Each hash was assigned to the unit's pointer. And when template unit was checked by `requirements()` function, its content was modified by `values[i] = unitPrintf(v, *uni)` code. Once templated unit was modified, all related units (which have same hash) were modified too, because they are related to one pointer.
@kayrus kayrus force-pushed the kayrus/fixed_template_metadata branch from 0a13c7b to a23ce6f Compare March 30, 2016 09:33
@tixxdz
Copy link
Contributor

tixxdz commented Mar 30, 2016

@jonboulle lgtm, thanks!

@jonboulle
Copy link
Contributor

LGTM, thanks - but how about reordering a23ce6f after or before de4ba7f ?

@kayrus
Copy link
Contributor Author

kayrus commented Mar 30, 2016

@jonboulle I suppose we have to show that the issue is covered by tests, and then fix it. so from my point of view the commit order is fine

@jonboulle jonboulle modified the milestones: v0.12.0, v0.13.0 Mar 31, 2016
@jonboulle jonboulle merged commit 9da32a1 into coreos:master Mar 31, 2016
@kayrus kayrus deleted the kayrus/fixed_template_metadata branch March 31, 2016 15:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants