Skip to content

Commit

Permalink
config-generator: Add generator for v2 config
Browse files Browse the repository at this point in the history
Create new config generation task, that would generate v2 config.
This tas should be more interactable and friendly to new
testsuite users.

Refs: #2138
Signed-off-by: Konstantin Yarovoy <[email protected]>
  • Loading branch information
Konstantin Yarovoy committed Sep 27, 2024
1 parent 6c76d20 commit 1f7fad7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/tasks/cnf_setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "sam"
require "file_utils"
require "colorize"
require "totem"
require "yaml"
require "./utils/utils.cr"

task "cnf_setup", ["helm_local_install", "create_namespace"] do |_, args|
Expand Down Expand Up @@ -76,6 +77,10 @@ task "generate_config" do |_, args|

end

task "generate_v2_config" do |_, args|
interactively_create_config()
end

#TODO force all cleanups to use generic cleanup
task "bad_helm_cnf_cleanup" do |_, args|
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-bad_helm_coredns-cnf", verbose: true)
Expand All @@ -99,3 +104,67 @@ end
task "sample_generic_cnf_cleanup" do |_, args|
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
end

def interactively_create_config
config = {
config_version: CNFInstall::Config::ConfigVersion::Latest.to_s,
deployments: {
helm_charts: [] of Hash(String, String),
helm_dirs: [] of Hash(String, String),
manifests: [] of Hash(String, String)
}
}

loop do
puts "Select deployment type:"
puts "1. Helm Chart"
puts "2. Helm Directory"
puts "3. Manifest Directory"
puts "4. Finish and save configuration"
choice = prompt("Enter your choice (1-4): ")

case choice
when "1"
helm_chart = {
"name" => prompt("Enter deployment name: "),
"helm_repo_name" => prompt("Enter Helm repository name: "),
"helm_repo_url" => prompt("Enter Helm repository URL: "),
"helm_chart_name" => prompt("Enter Helm chart name: ")
}
helm_chart["helm_chart_name"] = helm_chart["helm_repo_name"] + "/" + helm_chart["helm_chart_name"]
config[:deployments][:helm_charts] << helm_chart
when "2"
helm_dir = {
"name" => prompt("Enter deployment name: "),
"helm_directory" => prompt("Enter path to directory with Chart.yaml: ")
}
config[:deployments][:helm_dirs] << helm_dir
when "3"
manifest = {
"name" => prompt("Enter deployment name: "),
"manifest_directory" => prompt("Enter path to directory with manifest files: ")
}
config[:deployments][:manifests] << manifest
when "4"
break
else
puts "Invalid choice. Please try again."
end
end

yaml_config = config.to_yaml
puts "Generated Configuration:"
puts yaml_config

output_file = prompt("Choose output config path (leave empty for #{CONFIG_FILE}): ")
if output_file.strip.empty?
output_file = CONFIG_FILE
end
File.write(output_file, yaml_config)
puts "Configuration saved to #{output_file}"
end

def prompt(message)
print message
gets.try(&.strip) || ""
end

0 comments on commit 1f7fad7

Please sign in to comment.