Skip to content

Commit 7c7c38c

Browse files
authored
Merge pull request #514 from koshatul/fix-for-aliased-plugins
Fix aliased plugin names
2 parents fe78698 + 6c324f0 commit 7c7c38c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/puppet/parser/functions/docker_plugin_enable_flags.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ module Puppet::Parser::Functions
1010
opts = args[0] || {}
1111
flags = []
1212
flags << '--force' if opts['force_remove'] == true
13-
flags << "'#{opts['plugin_name']}'" if opts['plugin_name'] && opts['plugin_name'].to_s != 'undef'
13+
if opts['plugin_alias'] && opts['plugin_alias'].to_s != 'undef'
14+
flags << "'#{opts['plugin_alias']}'"
15+
elsif opts['plugin_name'] && opts['plugin_name'].to_s != 'undef'
16+
flags << "'#{opts['plugin_name']}'"
17+
end
1418
flags.flatten.join(' ')
1519
end
1620
end

manifests/plugin.pp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
})
8080

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

8484
exec { "plugin install ${plugin_name}":
8585
command => $exec_install,
@@ -95,7 +95,7 @@
9595
})
9696

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

100100
exec { "plugin remove ${plugin_name}":
101101
command => $exec_rm,
@@ -109,11 +109,12 @@
109109
if $enabled {
110110
$docker_plugin_enable_flags = docker_plugin_enable_flags({
111111
plugin_name => $plugin_name,
112+
plugin_alias => $plugin_alias,
112113
timeout => $timeout,
113114
})
114115

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

118119
exec { "plugin enable ${plugin_name}":
119120
command => $exec_enable,
@@ -129,7 +130,7 @@
129130
environment => 'HOME=/root',
130131
path => ['/bin', '/usr/bin'],
131132
timeout => 0,
132-
unless => "${docker_command} ls -f enabled=false | grep -w ${plugin_name}",
133+
unless => "${docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w ${plugin_name}",
133134
}
134135
}
135136
}

spec/defines/plugin_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@
1616
context 'with defaults for all parameters' do
1717
it { is_expected.to compile.with_all_deps }
1818
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_command(%r{docker plugin install}) }
19+
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_unless(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
1920
end
2021

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

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

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

3133
it { is_expected.to compile.with_all_deps }
3234
it { is_expected.to contain_exec('plugin remove foo/plugin:latest').with_command(%r{docker plugin rm}) }
35+
it { is_expected.to contain_exec('plugin remove foo/plugin:latest').with_onlyif(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
36+
end
37+
38+
context 'with alias => foo-plugin' do
39+
let(:params) { { 'plugin_alias' => 'foo-plugin' } }
40+
41+
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_command(%r{docker plugin install}) }
42+
it { is_expected.to contain_exec('plugin install foo/plugin:latest').with_unless(%r{docker ls --format='{{.PluginReference}}' | grep -w foo/plugin:latest}) }
3343
end
3444
end

0 commit comments

Comments
 (0)