diff --git a/CHANGELOG.md b/CHANGELOG.md index 7827efc..0c72535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/puppet/provider/package/tdagent.rb b/lib/puppet/provider/package/tdagent.rb index b69a7b7..bb23764 100644 --- a/lib/puppet/provider/package/tdagent.rb +++ b/lib/puppet/provider/package/tdagent.rb @@ -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 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/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", 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')