- From: Kevin Nuckolls <
>
- To:
- Subject: [chef] Re: Re: releasing knife-santoku: a drop in replacement for knife that helps you build out internal processes
- Date: Wed, 16 May 2012 10:03:29 -0500
Yep there were a few reasons. Mostly I tend to believe in writing the least amount of code to solve the problem and to keep it as decoupled as possible. Looking at the knife plugin documentation I came across this page[1] about calling other knife plugins from within a knife plugin. As you can see from that link it becomes a rather programmatic process. You have to load the specific plugin you're interested in calling, instantiate it, configure it, and launch it by hand.
I wanted this to work with whatever plugins you may happen to have installed so it seemed like there were three routes I could go down. I could write a lightweight wrapper for knife that shims in two callback functions (before and after the knife instantiation), I could go down the path of writing all the ruby metaprogramming needed to generalize the "calling a plugin within another plugin" code, or I could fork knife and add in the code there directly.
The other problem with making it a knife plugin is that I wanted it to be seamless. You don't have to learn any new commands, it should "just work". I wasn't interested in replicating what knife already does well, and I wasn't interested in forking knife at this point in time. The compromise solution was to just monkeypatch one very small part of knife[2] to keep everything running smoothly within the code that Opscode wrote and as a gem maintainer to keep an eye on that function as new releases come out to make sure that it still behaves as expected.
The most elegant solution is to add actual callback functions all over the knife codebase that you can hook into in your own knife.rb. I didn't want to do that without opscode's design guidance and frankly my solution was the quickest, simplest, most flexible, and most maintainable path to a solution that met the majority of our needs.
Hope that helps!
Kevin Nuckolls
[2]
https://github.com/knuckolls/knife-santoku/blob/master/lib/knife_santoku/monkey_patches/knife.rb
On Wed, May 16, 2012 at 3:39 AM, Andrea Campi
<
" target="_blank">
> wrote:
On Tue, May 15, 2012 at 11:28 PM, Kevin Nuckolls
<
">
> wrote:
> Ohai Chefs!
>
> We wanted to be able to notify a chatroom whenever anyone made changes to
> the chef server, this became more of a problem as the operations team got
> larger. I wrote knife-santoku as a drop in replacement for knife that lets
> you run arbitrary code before or after any knife command. The primary use
> case is matching what command was run and sending off notifications but you
> can build out any processes with it.
Interesting. Any reason why you didn't write this as a knife plugin?
Andrea
Archive powered by MHonArc 2.6.16.