Skip to content

Commit a025567

Browse files
committed
Add configuration for host/port. Might revert this later since running
on non-localhost is a potential paxos clusterfuck.
1 parent 1a4ba50 commit a025567

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ end
3434
This means that as soon as the cluster propagates a change, all `etcd-chef`
3535
daemons will activate. You may wish to set a `--splay` time if your recipe
3636
code involves non-local or contended resources.
37+
38+
## Configuration
39+
40+
By default an `etcd` instance on localhost will be used. You can customize this
41+
either via `--etcd-host` and `--etcd-port` command line options, or `etcd_host`
42+
and `etcd_port` in your configuration file.

lib/etcd-chef.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
require 'chef/application/solo'
2+
require 'chef/config'
23
require 'etcd'
34

5+
class Chef
6+
class Config
7+
etcd_host 'localhost'
8+
etcd_port 4001
9+
end
10+
end
11+
412
module EtcdChef
513
class Application < Chef::Application::Solo
614
self.options = Chef::Application::Solo.options
715
self.banner Chef::Application::Solo.banner
816

17+
option :etcd_host,
18+
:long => '--etcd-host HOSTNAME',
19+
:description => 'The etcd host to use'
20+
21+
option :etcd_port,
22+
:long => '--etcd-port PORT',
23+
:description => 'The etcd port to use',
24+
:proc => lambda { |s| s.to_i }
25+
926
def run_application
1027
Chef::Config[:cookbook_path] = [Chef::Config[:cookbook_path]] if Chef::Config[:cookbook_path].is_a?(String)
1128
Chef::Config[:cookbook_path].unshift(File.expand_path('../etcd-chef/cookbooks', __FILE__))
@@ -30,7 +47,7 @@ def run_chef_client
3047
@chef_client = nil
3148
# After CHEF-4546 replace ^^ with super
3249

33-
@etcd ||= Etcd.client # TODO: Config
50+
@etcd ||= Etcd.client(host: Chef::Config[:etcd_host], port: Chef::Config[:etcd_port], read_timeout: 2592000) # Set the timeout 30 days, pending https://github.com/ranjib/etcd-ruby/pull/7
3451
Chef::Log.debug("Starting etcd watch from index #{@etcd_index || 'nil'}")
3552
@etcd_index = @etcd.watch('/', @etcd_index).index
3653
rescue Exception

lib/etcd-chef/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Chef
22
class RunContext
33
def etcd
4-
@etcd_wrapper ||= EtcdWrapper.new(Etcd.client, [])
4+
@etcd_wrapper ||= EtcdWrapper.new(Etcd.client(host: Chef::Config[:etcd_host], port: Chef::Config[:etcd_port]), [])
55
end
66
end
77

0 commit comments

Comments
 (0)