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

Throwing :end_client_run_early during the recipe compile phase should not error. #8011

Open
mrysanek opened this Issue Dec 4, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@mrysanek

mrysanek commented Dec 4, 2018

Describe the Enhancement:

Implement a Chef Client run "blackout window" with no (or absolutely minimal) host impact during the period specified by an attribute. An "Exit with success" during the compile phase would be ideal because the exit code could be placed at the very beginning of the run

Describe the Need:

  • Any host with heavy resource usage and/or time/thread-sensitive code ($ traders, lunch rush, ...)
  • Any installation with a periodic business-mandated "code-freeze"

Current Alternative

  • "Exit with success" from a Chef run during the converge phase by calling "throw :end_client_run_early". This is not useful for CPU/disk-intensive hosts that are sensitive to the activity a normal Chef compile/converge puts on the system.
  • Schedule Chef using crond (much more complex if a blackout window is defined in an attribute)

Can We Help You Implement This?:

This should be a very simple implementation, since a "throw :end_client_run_early" during the compile phase already works - only returns an error/exception; either

  • change the behavior to match the converge phase exit (success) or
  • add a ":end_client_run_with_success" that behaves the same in compile and converge phases

My existing workaround (exit during converge phase) attached.

pb_freeze2.zip

@lamont-granquist lamont-granquist changed the title from A way to abort but not fail a Chef client run during the compile phase to Throwing :end_client_run_early during the recipe compile phase should not error. Dec 4, 2018

@lamont-granquist

This comment has been minimized.

Contributor

lamont-granquist commented Dec 4, 2018

% cat  /Users/lamont/zero/local-mode-cache/cache/chef-stacktrace.out
Generated at 2018-12-04 10:54:57 -0800
UncaughtThrowError: uncaught throw :end_client_run_early
/Users/lamont/zero/local-mode-cache/cache/cookbooks/test/recipes/default.rb:2:in `throw'
/Users/lamont/zero/local-mode-cache/cache/cookbooks/test/recipes/default.rb:2:in `from_file'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/mixin/from_file.rb:34:in `instance_eval'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/mixin/from_file.rb:34:in `from_file'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/cookbook_version.rb:199:in `load_recipe'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context.rb:350:in `load_recipe'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context/cookbook_compiler.rb:166:in `block in compile_recipes'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context/cookbook_compiler.rb:163:in `each'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context/cookbook_compiler.rb:163:in `compile_recipes'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context/cookbook_compiler.rb:79:in `compile'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/run_context.rb:199:in `load'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/client.rb:515:in `setup_run_context'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/client.rb:281:in `run'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/application.rb:279:in `block in run_chef_client'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/application.rb:261:in `run_chef_client'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/application/client.rb:440:in `run_application'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/lib/chef/application.rb:66:in `run'
/Users/lamont/.rvm/gems/ruby-2.5.1/gems/chef-14.7.17/bin/chef-client:25:in `<top (required)>'
/Users/lamont/.rvm/gems/ruby-2.5.1/bin/chef-client:23:in `load'
/Users/lamont/.rvm/gems/ruby-2.5.1/bin/chef-client:23:in `<main>'
/Users/lamont/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:15:in `eval'
/Users/lamont/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:15:in `<main>'%

delaying to converge phase succeeds correctly:

ruby_block "whatever" do
  block do
    throw :end_client_run_early
  end
end

results in:

% chef-client -z -j dna.json
Starting Chef Client, version 15.0.96
resolving cookbooks for run list: ["test"]
Synchronizing Cookbooks:
  - test (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: test::default
  * ruby_block[whatever] action run

    Running handlers:
    Running handlers complete
    Chef Client finished, 0/0 resources updated in 03 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment