sensu/sensu-chef

Cookbook breaks in Chef < 13 because of apt cookbook dependency

Closed this issue · 12 comments

Expected Behavior

Cookbook should run on Chef version 12 and lower.

Current Behavior

Compiling Cookbooks...

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/altmetric-sensu/recipes/client.rb
================================================================================

NoMethodError
-------------
No resource or method named `apt_preference' for `Chef::Recipe "_linux"'

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/sensu/recipes/_linux.rb:35:in `from_file'
  /var/chef/cache/cookbooks/sensu/recipes/default.rb:34:in `from_file'
  /var/chef/cache/cookbooks/altmetric-sensu/recipes/client.rb:10:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/sensu/recipes/_linux.rb:

 28:      key node['sensu']['apt_key_url']
 29:      distribution node["sensu"]["apt_repo_codename"] || node["lsb"]["codename"]
 30:      components node["sensu"]["use_unstable_repo"] ? ["unstable"] : ["main"]
 31:      action :add
 32:      only_if { node["sensu"]["add_repo"] }
 33:    end
 34:  
 35>>   apt_preference "sensu" do
 36:      pin "version #{node['sensu']['version']}"
 37:      pin_priority "700"
 38:    end
 39:  
 40:    package_options = '--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew"'
 41:  
 42:    package "sensu" do
 43:      version node["sensu"]["version"]
 44:      options package_options

System Info:
------------
chef_version=12.21.31

Possible Solution

Problematic because Chef doesn't support multiple version constraints, but ideally apt dependency needs to be pinned to < 7.0 where they have removed the apt_preference method completely and became Chef 13.3 exclusive.

Steps to Reproduce (for bugs)

Run the sensu default recipe on any Chef install < 13.3

Context

Breaks cookbook functionality completely.

Your Environment

System Info:
------------
chef_version=12.21.31
platform=ubuntu
platform_version=16.04
ruby=ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
program_name=chef-client worker: ppid=23768;start=15:29:56;
executable=/opt/chef/bin/chef-client
tas50 commented

Chef 12 is officially end of life at this point since Chef 14 shipped. You're going to see a large part of the Chef ecosystem begin to drop support for Chef 12. If you still want to continue to use it you'll need to pin apt on your own. It's pretty easy to do this either in your environment or in a wrapper cookbook, but that's really outside the scope of this cookbook. Pinning here would just break users of currently supported Chef releases who wanted to pull down the latest cookbooks.

That's fair enough, but the Readme should be in any case updated to reflect that this cookbook doesn't support Chef 12 anymore and is Chef 13+. We've pinned the apt cookbook for now and we're in the process of moving to 14 anyway, but this was still a pretty sudden break.

Updating your metadata.rb to reflect this dependency would be a start. The master branch still says chef_version '>= 12.14'.

Also, despite pinning an older version of this cookbook (4.0.6), presumably before you dropped support for Chef 12, I still ran into this issue. It only worked when I manually pinned all of my dependencies to known good versions.

If you're saying that NO versions of this cookbook work on Chef 12 any more, that's one thing, but if older versions are still supposed to work on 12 and they're not that's still an issue. Suddenly breaking and then telling people to pin their apt cookbook manually is pretty crappy. You should be responsible for pinning the right versions of your dependencies in your metadata.rb for each cookbook version. And >= is not good enough.

@tas50 this should work on chef 12.14 from what I recall in #608 is that not the case? If not then we need to either update the metadata or revert.

Confirmed that apt_preference did not exist before 13.3 here so the question is rollback or update it and say we support chef 13.3 >=.

If you're saying that NO versions of this cookbook work on Chef 12 any more, that's one thing, but if older versions are still supposed to work on 12 and they're not that's still an issue. Suddenly breaking and then telling people to pin their apt cookbook manually is pretty crappy. You should be responsible for pinning the right versions of your dependencies in your metadata.rb for each cookbook version. And >= is not good enough.

I wholeheartedly agree and had I known at the time that we need at least chef 13.3 I would have pushed back on the changes. What's done is done and there is no sense crying over spilled milk, I am very conflicted on the best course of action at this point is. As the intent of the PR was to bring the community back up to speed with changes and chef 12 is EOL (will never receive another update) and the change was made in a major release (indicating breaking changes which were properly called out in the CHANGELOG) I don't think we should revert it. I think we should update the chef metadata.rb to indicate the versions we support and I agree that we should have pinned the apt cookbook (as well as many others) to at least a major version using pessimistic version constraints. Not using >= comes with its fair share of problems as well (such as not supporting new major versions of chef-client or cookbooks before we have had time to test it) so no matter what someone is affected by the choices we make as far as pinning versions. If someone would like to submit a PR to fix this up it would be greatly appreciated otherwise I can submit a fix this week which should give people time to voice any conerns/disagreement. If there is enough disagreement on this being the right path forward what we could do is add the requirement for apt back in and would allow us to work with any chef 13.x (not forcing 13.3+ which has everything but apt_preferences) but I guess if you have already upgraded from 12 -> 13 an upgrade to >= 13.3 will not be too painful so I am not sure if that really helps anyone out but is an option to soften the impact.

As I have not heard anyone stating that we should roll back I have created the above PR to fix this. after it has been reviewed and merged I will release and link to it here.

what are the changes need to upgrade chef 12 to chef14 . could you please give me the how can i check the modifications manually,

@ajaydevops2019 I am not sure what to say, since I don't have access to your codebase I have no idea what you need to do. I linked you to generic resources to help you determine that for yourself. If that is not enough I suggest your company engage in some chef professional services or hire a contractor to assist your team. In the meantime you can pin the version of your cookbook to 4.4.0 as this was the last version of this cookbook to support chef 12. As chef dropped 12.x support on April 30, 2018 it is highly unlikely that we will release any further 4.x changes, the only changes I might see us backporting are any security issues with the chef code itself.