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

Enabled unified mode: CHEF-33 deprecation warning #822

Merged
merged 20 commits into from
Oct 15, 2021

Conversation

axl89
Copy link
Contributor

@axl89 axl89 commented Oct 7, 2021

We use this cookbook in our company, and by using in the kitchen.yml the setting of deprecations_as_errors, a CHEF-33 deprecation warning came up, so this should fix it by:

  1. Enabling unified mode for all versions than can support it (Chef 14.14+, Chef 15.3+, Chef 16+)
  2. Dropping support for unsupported Chef client versions that are already on EOL (12, 13 and <14.14).

I think this should be a major change (so v5.0.0) so I took the time to modify the CHANGELOG as well, but feel free to modify this pull request!

Cheers

This mode will be the default on Chef 18, and it's defined as a current
deprecation.

See CHEF-33: https://docs.chef.io/deprecations_unified_mode/
As per the CHEF-33 deprecation, for Chef client versions lower than
14.14 the unified_mode is not enabled. Having in mind that even Chef 14
(and 15) are on EOL now, dropping support for Chef client 12 and 13
should not be an issue.

See https://docs.chef.io/deprecations_unified_mode/
@axl89 axl89 requested a review from a team as a code owner October 7, 2021 16:53
@axl89
Copy link
Contributor Author

axl89 commented Oct 7, 2021

Related to #821

@albertvaka
Copy link
Contributor

Thanks a lot for the patch! Do you think we could make this backwards compatible with Chef 12, 13 and <14.14? I was hoping we could avoid doing a new major version for this :/

@axl89
Copy link
Contributor Author

axl89 commented Oct 8, 2021

Basing my answer on sous-chef/nginx cookbook PR to enable unified_mode, and reviewing the official documentation I think it’s even worse 😅! I think it’s required to drop support for Chef versions lower than 15.3!

Regardless, maybe it’s possible to if/else in the custom resources depending on the Chef version? I haven’t seen that on other cookbooks but it may be worth the try.

@albertvaka
Copy link
Contributor

Yes, I think that should be fairly easy and would avoid having to do a major version bump 😃

This function should fix the CHEF-33 deprecation warning where
maintaining backwards compatibility with Chef versions that can't enable
it (15.0,15.1,15.2 and lower than 14.14).

See https://docs.chef.io/deprecations_unified_mode/
This platforms are:
  - Chef 14.14+ but less than 15.0
  - Chef 15.3+

See https://docs.chef.io/deprecations_unified_mode/
@axl89
Copy link
Contributor Author

axl89 commented Oct 14, 2021

Hi @albertvaka ; after some smol vacations I've just uploaded some changes. Feel free to comment!

Copy link
Contributor

@albertvaka albertvaka left a comment

Choose a reason for hiding this comment

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

Nice! Thanks a lot for updating the PR with the conditional unified_mode : ) I left one minor comment but overall LGTM.

metadata.rb Outdated Show resolved Hide resolved
axl89 and others added 2 commits October 14, 2021 23:17
Co-authored-by: Albert Vaca Cintora <albertvaka@gmail.com>
@albertvaka
Copy link
Contributor

albertvaka commented Oct 14, 2021

The CI is failing but it seems to be due to rvm/rvm#5133 let me check if I can fix that...

Edit: This PR should fix the CI #823

albertvaka and others added 5 commits October 15, 2021 00:06
Set to true to treat deprecation warning messages as error messages.
Useful on CI environments to prevent cookbook getting rusty and ease its
maintenance.
@axl89
Copy link
Contributor Author

axl89 commented Oct 14, 2021

After merging your CI fix (3343988) it seems that the pipeline fails for old versions of Chef (14.10 and 13.12.14) like shown below. I'm not entirely sure this if/else thing is possible 😞 and we may need to bump a major version instead:

================================================================================
Recipe Compile Error in /tmp/d20211014-9475-d2suwc/cookbooks/datadog/resources/integration.rb
================================================================================

NoMethodError
-------------
undefined method `unified_mode' for #<Class:0x0000000009464b10>

Cookbook Trace:
---------------
  /tmp/d20211014-9475-d2suwc/cookbooks/datadog/resources/integration.rb:12:in `class_from_file'

Relevant File Content:
----------------------
/tmp/d20211014-9475-d2suwc/cookbooks/datadog/resources/integration.rb:

  5:  # already been setup.
  6:  
  7:  # enable unified mode on specific Chef versions.
  8:  # See CHEF-33 Deprecation warning:
  9:  # https://docs.chef.io/deprecations_unified_mode/
 10:  
 11:  if Chef::Datadog.should_use_unified_mode(node)
 12>>   unified_mode true
 13:  end
 14:  
 15:  default_action :install
 16:  
 17:  property :property_name, String, name_property: true
 18:  property :version, String, required: true
 19:  property :third_party, [true, false], required: false, default: false
 20:  
 21:  action :install do

System Info:
------------
chef_version=14.10.9
platform=ubuntu
platform_version=16.04
ruby=ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
program_name=/home/circleci/project/.bundle/ruby/2.6.0/gems/rspec-core-3.10.1/exe/rspec
executable=/home/circleci/project/.bundle/ruby/2.6.0/gems/rspec-core-3.10.1/exe/rspec

F

Maybe someone with more knowledge on ruby than me could hack this?

EDIT: I believe it may be working thanks to @tas50 chef wizardry (see job).

@axl89 axl89 mentioned this pull request Oct 15, 2021
Copy link
Contributor

@albertvaka albertvaka left a comment

Choose a reason for hiding this comment

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

Awesome, this solution is even cleaner 🎉 I'll merge it now. Again, thanks a ton for investigating this and opening a PR!

@albertvaka albertvaka merged commit baf7af1 into DataDog:main Oct 15, 2021
@axl89 axl89 deleted the chef-unified-mode branch October 15, 2021 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants