This is VERY closely related to the other topic I just posted about composite packages, but I felt it was enough of a different topic to deserve its own post.
Basically, I just built a consul-client package which allows running the Consul binary in “client” or “agent” mode so that it just communicates with a Consul cluster and doesn’t participate in the raft/consensus protocol.
Basically, consul allows you to register arbitrary services and drop the service config in a “config directory” (traditionally /etc/consul.d
) where the services will be loaded and reported back to the cluster. Then you’re able to query the consul cluster via dns for your service. This provides significant benefit in cases where you can’t run the hab
service or only have the ability to do DNS lookups. (selfishly, I’d like to start working our way away from Consul for service discovery and just use pure Habitat, but I’m not sold that this is the end-all-be-all solution… AND being able to do both provides some ability to “lift and shift” gradually rather than all at once…)
Is there a mechanism for applying “arbitrary” config files to habitat packages? With Chef we have a generic template that just parses node attributes and generates the appropriate JSON in /etc/consul.d
. We could conceivably create /hab/svc/consul-client/data/consul.d
and just drop files in there with Chef, which may be a fine interim solution, but it feels like this is the wrong approach and goes against the ethos of Habitat as a whole. I really don’t want to create a disparate consul-client package for each potential service config (besides I’m not sure what the logistics of running multiple composite packages natively that all use the same base qubitrenegade/consul-client
package you can’t run multiple instances of a package…)
My Chef looks like (this is off the top of my head and my not be 100% accurate but I think gets the gist across):
node['consul-client']['service'].each do |service_name, config|
template "/etc/consul.d/#{service_name}.json" do
source 'consul-service.erb'
variables config: config.to_json
action :create
end
end
I mean, maybe the answer is that Chef should still be generating these configs. Although I think it would be cool to be able to just provide that information in the user.toml
… I’m not really sold on one way or the other so open to any suggestions!
Thanks!