-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to include recipes smartly
Roles can get smart by making recipe inform the role about its dependencies across the proposal. So a recipe will be included by the role only if the attributes registered by the recipe are actually changed in current chef-client run. a recipe can register its dependencies as ``` mydependson = { "horizon::server" => [ ['glance','api','bind_port'] ] } BarclampLibrary::Barclamp::DependsOn.add(mydependson) ``` So here the "horizon::server" is informing about its dependencies. This is accomplished by comparing the value of the current attributes of node against the one already stored in the databag after the previous successful chef-client run. BarclampLibrary::Barclamp::DependsOn.add: takes in a map: recipe_name => [ [barclampname,drill,down,till,value], [otherbarclampname,onlyhere], ] This map is flushed and recreated only everyrun, however like resources this could also be cached. this behaviour can be altered by adding flag to config and using it 'include_recipe_smartly', however that is an extension to this behavior and can be addressed in subsequent commits Use the role(proposal) that was committed to compare against databag This object enables us to do real comparison on proposal level. Thus every barclamp can have proposal level dependency
- Loading branch information
Sumit Jamgade
committed
Jan 22, 2019
1 parent
43b9e38
commit 319518b
Showing
2 changed files
with
103 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "chef/mixin/language_include_recipe" | ||
|
||
class Chef | ||
module Mixin | ||
module LanguageIncludeRecipe | ||
def include_recipe_smartly(*list_of_recipes) | ||
list_of_recipes.each do |recipe| | ||
included = false | ||
BarclampLibrary::Barclamp::DependsOn.get(recipe).each do |dependency| | ||
next unless BarclampLibrary::Barclamp::Config.changes_to_apply?(dependency) | ||
Chef::Log.info("[smart] including recipe: #{recipe}") | ||
Chef::Log.debug("[smart] due to change in: #{dependency}") | ||
include_recipe recipe | ||
included = true | ||
break | ||
end # each | ||
Chef::Log.info("[smart] recipe excluded: #{recipe}") unless included | ||
end # each | ||
end # def include_recipe_smartly | ||
end | ||
end | ||
end |