Skip to content

Commit

Permalink
Merge pull request #17 from EncoreTechnologies/hotfix/package
Browse files Browse the repository at this point in the history
Reworking the way that the tdagent gem package provider works and fin…
  • Loading branch information
nmaludy authored Dec 17, 2020
2 parents 0afcd62 + 0809275 commit f3bc6e9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
## Development

## 2020-11-13 - Release v1.0.2

- Fix `tdagent` provider for `package` to implement proper lazy delay of its commands
and pick up the correct command path once `td-agent` is properly installed.
This fixes a bug where the `tdagent` provider for `package` was not usable during
the Puppet run when `td-agent` is installed.

Contributed by Nick Maludy (@nmaludy)

- Removed fix put in place in v1.0.1 for RHE/CentOS $releasever workaround.
Treasure Data has fixed the problem on their repo and "7Server" now redirects properly.

Contributed by Nick Maludy (@nmaludy)

## 2020-11-13 - Release v1.0.1

- Fix td-agent YUM repo URL for v4 on RHEL/CentOS not behaving correctly when $releasever
Expand Down
47 changes: 29 additions & 18 deletions lib/puppet/provider/package/tdagent.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
Puppet::Type.type(:package).provide :tdagent, parent: :gem, source: :gem do
has_feature :install_options, :versionable

# yes, i know this isn't how you're "supposed" to do it, but because
# we're overriding the "gem" package provider here, we need this to be
# one named provider for use in our package resources.
if Puppet::Util::Platform.windows?
if Puppet::FileSystem.exist?('C:/opt/td-agent/bin/fluent-gem.bat')
# v4 and newer
commands gemcmd: 'C:/opt/td-agent/bin/fluent-gem.bat'
def self.which_from_paths(command, paths)
# copied/inspired by puppet/util.rb which() function
# this allows you to pass in your own custom search paths
paths.each do |dir|
dest = File.expand_path(File.join(dir, command))
return dest if FileTest.file?(dest) && FileTest.executable?(dest)
end
raise Puppet::Error, _("Provider %{name} package command '%{command}' does not exist on this host, it couldn't be found in the following paths: %{paths}") % { name: name, cmd: cmd, paths: paths }
end

def self.provider_command
# FUTURE: if this still isn't good enough in the future we could append the PATH
# components and look there too
if Puppet::Util::Platform.windows?
gem_cmd = 'fluent-gem.bat'
search_paths = [
# v4 and newer
'C:\\opt\\td-agent\\bin',
# v3 and older
'C:\\opt\\td-agent\\embedded\\bin',
]
else
# v3 and older
commands gemcmd: 'C:/opt/td-agent/embedded/bin/fluent-gem.bat'
gem_cmd = 'td-agent-gem'
search_paths = [
# v3, v4 and newer
'/usr/sbin',
# v0
'/opt/td-agent/usr/sbin',
]
end
elsif Puppet::FileSystem.exist?('/usr/sbin/td-agent-gem')
# v3, v4 and newer
commands gemcmd: '/usr/sbin/td-agent-gem'
elsif Puppet::FileSystem.exist?('/opt/td-agent/usr/sbin/td-agent-gem')
# v0
commands gemcmd: '/opt/td-agent/usr/sbin/td-agent-gem'
else
# use PATH to resolve
commands gemcmd: 'td-agent-gem'
which_from_paths(gem_cmd, search_paths)
end
end
12 changes: 1 addition & 11 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
$version = $fluentd::repo_version
case $facts['os']['family'] {
'RedHat': {
# Version 4 of the YUM repo doesn't behave correctly when yum $releasever
# is set to something like "7Server", instead it expects it to simply be
# the major version "7".
# I'm sure this will get fixed at some point, see:
# https://github.com/fluent/fluentd-docs-gitbook/issues/222
$releasever = $version ? {
'4' => $facts['os']['release']['major'],
default => "\$releasever",
}

$repo_url = pick($fluentd::repo_url,
"http://packages.treasuredata.com/${version}/redhat/${releasever}/\$basearch")
"http://packages.treasuredata.com/${version}/redhat/\$releasever/\$basearch")
yumrepo { $fluentd::repo_name:
descr => $fluentd::repo_desc,
baseurl => $repo_url,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "encore-fluentd",
"version": "1.0.1",
"version": "1.0.2",
"author": "encore",
"summary": "Installs, configures, and manages Fluentd data collector",
"license": "Apache-2.0",
Expand Down
5 changes: 1 addition & 4 deletions spec/classes/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@

if os_facts[:os]['family'] == 'RedHat'
it do
# FYI v4 needs to hard code major version instead of $releasever
# see https://github.com/fluent/fluentd-docs-gitbook/issues/222
# hopefully this gets fixed in the future
is_expected.to contain_yumrepo('treasuredata')
.with('descr' => 'TreasureData',
'baseurl' => "http://packages.treasuredata.com/4/redhat/#{os_facts[:os]['release']['major']}/\$basearch",
'baseurl' => "http://packages.treasuredata.com/4/redhat/\$releasever/\$basearch",
'enabled' => true,
'gpgcheck' => true,
'gpgkey' => 'https://packages.treasuredata.com/GPG-KEY-td-agent')
Expand Down

0 comments on commit f3bc6e9

Please sign in to comment.