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: export_published_chart correctly detects and exports tar file #2052

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Changes from 2 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
49 changes: 37 additions & 12 deletions src/tasks/utils/cnf_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -721,30 +721,38 @@ module CNFManager

input_file = cli_args[:input_file]
output_file = cli_args[:output_file]

# delete previous tgz files and pull the helm chart
unless input_file && !input_file.empty?
files_to_delete = Dir.glob("#{Helm.chart_name(helm_chart)}-*.tgz")
files_to_delete.each do |file|
FileUtils.rm(file)
puts "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

# 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]
elsif output_file && !output_file.empty?
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_testsuite_yml_path(config_file), generate_tar_mode: true)
tgz_name = "#{Helm.chart_name(helm_chart)}-*.tgz"
tgz_name = get_tgz_name(helm_chart)
else
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_testsuite_yml_path(config_file))
tgz_name = "#{Helm.chart_name(helm_chart)}-*.tgz"
tgz_name = get_tgz_name(helm_chart)
end
Log.info { "tgz_name: #{tgz_name}" }

unless input_file && !input_file.empty?
FileUtils.rm_rf(tgz_name)
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")
TarClient.untar(tgz_name, "#{destination_cnf_dir}/exported_chart")

Log.for("verbose").info { "mv #{destination_cnf_dir}/exported_chart/#{Helm.chart_name(helm_chart)}/* #{destination_cnf_dir}/exported_chart" } if verbose
Log.for("verbose").debug {
Expand Down Expand Up @@ -1259,6 +1267,18 @@ module CNFManager
resource_keys.includes?(resource_key)
end

def self.get_tgz_name(helm_chart)
tgz_files = Dir.glob("#{Helm.chart_name(helm_chart)}-*.tgz")

# In case no tgz file is present (should only happen if there was a prior helm failure).
if tgz_files.empty?
Log.error { "No .tgz files found for #{Helm.chart_name(helm_chart)}" }
raise TarFileNotFoundError.new(Helm.chart_name(helm_chart))
end

tgz_files.first
end

class HelmDirectoryMissingError < Exception
property helm_directory : String = ""

Expand All @@ -1267,4 +1287,9 @@ module CNFManager
end
end

class TarFileNotFoundError < Exception
def initialize(chart_name)
super("No .tgz files found for chart #{chart_name}")
end
end
end
Loading