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

Add support of IOT agent flavor #717

Merged
merged 5 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
# Example:
# default['datadog']['agent_version'] = '7.16.0'
default['datadog']['agent_version'] = nil # nil to install latest
# Agent flavor, acceptable values are "agent", iot-agent"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: on the Agent we use agent and iot_agent for the flavors, maybe we could use those values here too for consistency? I am not sure if the other ones are user-facing though, but just in case they ever are.

Copy link
Contributor

@albertvaka albertvaka May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like iot-agent better because it matches the name of the package (datadog-iot-agent). The flavor names in the Agent code are to identify them on our side, but shouldn't be user-facing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks Albert

kbogtob marked this conversation as resolved.
Show resolved Hide resolved
default['datadog']['agent_flavor'] = 'agent' # "agent" to install default agent
kbogtob marked this conversation as resolved.
Show resolved Hide resolved

# Allow override with `upgrade` to get latest (Linux only)
default['datadog']['agent_package_action'] = 'install'
Expand Down
13 changes: 13 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ suites:
api_key: somenonnullapikeythats32charlong
application_key: alsonotnil

- name: dd-agent-iot
run_list:
- recipe[datadog::dd-agent]
attributes:
datadog: &DATADOG
api_key: somenonnullapikeythats32charlong
application_key: alsonotnil
install_info_enabled: true
agent_flavor: iot-agent
aptrepo: 'https://apt.datad0g.com'
aptrepo_dist: 'beta'
agent_version: '7.20.0~rc.3'

- name: system-probe
run_list:
- recipe[datadog::dd-agent]
Expand Down
17 changes: 17 additions & 0 deletions libraries/recipe_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class Chef
# Helper class for Datadog Chef recipes
class Datadog
class << self
ACCEPTABLE_AGENT_FLAVORS = %w[
agent
iot-agent
].freeze

def agent_version(node)
dd_agent_version = node['datadog']['agent_version']
if dd_agent_version.respond_to?(:each_pair)
Expand Down Expand Up @@ -47,6 +52,18 @@ def agent_major_version(node)
7
end

def agent_flavor(node)
# user-specified values
agent_flavor = node['datadog']['agent_flavor']
agent_flavor ||= node.default['datadog']['agent_flavor']

unless ACCEPTABLE_AGENT_FLAVORS.include?(agent_flavor)
raise "Unknown agent flavor '#{agent_flavor}' (acceptable values: #{ACCEPTABLE_AGENT_FLAVORS.inspect})"
end

agent_flavor
end

def api_key(node)
run_state_or_attribute(node, 'api_key')
end
Expand Down
12 changes: 8 additions & 4 deletions recipes/_install-linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
include_recipe 'datadog::repository' if node['datadog']['installrepo']

dd_agent_version = Chef::Datadog.agent_version(node)
dd_agent_flavor = Chef::Datadog.agent_flavor(node)

package_name = "datadog-#{dd_agent_flavor}"

package_action = node['datadog']['agent_package_action']

package_retries = node['datadog']['agent_package_retries']
package_retry_delay = node['datadog']['agent_package_retry_delay']

# Install the regular package
case node['platform_family']
when 'debian'
apt_package 'datadog-agent' do
apt_package package_name do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand All @@ -41,14 +45,14 @@
node['platform_family'] == 'fedora' && node['platform_version'].to_i >= 28
# yum_package doesn't work on RHEL 8 and Fedora >= 28
# dnf_package only works on RHEL 8 / Fedora >= 28 if Chef 15+ is used
dnf_package 'datadog-agent' do
dnf_package package_name do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
action package_action # default is :install
end
else
yum_package 'datadog-agent' do
yum_package package_name do
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand All @@ -57,7 +61,7 @@
end
end
when 'suse'
zypper_package 'datadog-agent' do # ~FC009
zypper_package package_name do # ~FC009
version dd_agent_version
retries package_retries unless package_retries.nil?
retry_delay package_retry_delay unless package_retry_delay.nil?
Expand Down
5 changes: 5 additions & 0 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#

dd_agent_version = Chef::Datadog.agent_version(node)
dd_agent_flavor = Chef::Datadog.agent_flavor(node)

if dd_agent_flavor != 'agent'
raise "Unsupported agent flavor '#{dd_agent_flavor}' on Windows (only supports 'agent')"
end

if dd_agent_version.nil?
# Use latest
Expand Down
29 changes: 29 additions & 0 deletions test/integration/dd-agent-iot/serverspec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

@agent_package_name = 'datadog-iot-agent'

describe package(@agent_package_name) do
it { should be_installed }
end

describe service(@agent_service_name) do
it { should be_running }
end

describe command('/opt/datadog-agent/bin/agent/agent status | grep -v "Instance ID"'), :if => os[:family] != 'windows' do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain '[OK]' }
its(:stdout) { should_not contain 'ERROR' }
end

# The new APT key is imported
describe command('apt-key list'), :if => ['debian', 'ubuntu'].include?(os[:family]) do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain '382E94DE' }
end

# The new RPM key is imported
describe command('rpm -q gpg-pubkey-e09422b3'), :if => os[:family] == 'redhat' do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain 'gpg-pubkey-e09422b3' }
end
25 changes: 25 additions & 0 deletions test/integration/dd-agent-iot/serverspec/install_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

@agent_package_name = 'datadog-iot-agent'

describe 'Install infos' do
let(:install_info_path) do
if os == :windows
"#{ENV['ProgramData']}\\Datadog\\install_info"
else
'/etc/datadog-agent/install_info'
end
end

let(:install_info) do
YAML.load_file(install_info_path)
end

it 'adds an install_info' do
expect(install_info['install_method']).to match(
'tool_version' => /chef-\d+\.\d+\.\d+/,
'tool' => 'chef',
'installer_version' => /^datadog_cookbook-\d+\.\d+\.\d+$/
)
end
end