diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/node_map.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource.rb | 24 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index 62efbc12d6..9c3d223181 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -71,7 +71,7 @@ EOH # # @return [NodeMap] Returns self for possible chaining # - def set(key, klass, platform: nil, platform_version: nil, platform_family: nil, os: nil, canonical: nil, override: nil, allow_cookbook_override: false, __core_override__: false, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName + def set(key, klass, platform: nil, platform_version: nil, platform_family: nil, os: nil, canonical: nil, override: nil, allow_cookbook_override: false, __core_override__: false, chef_version: nil, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName new_matcher = { klass: klass } new_matcher[:platform] = platform if platform new_matcher[:platform_version] = platform_version if platform_version @@ -83,6 +83,10 @@ EOH new_matcher[:cookbook_override] = allow_cookbook_override new_matcher[:core_override] = __core_override__ + if chef_version && Chef::VERSION !~ chef_version + return map + end + # Check if the key is already present and locked, unless the override is allowed. # The checks to see if we should reject, in order: # 1. Core override mode is not set. diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index d341e401de..f65af0c7eb 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -1305,6 +1305,26 @@ class Chef end # + # This API can be used for backcompat to do: + # + # chef_version_for_provides "< 14.0" if defined?(:chef_version_for_provides) + # + # For core chef versions that do not support chef_version: in provides lines. + # + # Since resource_name calls provides the generally correct way of doing this is + # to do `chef_version_for_provides` first, then `resource_name` and then + # any additional options `provides` lines. Calling `resource_name` is somewhat + # important to have the canonical_dsl removed or else that'll stick around + # and chef_version won't get applied to it. + # + # Once we no longer care about supporting chef < 14.4 then we can deprecate + # this API. + # + def self.chef_version_for_provides(arg) + @chef_version_for_provides = arg + end + + # # Mark this resource as providing particular DSL. # # Resources have an automatic DSL based on their resource_name, equivalent to @@ -1327,6 +1347,10 @@ class Chef options[:allow_cookbook_override] = true end + if @chef_version_for_provides && !options.include?(:chef_version) + options[:chef_version] = @chef_version_for_provides + end + result = Chef.resource_handler_map.set(name, self, options, &block) Chef::DSL::Resources.add_resource_dsl(name) result |