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

installation: CNF Installation (6) New installation process #2165

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 2 additions & 23 deletions spec/utils/utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,9 @@ describe "Utils" do

it "'single_task_runner' should put a 1 in the results file if it has an exception", tags: ["task_runner"] do
CNFManager::Points.clean_results_yml
args = Sam::Args.new(["cnf-config=./cnf-testsuite.yml"])
args = Sam::Args.new()
task_response = CNFManager::Task.single_task_runner(args) do
cdir = FileUtils.pwd()
response = String::Builder.new
config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(args.named["cnf-config"].as(String)))
helm_directory = config.deployments.get_deployment_param(:helm_directory)
if File.directory?(CNFManager.ensure_cnf_testsuite_dir(args.named["cnf-config"].as(String)) + helm_directory)
Dir.cd(CNFManager.ensure_cnf_testsuite_dir(args.named["cnf-config"].as(String)) + helm_directory)
Process.run("grep -r -P '^(?!.+0\.0\.0\.0)(?![[:space:]]*0\.0\.0\.0)(?!#)(?![[:space:]]*#)(?!\/\/)(?![[:space:]]*\/\/)(?!\/\\*)(?![[:space:]]*\/\\*)(.+([0-9]{1,3}[\.]){3}[0-9]{1,3})'", shell: true) do |proc|
while line = proc.output.gets
response << line
end
end
Dir.cd(cdir)
if response.to_s.size > 0
resp = upsert_failed_task("ip_addresses","✖️ FAILED: IP addresses found", Time.utc)
else
resp = upsert_passed_task("ip_addresses", "✔️ PASSED: No IP addresses found", Time.utc)
end
resp
else
Dir.cd(cdir)
resp = upsert_passed_task("ip_addresses", "✔️ PASSED: No IP addresses found", Time.utc)
end
raise Exception.new()
end
yaml = File.open("#{CNFManager::Points::Results.file}") do |file|
YAML.parse(file)
Expand Down
21 changes: 21 additions & 0 deletions src/tasks/cnf_setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ task "sample_generic_cnf_cleanup" do |_, args|
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
end

task "new_cnf_setup" do |_, args|
if CNFManager.cnf_installed?
stdout_warning "A CNF is already set up. Setting up multiple CNFs is not allowed."
stdout_warning "To set up a new CNF, clean up the existing one by running: cnf_cleanup cnf-path=#{CNFManager.cnf_config_list.first}"
exit 0
end
if ClusterTools.install
stdout_success "ClusterTools installed"
else
stdout_failure "The ClusterTools installation timed out. Please check the status of the cluster-tools pods."
exit 1
end
stdout_success "CNF installation start."
CNFInstall.install_cnf(args)
stdout_success "CNF installation complete."
end

task "new_cnf_cleanup" do |_, args|
CNFInstall.uninstall_cnf()
end

