Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Kubernetes recipe #409

Merged
merged 3 commits into from Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions recipes/kubernetes.rb
@@ -0,0 +1,30 @@
include_recipe 'datadog::dd-agent'

# Monitor kubernetes
#
# Assuming you have a kubernetes instance on a given server, you will need to set
# up the following attributes at some point in your Chef run, in either
# a role or another cookbook.
#
# node['datadog']['kubernetes']['instances'] = [
# {
# 'host' => 'localhost',
# 'port' => 4194,
# 'method' => 'http',
# 'kubelet_port' => 10255,
# 'namespace' => 'default'
# 'collect_events' => false,
# 'use_histogram' => false,
# 'enabled_rates' => [
# 'cpu.*',
# 'network.*'
# ],
# 'enabled_gauges' => [
# 'filesystem.*'
# ]
# }
# ]

datadog_monitor 'kubernetes' do
instances node['datadog']['kubernetes']['instances']
end
49 changes: 49 additions & 0 deletions spec/integrations/kubernetes_spec.rb
@@ -0,0 +1,49 @@
describe 'datadog::kubernetes' do
expected_yaml = <<-EOF
instances:
- host: localhost
port: 4194
kubelet_port: 10255
enabled_rates:
- cpu.*
- network.*
init_config:
EOF

cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
node.automatic['languages'] = { python: { version: '2.7.2' } }

node.set['datadog'] = {
api_key: 'someapikey',
kubernetes: {
instances: [
{
host: 'localhost',
port: 4194,
kubelet_port: 10255,
enabled_rates: [
'cpu.*',
'network.*'
]
}
]
}
}
end.converge(described_recipe)
end

subject { chef_run }

it_behaves_like 'datadog-agent'

it { is_expected.to include_recipe('datadog::dd-agent') }

it { is_expected.to add_datadog_monitor('kubernetes') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/kubernetes.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
4 changes: 4 additions & 0 deletions templates/default/kubernetes.yaml.erb
@@ -0,0 +1,4 @@
<%= JSON.parse(({ 'instances' => @instances }).to_json).to_yaml %>

# Nothing to configure here
init_config: