Skip to content

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

Closed
mkenigs wants to merge 1 commit intocoreos:mainfrom
mkenigs:no-Compression
Closed

merge.go: drop Compression field if nil in child#1329
mkenigs wants to merge 1 commit intocoreos:mainfrom
mkenigs:no-Compression

Conversation

@mkenigs
Copy link
Copy Markdown

@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
Comment thread config/merge/merge.go
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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