def interactively_create_config
new_config = {
config_version: CNFInstall::Config::ConfigVersion::Latest.to_s,
Expand Down
3 changes: 3 additions & 0 deletions src/tasks/constants.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ require "./utils/embedded_file_manager.cr"

ESSENTIAL_PASSED_THRESHOLD = 15
CNF_DIR = "cnfs"
DEPLOYMENTS_DIR = File.join(CNF_DIR, "deployments")
CNF_TEMP_FILES_DIR = File.join(CNF_DIR, "temp_files")
CONFIG_FILE = "cnf-testsuite.yml"
BASE_CONFIG = "./config.yml"
COMMON_MANIFEST_FILE_PATH = "#{CNF_DIR}/common_manifest.yml"
DEPLOYMENT_MANIFEST_FILE_NAME = "deployment_manifest.yml"
PASSED = "passed"
FAILED = "failed"
SKIPPED = "skipped"
Expand Down
4 changes: 4 additions & 0 deletions src/tasks/utils/cnf_installation/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module CNFInstall
end

def self.parse_cnf_config_from_file(path_to_config)
if !File.exists?(path_to_config)
stdout_failure "No config found at #{path_to_config}."
exit 1
end
yaml_content = File.read(path_to_config)
config_dir = CNFManager.ensure_cnf_testsuite_dir(path_to_config)
begin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module CNFInstall
abstract class DeploymentManager
property deployment_name : String

abstract def install
abstract def uninstall
abstract def generate_manifest

def initialize(deployment_name)
@deployment_name = deployment_name
end
end


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
require "../config_versions/config_versions.cr"
require "./deployment_manager_common.cr"

module CNFInstall
abstract class HelmDeploymentManager < DeploymentManager
def initialize(deployment_name)
super(deployment_name)
end

abstract def get_deployment_config() : ConfigV2::HelmDeploymentConfig

def get_deployment_name()
helm_deployment_config = get_deployment_config()
helm_deployment_config.name()
end

def get_deployment_namespace()
helm_deployment_config = get_deployment_config()
helm_deployment_config.namespace.empty? ? DEFAULT_CNF_NAMESPACE : helm_deployment_config.namespace
end

def install_from_folder(chart_path, helm_namespace, helm_values)
begin
CNFManager.ensure_namespace_exists!(helm_namespace)
#TODO (kosstennbl) fix Helm install to add -n to namespace and remove it there
response = Helm.install(release_name: @deployment_name, helm_chart: chart_path, namespace: "-n #{helm_namespace}", values: helm_values)
if !response[:status].success?
stdout_failure "Helm installation failed, stderr:"
stdout_failure "\t#{response[:error]}"
exit 1
end
rescue e : Helm::InstallationFailed
stdout_failure "Helm installation failed with message:"
stdout_failure "\t#{e.message}"
exit 1
kosstennbl marked this conversation as resolved.
Show resolved Hide resolved
rescue e : Helm::CannotReuseReleaseNameError
stdout_failure "Helm deployment \"#{@deployment_name}\" already exists in \"#{helm_namespace}\" namespace."
stdout_failure "Change deployment name in CNF configuration or uninstall existing deployment."
exit 1
end
end

def uninstall()
deployment_name = get_deployment_name()
helm_uninstall_cmd = "#{deployment_name} -n #{get_deployment_namespace()}"
result = Helm.uninstall(helm_uninstall_cmd)
if result[:status].success?
stdout_success "Successfully uninstalled helm deployment \"#{deployment_name}\"."
end
end
kosstennbl marked this conversation as resolved.
Show resolved Hide resolved

def generate_manifest()
kosstennbl marked this conversation as resolved.
Show resolved Hide resolved
namespace = get_deployment_namespace()
generated_manifest = Helm.generate_manifest(get_deployment_name(), namespace)
generated_manifest_with_namespaces = Manifest.add_namespace_to_resources(generated_manifest, namespace)
end
end

class HelmChartDeploymentManager < HelmDeploymentManager
@helm_chart_config : ConfigV2::HelmChartConfig

def initialize(helm_chart_config)
super(helm_chart_config.name)
@helm_chart_config = helm_chart_config
end

def install()
helm_repo_url = @helm_chart_config.helm_repo_url
helm_repo_name = @helm_chart_config.helm_repo_name
helm_chart_name = @helm_chart_config.helm_chart_name

if !helm_repo_url.empty?
Helm.helm_repo_add(helm_repo_name, helm_repo_url)
end
helm_pull_destination = File.join(DEPLOYMENTS_DIR, @deployment_name)
helm_pull_cmd = "#{helm_repo_name}/#{helm_chart_name} --untar --destination #{helm_pull_destination}"
pull_response = Helm.pull(helm_pull_cmd)
if !pull_response[:status].success?
stdout_failure "Helm pull failed for deployment \"#{get_deployment_name()}\": #{pull_response[:error]}"
exit 1
end
chart_path = File.join(helm_pull_destination, helm_chart_name)
install_from_folder(chart_path, get_deployment_namespace(), @helm_chart_config.helm_values)
end

def get_deployment_config() : ConfigV2::HelmDeploymentConfig
@helm_chart_config
end
end

class HelmDirectoryDeploymentManager < HelmDeploymentManager
@helm_directory_config : ConfigV2::HelmDirectoryConfig

def initialize(helm_directory_config)
super(helm_directory_config.name)
@helm_directory_config = helm_directory_config
end

def install()
chart_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @helm_directory_config.helm_directory)
install_from_folder(chart_path, get_deployment_namespace(), @helm_directory_config.helm_values)
end


def get_deployment_config() : ConfigV2::HelmDeploymentConfig
@helm_directory_config
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "../config_versions/config_versions.cr"
require "./deployment_manager_common.cr"


module CNFInstall
class ManifestDeploymentManager < DeploymentManager
@manifest_config : ConfigV2::ManifestDirectoryConfig
@manifest_directory_path : String

def initialize(manifest_config)
super(manifest_config.name)
@manifest_config = manifest_config
@manifest_directory_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @manifest_config.manifest_directory)
end

def install()
KubectlClient::Apply.file(@manifest_directory_path)
end

def uninstall()
result = KubectlClient::Delete.file(@manifest_directory_path, wait: true)
if result[:status].success?
stdout_success "Successfully uninstalled manifest deployment \"#{@manifest_config.name}\""
end
end

def generate_manifest()
deployment_manifest = ""
list_of_manifests = Manifest.manifest_file_list(@manifest_directory_path)
list_of_manifests.each do |manifest_path|
manifest = File.read(manifest_path)
deployment_manifest = deployment_manifest + manifest + "\n"
end
deployment_manifest
end
end
end
Loading
Loading