Skip to content

Commit e30e6f0

Browse files
committed
Properly handle idempotently removing image
Signed-off-by: Eric D. Helms <[email protected]>
1 parent c15aaab commit e30e6f0

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

manifests/image.pp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,19 @@
7373
}
7474
}
7575

76-
case $ensure {
77-
'present': {
78-
exec { "pull_image_${title}":
79-
command => "podman image pull ${_flags} ${image}",
80-
unless => "podman image exists ${image}",
81-
path => '/sbin:/usr/sbin:/bin:/usr/bin',
82-
* => $exec_defaults,
83-
}
76+
if $ensure == 'present' {
77+
exec { "pull_image_${title}":
78+
command => "podman image pull ${_flags} ${image}",
79+
unless => "podman image exists ${image}",
80+
path => '/sbin:/usr/sbin:/bin:/usr/bin',
81+
* => $exec_defaults,
8482
}
85-
default: {
86-
exec { "pull_image_${title}":
87-
command => "podman image pull ${_flags} ${image}",
88-
unless => "podman rmi ${image}",
89-
path => '/sbin:/usr/sbin:/bin:/usr/bin',
90-
* => $exec_defaults,
91-
}
83+
} elsif $ensure == 'absent' {
84+
exec { "remove_image_${title}":
85+
command => "podman rmi ${image}",
86+
onlyif => "podman image exists ${image}",
87+
path => '/sbin:/usr/sbin:/bin:/usr/bin',
88+
* => $exec_defaults,
9289
}
9390
}
9491
}

spec/defines/image_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
let(:params) { { ensure: 'absent', image: 'image:test' } }
5656

5757
it do
58-
is_expected.to contain_exec('pull_image_title').only_with(
58+
is_expected.to contain_exec('remove_image_title').only_with(
5959
{
60-
'command' => 'podman image pull image:test',
61-
'unless' => 'podman rmi image:test',
60+
'command' => 'podman rmi image:test',
61+
'onlyif' => 'podman image exists image:test',
6262
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
6363
'environment' => [],
6464
},
@@ -84,10 +84,10 @@
8484
it { is_expected.to contain_podman__rootless('dummy').only_with({}) }
8585

8686
it do
87-
is_expected.to contain_exec('pull_image_title').only_with(
87+
is_expected.to contain_exec('remove_image_title').only_with(
8888
{
89-
'command' => 'podman image pull image:test',
90-
'unless' => 'podman rmi image:test',
89+
'command' => 'podman rmi image:test',
90+
'onlyif' => 'podman image exists image:test',
9191
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
9292
'environment' => ['HOME=/home/dummy', 'XDG_RUNTIME_DIR=/run/user/3333', 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/3333/bus'],
9393
'cwd' => '/home/dummy',
@@ -156,9 +156,9 @@
156156
let(:params) { { flags: { publish: ['242:242'], volume: 'jenkins:/test/ing' }, ensure: 'absent', image: 'image:test' } }
157157

158158
it do
159-
is_expected.to contain_exec('pull_image_title').with(
159+
is_expected.to contain_exec('remove_image_title').with(
160160
{
161-
'command' => "podman image pull --publish '242:242' --volume 'jenkins:/test/ing' image:test",
161+
'command' => 'podman rmi image:test',
162162
},
163163
)
164164
end
@@ -223,10 +223,10 @@
223223
it { is_expected.to contain_podman__rootless('testing').only_with({}) }
224224

225225
it do
226-
is_expected.to contain_exec('pull_image_title').only_with(
226+
is_expected.to contain_exec('remove_image_title').only_with(
227227
{
228-
'command' => 'podman image pull image:test',
229-
'unless' => 'podman rmi image:test',
228+
'command' => 'podman rmi image:test',
229+
'onlyif' => 'podman image exists image:test',
230230
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
231231
'environment' => ['HOME=/home/testing', 'XDG_RUNTIME_DIR=/run/user/3333', 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/3333/bus'],
232232
'cwd' => '/home/testing',

0 commit comments

Comments
 (0)