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

Fix aliased plugin names #514

Merged
merged 5 commits into from
Aug 27, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/puppet/parser/functions/docker_plugin_enable_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module Puppet::Parser::Functions
opts = args[0] || {}
flags = []
flags << '--force' if opts['force_remove'] == true
flags << "'#{opts['plugin_name']}'" if opts['plugin_name'] && opts['plugin_name'].to_s != 'undef'
if opts['plugin_alias'] && opts['plugin_alias'].to_s != 'undef'
flags << "'#{opts['plugin_alias']}'"
elsif opts['plugin_name'] && opts['plugin_name'].to_s != 'undef'
flags << "'#{opts['plugin_name']}'"
end
flags.flatten.join(' ')
end
end
9 changes: 5 additions & 4 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
})

$exec_install = "${docker_command} install ${docker_plugin_install_flags}"
$unless_install = "${docker_command} ls | grep -w ${plugin_name}"
$unless_install = "${docker_command} ls --format='{{.PluginReference}}' | grep -w ${plugin_name}"

exec { "plugin install ${plugin_name}":
command => $exec_install,
Expand All @@ -95,7 +95,7 @@
})

$exec_rm = "${docker_command} rm ${docker_plugin_remove_flags}"
$onlyif_rm = "${docker_command} ls | grep -w ${plugin_name}"
$onlyif_rm = "${docker_command} ls --format='{{.PluginReference}}' | grep -w ${plugin_name}"

exec { "plugin remove ${plugin_name}":
command => $exec_rm,
Expand All @@ -109,11 +109,12 @@
if $enabled {
$docker_plugin_enable_flags = docker_plugin_enable_flags({
plugin_name => $plugin_name,
plugin_alias => $plugin_alias,
timeout => $timeout,
})

$exec_enable = "${docker_command} enable ${docker_plugin_enable_flags}"
$onlyif_enable = "${docker_command} ls -f enabled=false | grep -w ${plugin_name}"
$onlyif_enable = "${docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w ${plugin_name}"

exec { "plugin enable ${plugin_name}":
command => $exec_enable,
Expand All @@ -129,7 +130,7 @@
environment => 'HOME=/root',
path => ['/bin', '/usr/bin'],
timeout => 0,
unless => "${docker_command} ls -f enabled=false | grep -w ${plugin_name}",
unless => "${docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w ${plugin_name}",
}
}
}
10 changes: 10 additions & 0 deletions spec/defines/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@
context 'with defaults for all parameters' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_command(%r{docker plugin install}) }
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_unless(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
end

context 'with enabled => false' do
let(:params) { { 'enabled' => false } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('disable foo/plugin:latest').with_command(%r{docker plugin disable}) }
it { is_expected.to contain_exec('disable foo/plugin:latest').with_unless(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
end

context 'with ensure => absent' do
let(:params) { { 'ensure' => 'absent' } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('plugin remove foo/plugin:latest').with_command(%r{docker plugin rm}) }
it { is_expected.to contain_exec('plugin remove foo/plugin:latest').with_onlyif(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
end

context 'with alias => foo-plugin' do
let(:params) { { 'plugin_alias' => 'foo-plugin' } }

it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_command(%r{docker plugin install}) }
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_unless(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
end
end