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

Bring cookbook up to Chef 13 compliance #20

Merged
merged 3 commits into from
Jan 27, 2018

Conversation

strong-code
Copy link
Contributor

@strong-code strong-code commented Jan 25, 2018

This PR brings this cookbook up to Chef 13 compliance. A breaking change in version 13 did not allow for unsafe access of node attributes in custom resources.

As this cookbook currently stands, this error is thrown when attempting to use the custom resource:

ERROR: can't modify frozen Chef::Node::ImmutableArray

The solution is to call .dup on each attribute accessed inside of ./resources/default.rb or to move values directly into that file. I tried to find a good middle-of-the-road solution.

For anything that had a simple (read: 1 liner or blank array) value, I moved it directly into the ./resources/default.rb file and removed it from ./attributes/default.rb. I also migrated the comments where appropriate.

For larger values, I left them in ./attributes/default.rb and called the .dup method on them to safely clone the node attribute when it is referenced inside of the custom resource file.

I know this is kind of an ugly PR, and I am happy to work with the maintainer to clean it up. I am not sure if you would prefer for everything to be placed directly into ./resources/default.rb or leave it as is and instead call .dup on every node attribute referenced.

@strong-code
Copy link
Contributor Author

Also to note, I tested & verified my changes on Chef version 13.7.16

@chr4
Copy link
Member

chr4 commented Jan 26, 2018

Thanks for investigating this!
The pattern to use attributes as default values in providers was a workaround to fix the mess in Chef to allow both: attributes in node configuration, as well as LWRP usage. Apparently, this workaround doesn't work anymore in Chef 13.

The PR looks good to me, I'd just ask you to remove the metadata.yml change.
I think this PR would require a major version bump, as it might break existing configurations, and I'm going to write a Changelog entry as well explaining this before the release. If you want to take a shot, feel free to do so - otherwise, just remove the version change and I'll handle it.

@strong-code
Copy link
Contributor Author

@chr4 I've reverted the metadata.rb change, and I'll let you update the CHANGELOG as well.

I also added my Vagrantfile line to .gitignore. I'm not sure if there is any utility in including it, but it could help for local testing and development against various Chef versions. I can remove it from the .gitignore file if you'd prefer.

@strong-code strong-code changed the title Bring cookbook up to Chef 13 compliance, update CHANGELOG Bring cookbook up to Chef 13 compliance Jan 26, 2018
@chr4 chr4 merged commit 6bca371 into chr4-cookbooks:master Jan 27, 2018
@chr4
Copy link
Member

chr4 commented Jan 27, 2018

The Vagrantfile in .gitignore is fine for me.

This completely disables node configuration. Maybe we can use something like this to continue supporting it?

attribute :head, kind_of: [Array, String], default: node['resolvconf']['head'].dup
attribute :base, kind_of: [Array, String], default: node['resolvconf']['base'].dup
attribute :tail, kind_of: [Array, String], default: node['resolvconf']['tail'].dup

This would create a problem though when the default attribute is not set, so maybe there's a way to do something like

if node['resolvconf']['base']
  node['resolvconf']['base'].dup
else
  []
end

What do you think? (I've merged this PR, but didn't release it yet).

chr4 added a commit that referenced this pull request Jan 31, 2018
@robbwagoner
Copy link

@chr4 Why was this PR reverted?

@chr4
Copy link
Member

chr4 commented Apr 2, 2018

It was not reverted, I just didn't release a new version (including this fix) yet. The reason is, that it breaks existing attribute configurations, see #20 (comment)

@robbwagoner
Copy link

robbwagoner commented Apr 4, 2018

@chr4 I see; I misread the reference to this in the revert commit 11c7bfd - apologies.

@chr4 chr4 mentioned this pull request May 11, 2018
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.

3 participants