From 20b7de21a2691181bcaf03172494b575549ac621 Mon Sep 17 00:00:00 2001 From: Nick Maludy Date: Wed, 16 Dec 2020 22:19:55 -0500 Subject: [PATCH 1/3] Reworking the way that the tdagent gem package provider works and finds its command --- lib/puppet/provider/package/tdagent.rb | 46 ++++++++++++++++---------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/puppet/provider/package/tdagent.rb b/lib/puppet/provider/package/tdagent.rb index b69a7b7..e0db9d4 100644 --- a/lib/puppet/provider/package/tdagent.rb +++ b/lib/puppet/provider/package/tdagent.rb @@ -1,25 +1,35 @@ 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 + + # TODO: should we also look in PATH? + def self.provider_command + 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/td-agent-gem', + ] 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 From 31870d3e6ba274a58b417baa0cedcc5657108395 Mon Sep 17 00:00:00 2001 From: Nick Maludy Date: Thu, 17 Dec 2020 00:06:07 -0500 Subject: [PATCH 2/3] Release v1.0.2 --- CHANGELOG.md | 9 +++++++++ lib/puppet/provider/package/tdagent.rb | 7 ++++--- metadata.json | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7827efc..9b800dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## 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) + ## 2020-11-13 - Release v1.0.1 - Fix td-agent YUM repo URL for v4 on RHEL/CentOS not behaving correctly when $releasever diff --git a/lib/puppet/provider/package/tdagent.rb b/lib/puppet/provider/package/tdagent.rb index e0db9d4..bb23764 100644 --- a/lib/puppet/provider/package/tdagent.rb +++ b/lib/puppet/provider/package/tdagent.rb @@ -11,8 +11,9 @@ def self.which_from_paths(command, paths) 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 - # TODO: should we also look in PATH? 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 = [ @@ -25,9 +26,9 @@ def self.provider_command gem_cmd = 'td-agent-gem' search_paths = [ # v3, v4 and newer - '/usr/sbin/', + '/usr/sbin', # v0 - '/opt/td-agent/usr/sbin/td-agent-gem', + '/opt/td-agent/usr/sbin', ] end which_from_paths(gem_cmd, search_paths) diff --git a/metadata.json b/metadata.json index ffc2d31..065b87e 100644 --- a/metadata.json +++ b/metadata.json @@ -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", From 0809275e1efd64d080545f178fc8212c0561b3ba Mon Sep 17 00:00:00 2001 From: Nick Maludy Date: Thu, 17 Dec 2020 00:11:19 -0500 Subject: [PATCH 3/3] Remove hotfix for v4 repository not redirecting for 7Server --- CHANGELOG.md | 5 +++++ manifests/repo.pp | 12 +----------- spec/classes/repo_spec.rb | 5 +---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b800dd..0c72535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ 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 diff --git a/manifests/repo.pp b/manifests/repo.pp index 5d6182c..0d075d4 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -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, diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 1d8590f..6ea4182 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -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')