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

merge.go: drop Compression field if nil in child #1329

Closed
wants to merge 1 commit into from

Conversation

mkenigs
Copy link

@mkenigs mkenigs commented Mar 14, 2022

If a child's Compression field is nil, since it may have uncompressed
Source that gets copied to result, Compression should not be set in
result even if it's set in parent

Fixes coreos/butane#332

If a child's Compression field is nil, since it may have uncompressed
Source that gets copied to result, Compression should not be set in
result even if it's set in parent

Fixes https://github.com/coreos/ignition/issues/1327
@@ -240,6 +240,10 @@ func mergeStruct(parent reflect.Value, parentPath path.ContextPath, child reflec
resultField.Set(mergeStruct(parentField.Elem(), parentFieldPath, childField.Elem(), childFieldPath, resultFieldPath, transcript).Addr())
transcribeOne(parentFieldPath, resultFieldPath, transcript)
transcribeOne(childFieldPath, resultFieldPath, transcript)
case kind == reflect.Ptr && childField.IsNil() && fieldMeta.Name == "Compression":
Copy link
Author

Choose a reason for hiding this comment

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

Is there a better place to put this? Doesn't seem like it should be a case in mergeStruct() since it's such a general function but I couldn't find where else to put it

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused how this works...wouldn't we fall through to the case below without this?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah it would fall through to the next case which calls resultField.Set(parentField). Afaict that's what we want to avoid doing, and instead we want to do nothing (ie set Compression to nil)

Copy link
Author

Choose a reason for hiding this comment

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

The bug we're hitting is when parentField has Compression = gzip but childField.IsNil()

Copy link
Member

Choose a reason for hiding this comment

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

Right sorry, I get confused sometimes how in Go fallthrough requires an explicit fallthrough.

Copy link
Author

Choose a reason for hiding this comment

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

Haha when I read your comment I had a definite moment of crisis over that

Comment on lines +1394 to +1403
{path.New(TAG_CHILD, "storage", "files", 0, "path"), path.New(TAG_RESULT, "storage", "files", 0, "path")},
{path.New(TAG_CHILD, "storage", "files", 0, "contents", "source"), path.New(TAG_RESULT, "storage", "files", 0, "contents", "source")},
{path.New(TAG_PARENT, "storage", "files", 0, "contents"), path.New(TAG_RESULT, "storage", "files", 0, "contents")},
{path.New(TAG_CHILD, "storage", "files", 0, "contents"), path.New(TAG_RESULT, "storage", "files", 0, "contents")},
{path.New(TAG_PARENT, "storage", "files", 0), path.New(TAG_RESULT, "storage", "files", 0)},
{path.New(TAG_CHILD, "storage", "files", 0), path.New(TAG_RESULT, "storage", "files", 0)},
{path.New(TAG_PARENT, "storage", "files"), path.New(TAG_RESULT, "storage", "files")},
{path.New(TAG_CHILD, "storage", "files"), path.New(TAG_RESULT, "storage", "files")},
{path.New(TAG_PARENT, "storage"), path.New(TAG_RESULT, "storage")},
{path.New(TAG_CHILD, "storage"), path.New(TAG_RESULT, "storage")},
Copy link
Author

Choose a reason for hiding this comment

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

I reverse engineered this so have no idea if it's correct

@bgilbert
Copy link
Contributor

Thanks for the PR. Config merging is defined to be field-by-field, so the current behavior is the correct one. This PR would break existing configs where the child config intends to inherit the parent's compression field.

Butane's automatic compression semantics were implemented without a full recognition of the implications for config merging. The fix should be in Butane; see discussion in coreos/butane#332 (comment).

@bgilbert bgilbert closed this Mar 16, 2022
cgwalters added a commit to cgwalters/machine-config-operator that referenced this pull request May 3, 2022
jkyros pushed a commit to jkyros/machine-config-operator that referenced this pull request Jun 22, 2022
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.

Automatically-compressed resources interact badly with config merging
3 participants