-
Notifications
You must be signed in to change notification settings - Fork 70
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: export_published_chart correctly detects and exports tar file #2052
base: main
Are you sure you want to change the base?
Conversation
Refs: cnti-testcatalog#1947 - Fixes the issue where multiple tar files caused the Tar module to fail due to globbing, by selecting a single tgz file. - There was a line that was supposed to delete the tgz file (no idea why): FileUtils.rm_rf(tgz_name), which did not actually work due to the previously mentioned globbing, it was removed because it would now cause the program to fail. Signed-off-by: svteb <[email protected]>
Refs: cnti-testcatalog#1947 - Backtracked on removal of: FileUtils.rm_rf(tgz_name), made it functional through Dir.glob("#{Helm.chart_name(helm_chart)}-*.tgz"). Through this addition a state where multiple tgz archives are present is not possible. - Also added an exception in case a prior helm failure happens and no archive is pulled (not sure whether this state can be reached). Signed-off-by: svteb <[email protected]>
Comments from @martin-mat were correct in pointing out some unhandled cases/lack of information provided. I've come to understand the intentions behind
It was necessary to do it like this because Another mistake from the previous commit, that was undiscovered, was the necessity of moving this entire block before the block where tgz archive is being discovered, as the
Furthermore I added an exception that prints better information in case no tgz file is discovered. |
- Dir.glob functionality for getting tgz files in the working directory abstracted into a function - get_tgz_name function made more generic - outputs made more explicit Signed-off-by: svteb <[email protected]>
2bfb97c
to
255da4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, good refactoring!
src/tasks/utils/cnf_manager.cr
Outdated
unless input_file && !input_file.empty? | ||
FileUtils.rm_rf(tgz_name) | ||
files_to_delete = find_tgz_files(helm_chart) | ||
files_to_delete.each do |file| | ||
FileUtils.rm(file) | ||
Log.info { "Deleted: #{file}" } | ||
end | ||
|
||
helm_info = Helm.pull(helm_chart) | ||
unless helm_info[:status].success? | ||
puts "Helm pull error".colorize(:red) | ||
raise "Helm pull error" | ||
end | ||
end | ||
|
||
TarClient.untar(tgz_name, "#{destination_cnf_dir}/exported_chart") | ||
# get the tgz file name | ||
if input_file && !input_file.empty? | ||
# todo add generate and set tar as well | ||
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_testsuite_yml_path(config_file), airgapped: true) | ||
tar_info = AirGap.tar_info_by_config_src(helm_chart) | ||
tgz_name = tar_info[:tar_name] | ||
else | ||
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_testsuite_yml_path(config_file), generate_tar_mode: output_file && !output_file.empty?) | ||
tgz_name = get_and_verify_tgz_name(helm_chart) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that these "if" statements should be joined and each logical branch marked with comments:
if input_file && !input_file.empty? # Input file present, existing Tar exctraction mode
...
else # Input file absent, Pulled chart tar extraction mode
...
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, I reduced it to one if else block, should be alright now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than mentioned problem - looks nice: fixes the Tar problem and refactors the code
cdcf9b1
to
4746e73
Compare
Signed-off-by: svteb <[email protected]>
4746e73
to
c764af9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
Removed file globbing as it caused errors and added a new function that will detect a specific tgz file to be untared. Removed the line:
FileUtils.rm_rf(tgz_name)
as it did not work previously and now that globbing has been fixed it would cause undesired behavior (honestly I was not able to figure out why it is there at all).Issues:
Refs: #1947
How has this been tested:
Types of changes:
Checklist:
Documentation
Code Review
Issue