Skip to content

Commit 048a3fd

Browse files
ehelmsevgeni
authored andcommitted
Fix iop_frontend trying to pull image with ensure absent
Signed-off-by: Eric D. Helms <[email protected]>
1 parent 86e2134 commit 048a3fd

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

lib/puppet/provider/iop_frontend/podman.rb

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,56 @@
1212
commands runtime: 'podman'
1313

1414
def exists?
15-
desired_checksum = get_image_content_checksum
16-
17-
unless File.directory?(resource[:destination])
18-
Puppet.debug("Destination #{resource[:destination]} not found. Resource does not exist.")
19-
return false
20-
end
21-
22-
current_checksum = get_deployed_checksum
23-
24-
in_sync = current_checksum == desired_checksum
25-
Puppet.debug("Current checksum: #{current_checksum}, Desired checksum: #{desired_checksum}. In sync: #{in_sync}")
15+
File.exist?(metadata_file)
16+
end
2617

27-
cleanup(nil, @staged_content_path) if in_sync
18+
def image
19+
get_deployed_checksum.to_s
20+
end
2821

29-
in_sync
22+
def image=(value)
23+
create
3024
end
3125

3226
def create
3327
Puppet.info("Deploying new frontend content to '#{resource[:destination]}'")
3428

3529
destroy if File.directory?(resource[:destination])
3630

37-
Puppet.debug("Copying staged content from '#{@staged_content_path}' to '#{resource[:destination]}'")
31+
staged_content_path, new_content_checksum = stage_content
32+
Puppet.debug("Copying staged content from '#{staged_content_path}' to '#{resource[:destination]}'")
3833
Dir.mkdir(resource[:destination], 0755)
39-
FileUtils.cp_r(Dir.glob(File.join(@staged_content_path, '*')), resource[:destination])
34+
FileUtils.cp_r(Dir.glob(File.join(staged_content_path, '*')), resource[:destination])
4035

4136
restore_selinux_context(resource[:destination])
4237

43-
metadata_file = File.join(resource[:destination], '.iop_frontend_checksum')
44-
Puppet.debug("Writing new checksum #{@new_content_checksum} to #{metadata_file}")
45-
File.write(metadata_file, @new_content_checksum)
46-
47-
@staged_content_path = nil
48-
@new_content_checksum = nil
38+
Puppet.debug("Writing new checksum #{new_content_checksum} to #{metadata_file}")
39+
File.write(metadata_file, new_content_checksum)
4940
end
5041

5142
def destroy
5243
Puppet.info("Removing frontend at '#{resource[:destination]}'")
5344
FileUtils.rm_rf(resource[:destination])
5445
end
5546

47+
def content_checksum
48+
path, checksum = stage_content
49+
checksum
50+
end
51+
5652
private
5753

54+
def metadata_file
55+
File.join(resource[:destination], '.iop_frontend_checksum')
56+
end
57+
5858
def get_deployed_checksum
59-
metadata_file = File.join(resource[:destination], '.iop_frontend_checksum')
6059
return nil unless File.exist?(metadata_file)
6160

6261
File.read(metadata_file).strip
6362
end
6463

65-
def get_image_content_checksum
66-
return @new_content_checksum if @new_content_checksum
67-
64+
def stage_content
6865
temp_container_name = "iop-frontend-checker-#{resource.title.gsub(/[^0-9a-zA-Z]/, '-')}"
6966
staging_dir = Dir.mktmpdir('iop_frontend_check')
7067

@@ -73,10 +70,10 @@ def get_image_content_checksum
7370
source_in_container = "#{temp_container_name}:#{resource[:source_path]}/."
7471
execute(['podman', 'cp', source_in_container, staging_dir])
7572

76-
@new_content_checksum = calculate_checksum_for_path(staging_dir)
77-
@staged_content_path = staging_dir
73+
new_content_checksum = calculate_checksum_for_path(staging_dir)
74+
staged_content_path = staging_dir
7875

79-
return @new_content_checksum
76+
return staged_content_path, new_content_checksum
8077
rescue Puppet::ExecutionFailure => e
8178
Puppet.err("Failed to get content checksum from image '#{resource[:image]}': #{e.message}")
8279
cleanup(temp_container_name, staging_dir)

lib/puppet/type/iop_frontend.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,26 @@
1313
end
1414
end
1515

16-
newparam(:image) do
16+
newproperty(:image) do
1717
desc 'The full name of the container image to pull, including the tag (e.g., "registry.example.com/my-app:latest").'
1818

1919
validate do |value|
2020
unless value.is_a?(String)
2121
raise ArgumentError, "Image must be a string, not '#{value.class}'"
2222
end
2323
end
24+
25+
def content_checksum
26+
provider.content_checksum.to_s
27+
end
28+
29+
def should_to_s(newvalue)
30+
self.class.format_value_for_display(content_checksum)
31+
end
32+
33+
def insync?(is)
34+
is.to_s == content_checksum
35+
end
2436
end
2537

2638
newparam(:source_path) do

0 commit comments

Comments
 (0)