Add pre- and postdeploy hooks to littlechef

49 views
Skip to first unread message

thekorn

unread,
Jan 9, 2012, 12:26:12 PM1/9/12
to littl...@googlegroups.com
Hey littlechefs,
sometimes it is necessary  to run commands before or after fixing a set of nodes, or a particular node. Let me give you a few examples:

 * I would like to make sure that I have an up-to-date checkout of my kitchen before running fix
 * After running fix I would like to run a testsuite on the new deployment, to make sure everything went smooth and fine.
 * Before fixing a node I would like to remove the node from a loadbalancer, and add it again when deploying the node worked fine
 * Schedule a downtime or send out a notification before fixing a node, or a set of nodes

Therefor I would be great if littlechef had a concept of pre- and post commit hooks. These hooks should be any executable scripts, such that they are completely decoupled from the python stack.
There should be global hooks which are executed very early/late in a fix run. Hooks for each node should be run around each deployment call.

Pre deploy hooks should take one or more arguments:
 * one argument if it's not a global hook
 * more than one argument if it is a global hook
Each argument should be the fqdn of the node which is about to be configured.

Post deploy hooks should take at least two arguments:
 * the first is always the return code of either the fix command (if it is a global hook) or the deploy() method in case of an individual hook
 * the next arguments are always the related node's fqdns

Hook scripts should always return with exit code 0 if everything worked fine, or >0 if sth. went wrong.
 * If a global Pre deploy hook finish with an error, no nodes are deployed.
 * If a node related pre deploy hook returns an error, deployment of this particular node is skipped
 * the return code of the global post deploy hook is always the result of fix
 * if a node specific post deploy hook indicates an error, fix will always return immediately, with an error.

The hooks which are run during a particular fix run should be configurable based on the chef_environment which is used, roles which are affected, etc.

I propose we add another directory to the kitchen which contain some kind of JSON hook definitions. Each definitions looks sth. like:
{
  "name": "my pre deploy hook",
  "type": "gobal_predeployhook",
  "filters": {
      "chef_environement": ["staging"],
      "node": ["a.google.de", "lb.google.de"]
  },
  "exec": "/usr/bin/somehook"
}

This means:
 * Global pre commit hook
 * only run if chef_environment is "staging" and "a.google.de" or "lb.google.de" are in the list of to-deployed nodes
 * /usr/bin/somehook is executed

If "exec" does not start with a "/" the script is relative to the "hooks" dir in the kitchen.

This is just a summary of my initial idea. I'm very happy to discuss further details, esp. design related things ;)
If you guys like the idea, and we agree on some fundamentals I will open a wiki page for more detailed discussions.

Markus

Miquel Torres

unread,
Jan 10, 2012, 3:59:26 AM1/10/12
to littl...@googlegroups.com
This seems like an interesting idea.

Some of this use cases could be fulfilled by writting plugins
(introduced in the 1.1.0 release!) that act on several nodes (first
lb, then the node in question, then lb again), but I don't know how
clean that would be.

Regarding "exec", you say that would be just a script. That is of
course great inasmuch as anyone would be able to use it. The problem I
see (as opposed to expanding/using plugins) is that this script
potentially doesn't know about some dynamic things. For example, how
would such a script, executed at a load balancer know which node it
should take out?

The usefulness of precommit hooks is clearer to me, as your examples
ilustrate. Can you please explain in more detail how it would be
possible to dynamically take out a node out of lb, or scheduling
downtime at nagios before configuring it, and reverting lb or nagios
config afterwards?

2012/1/9 thekorn <marku...@googlemail.com>:

Reply all
Reply to author
Forward
0 new messages