Skip to content

Commit

Permalink
Add simple Atlas support
Browse files Browse the repository at this point in the history
  • Loading branch information
shanesveller committed Mar 16, 2015
1 parent 3e4f086 commit 39dd110
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ suites:
consul:
service_mode: cluster
bootstrap_expect: 1
- name: atlas
run_list:
- recipe[consul::default]
attributes:
consul:
atlas_autojoin: true
atlas_cluster: <%= ENV.fetch('ATLAS_CLUSTER', 'example/cluster') %>
atlas_token: <%= ENV.fetch('ATLAS_TOKEN', 'NOT_REAL') %>
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ Installs and configures [Consul][1] client, server and UI.
<td>This provides the address of a statsd instance (UDP).</td>
<td><tt>nil</tt></td>
</tr>
<tr>
<td><tt>['consul']['atlas_autojoin']</tt></td>
<td>Boolean</td>
<td>
Determines whether Consul attempts to auto-join the cluster provided by <tt>atlas_cluster</tt> using the value of <tt>atlas_token</tt>
</td>
<td><tt>false</tt></td>
</tr>
<tr>
<td><tt>['consul']['atlas_cluster']</tt></td>
<td>String</td>
<td>
Name of Atlas cluster to auto-join
</td>
<td><tt>nil</tt></td>
</tr>
<tr>
<td><tt>['consul']['atlas_token']</tt></td>
<td>String</td>
<td>
API token used for Atlas integration
</td>
<td><tt>nil</tt></td>
</tr>
</table>

### Databag Attributes (optional)
Expand Down
5 changes: 5 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@
default['consul']['client_addr'] = '0.0.0.0'
default['consul']['serve_ui'] = false
default['consul']['extra_params'] = {}

# Atlas support
default['consul']['atlas_autojoin'] = false
default['consul']['atlas_cluster'] = nil
default['consul']['atlas_token'] = nil
11 changes: 11 additions & 0 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@
end
end

# Atlas integration
if node.consul.atlas_autojoin or node.consul.atlas_token
cluster = node.consul.atlas_cluster
token = node.consul.atlas_token
raise "atlas_cluster is empty or nil" if cluster.empty? or cluster.nil?
raise "atlas_token is empty or nil" if token.empty? or token.nil?
service_config['atlas_infrastructure'] = cluster
service_config['atlas_join'] = node.consul.atlas_autojoin
service_config['atlas_token'] = token
end

consul_config_filename = File.join(node['consul']['config_dir'], 'default.json')

file consul_config_filename do
Expand Down
22 changes: 22 additions & 0 deletions test/integration/atlas/serverspec/localhost/atlas_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

describe command('which consul') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match '/usr/local/bin/consul' }
end

describe service('consul') do
it { should be_enabled }
it { should be_running }
end

describe file('/etc/consul.d') do
it { should be_directory }
end

describe command('grep atlas /etc/consul.d/default.json') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{"atlas_infrastructure":\s"([^"]*)"} }
its(:stdout) { should match %r{"atlas_join":\s(true|false)} }
its(:stdout) { should match %r{"atlas_token":\s"([^"]*)"} }
end
7 changes: 7 additions & 0 deletions test/integration/atlas/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'serverspec'

set :backend, :exec

RSpec.configure do |c|
c.path = '/usr/local/bin:/sbin:/bin:/usr/bin'
end

0 comments on commit 39dd110

Please sign in to comment.