Skip to content

Commit 6d7ee00

Browse files
committed
Updates in setup directory
- Fill setup/constants with consts with versions, urls and so on - Fix build issues - Refactor few baseline setup tasks (setup, cluster_setup, cnf_setup) - Add SAM namespace called 'setup' to group setup tasks - Remove unused cnf_conformance_setup.cr file Signed-off-by: Rafal Lal <rafal.lal@tietoevry.com>
1 parent 3b1bb62 commit 6d7ee00

12 files changed

Lines changed: 202 additions & 236 deletions

File tree

spec/workload/microservice_spec.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ require "colorize"
33
require "../../src/tasks/utils/utils.cr"
44
require "kubectl_client"
55
require "helm"
6-
require "../../src/tasks/setup/dockerd_setup.cr"
76
require "file_utils"
87
require "sam"
98

spec/workload/registry_spec.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ require "colorize"
33
require "../../src/tasks/utils/utils.cr"
44
require "kubectl_client"
55
require "helm"
6-
require "../../src/tasks/setup/dockerd_setup.cr"
76
require "file_utils"
87
require "sam"
98

src/tasks/constants.cr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ ERROR = "error"
1717
# CHART_YAML = "Chart.yaml"
1818
DEFAULT_POINTSFILENAME = "points_v1.yml"
1919
SONOBUOY_K8S_VERSION = "0.56.14"
20-
KUBESCAPE_VERSION = "3.0.30"
21-
KUBESCAPE_FRAMEWORK_VERSION = "1.0.316"
22-
KIND_VERSION = "0.27.0"
23-
KIND_DOWNLOAD_URL = "https://github.com/kubernetes-sigs/kind/releases/download/v#{KIND_VERSION}/kind-linux-amd64"
2420
SONOBUOY_OS = "linux"
2521
IGNORED_SECRET_TYPES = ["kubernetes.io/service-account-token", "kubernetes.io/dockercfg", "kubernetes.io/dockerconfigjson", "helm.sh/release.v1"]
2622
EMPTY_JSON = JSON.parse(%({}))
@@ -29,6 +25,7 @@ SPECIALIZED_INIT_SYSTEMS = ["tini", "dumb-init", "s6-svscan"]
2925
ROLLING_VERSION_CHANGE_TEST_NAMES = ["rolling_update", "rolling_downgrade", "rolling_version_change"]
3026
WORKLOAD_RESOURCE_KIND_NAMES = ["replicaset", "deployment", "statefulset", "pod", "daemonset"]
3127

28+
# (rafal-lal)T TODO: why do we need 2 namespaces, trim that to 1
3229
TESTSUITE_NAMESPACE = "cnf-testsuite"
3330
DEFAULT_CNF_NAMESPACE = "cnf-default"
3431
# (kosstennbl) Needed only for manifest deployments, where we don't have control over installation namespace

src/tasks/setup/cluster_api_setup.cr

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,82 @@ require "colorize"
44
require "totem"
55
require "http/client"
66
require "halite"
7-
require "./utils/utils.cr"
7+
require "../utils/utils.cr"
88
require "json"
99
require "yaml"
1010

11-
desc "Install Cluster API for Kind"
12-
task "cluster_api_install" do |_, args|
13-
current_dir = FileUtils.pwd
11+
namespace "setup" do
12+
desc "Install Cluster API for Kind"
13+
task "cluster_api_install" do |_, args|
14+
current_dir = FileUtils.pwd
1415

15-
HttpHelper.download("https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.2.0/clusterctl-linux-amd64", "clusterctl")
16+
download(Setup::CLUSTER_API_URL, Setup::CLUSTERCTL_BINARY)
1617

17-
Process.run(
18-
"sudo chmod +x ./clusterctl",
19-
shell: true,
20-
output: stdout = IO::Memory.new,
21-
error: stderr = IO::Memory.new
22-
)
23-
Process.run(
24-
"sudo mv ./clusterctl /usr/local/bin/clusterctl",
25-
shell: true,
26-
output: stdout = IO::Memory.new,
27-
error: stderr = IO::Memory.new
28-
)
18+
Process.run(
19+
"sudo chmod +x ./clusterctl",
20+
shell: true,
21+
output: stdout = IO::Memory.new,
22+
error: stderr = IO::Memory.new
23+
)
24+
Process.run(
25+
"sudo mv ./clusterctl /usr/local/bin/clusterctl",
26+
shell: true,
27+
output: stdout = IO::Memory.new,
28+
error: stderr = IO::Memory.new
29+
)
2930

30-
Log.info { "Completed downloading clusterctl" }
31+
Log.info { "Completed downloading clusterctl" }
3132

32-
clusterctl = Path["~/.cluster-api"].expand(home: true)
33+
clusterctl = Path["~/.cluster-api"].expand(home: true)
3334

34-
FileUtils.mkdir_p("#{clusterctl}")
35+
FileUtils.mkdir_p("#{clusterctl}")
3536

36-
File.write("#{clusterctl}/clusterctl.yaml", "CLUSTER_TOPOLOGY: \"true\"")
37+
File.write("#{clusterctl}/clusterctl.yaml", "CLUSTER_TOPOLOGY: \"true\"")
3738

38-
cluster_init_cmd = "clusterctl init --infrastructure docker"
39-
stdout = IO::Memory.new
40-
Process.run(cluster_init_cmd, shell: true, output: stdout, error: stdout)
41-
Log.for("clusterctl init").info { stdout }
39+
cluster_init_cmd = "clusterctl init --infrastructure docker"
40+
stdout = IO::Memory.new
41+
Process.run(cluster_init_cmd, shell: true, output: stdout, error: stdout)
42+
Log.for("clusterctl init").info { stdout }
4243

43-
create_cluster_file = "#{current_dir}/capi.yaml"
44+
create_cluster_file = "#{current_dir}/capi.yaml"
4445

45-
create_cluster_cmd = "clusterctl generate cluster capi-quickstart --kubernetes-version v1.24.0 --control-plane-machine-count=3 --worker-machine-count=3 --flavor development > #{create_cluster_file} "
46+
create_cluster_cmd = "clusterctl generate cluster capi-quickstart --kubernetes-version v1.24.0 --control-plane-machine-count=3 --worker-machine-count=3 --flavor development > #{create_cluster_file} "
4647

47-
Process.run(
48-
create_cluster_cmd,
49-
shell: true,
50-
output: create_cluster_stdout = IO::Memory.new,
51-
error: create_cluster_stderr = IO::Memory.new
52-
)
48+
Process.run(
49+
create_cluster_cmd,
50+
shell: true,
51+
output: create_cluster_stdout = IO::Memory.new,
52+
error: create_cluster_stderr = IO::Memory.new
53+
)
5354

54-
# TODO (rafal-lal): Connection error is expected in first couple tries, but it's not
55-
# reasonable to rescue it inside 'wait_for_install_by_apply' method, hence the while
56-
# loop here. Ideally this should be implemented in different way so we don't have to
57-
# rescue NetworkError at all. 'loop_count' var added so testsuite won't hang
58-
# indefinitely here.
59-
loop_break = false
60-
loop_count = 0
61-
while !loop_break && loop_count < 10
62-
begin
63-
KubectlClient::Wait.wait_for_install_by_apply(create_cluster_file)
64-
loop_break = true
65-
rescue KubectlClient::ShellCMD::NetworkError
66-
sleep 3.seconds
67-
loop_count += 1
55+
# TODO (rafal-lal): Connection error is expected in first couple tries, but it's not
56+
# reasonable to rescue it inside 'wait_for_install_by_apply' method, hence the while
57+
# loop here. Ideally this should be implemented in different way so we don't have to
58+
# rescue NetworkError at all. 'loop_count' var added so testsuite won't hang
59+
# indefinitely here.
60+
loop_break = false
61+
loop_count = 0
62+
while !loop_break && loop_count < 10
63+
begin
64+
KubectlClient::Wait.wait_for_install_by_apply(create_cluster_file)
65+
loop_break = true
66+
rescue KubectlClient::ShellCMD::NetworkError
67+
sleep 3.seconds
68+
loop_count += 1
69+
end
6870
end
69-
end
7071

71-
Log.for("clusterctl-create").info { create_cluster_stdout.to_s }
72-
Log.info { "cluster api setup complete" }
73-
end
72+
Log.for("clusterctl-create").info { create_cluster_stdout.to_s }
73+
Log.info { "cluster api setup complete" }
74+
end
7475

75-
desc "Uninstall Cluster API"
76-
task "cluster_api_uninstall" do |_, args|
77-
current_dir = FileUtils.pwd
78-
delete_cluster_file = "#{current_dir}/capi.yaml"
79-
begin KubectlClient::Delete.file("#{delete_cluster_file}") rescue KubectlClient::ShellCMD::NotFoundError end
76+
desc "Uninstall Cluster API"
77+
task "cluster_api_uninstall" do |_, args|
78+
current_dir = FileUtils.pwd
79+
delete_cluster_file = "#{current_dir}/capi.yaml"
80+
begin KubectlClient::Delete.file("#{delete_cluster_file}") rescue KubectlClient::ShellCMD::NotFoundError end
8081

81-
cmd = "clusterctl delete --all --include-crd --include-namespace"
82-
Process.run(cmd, shell: true, output: stdout = IO::Memory.new, error: stderr = IO::Memory.new)
82+
cmd = "clusterctl delete --all --include-crd --include-namespace"
83+
Process.run(cmd, shell: true, output: stdout = IO::Memory.new, error: stderr = IO::Memory.new)
84+
end
8385
end

src/tasks/setup/cluster_setup.cr

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
require "sam"
2-
require "file_utils"
3-
require "colorize"
42
require "cluster_tools"
5-
require "totem"
6-
require "./utils/utils.cr"
73

8-
# CHAOS_MESH_VERSION = "v0.8.0"
4+
namespace "setup" do
5+
desc "Install CNF Test Suite Cluster Tools"
6+
task "install_cluster_tools" do |_, args|
7+
logger = SLOG.for("install_cluster_tools")
8+
logger.info { "Installing cluster_tools on the cluster" }
99

10-
desc "Install CNF Test Suite Cluster Tools"
11-
task "install_cluster_tools" do |_, args|
12-
begin
13-
ClusterTools.install
14-
rescue e : ClusterTools::NamespaceDoesNotExistException
15-
Log.error { "#{e.message}" }
16-
stdout_failure "Error: Namespace cnf-testsuite does not exist.\nPlease run 'cnf-testsuite setup' to create the necessary namespace."
17-
exit(1)
10+
begin
11+
ClusterTools.install
12+
rescue ex : ClusterTools::NamespaceDoesNotExistException
13+
logger.error { "Error while installing: #{ex.message}" }
14+
stdout_failure "Error: Namespace cnf-testsuite does not exist.\n" +
15+
"Please run 'cnf-testsuite setup' to create the necessary namespace."
16+
exit(1)
17+
rescue ex : Exception
18+
logger.error { "Error while installing: #{ex.message}" }
19+
stdout_failure "Unexpected error occured. Check logs for more info."
20+
exit(1)
21+
end
22+
logger.info { "cluster_tools has been installed on the cluster" }
1823
end
19-
end
2024

21-
desc "Uninstall CNF Test Suite Cluster Tools"
22-
task "uninstall_cluster_tools" do |_, args|
23-
begin
24-
ClusterTools.uninstall
25-
rescue e : ClusterTools::NamespaceDoesNotExistException
26-
Log.error { "#{e.message}" }
27-
stdout_failure "Error: Namespace cnf-testsuite does not exist.\nPlease run 'cnf-testsuite setup' to create the necessary namespace."
28-
exit(1)
25+
desc "Uninstall CNF Test Suite Cluster Tools"
26+
task "uninstall_cluster_tools" do |_, args|
27+
logger = SLOG.for("uninstall_cluster_tools")
28+
logger.info { "Uninstalling cluster_tools from the cluster" }
29+
30+
begin
31+
ClusterTools.uninstall
32+
rescue e : ClusterTools::NamespaceDoesNotExistException
33+
logger.error { "Error while uninstalling: #{ex.message}" }
34+
stdout_failure "Error: Namespace cnf-testsuite does not exist.\n" +
35+
"Please run 'cnf-testsuite setup' to create the necessary namespace."
36+
exit(1)
37+
rescue ex : Exception
38+
logger.error { "Error while installing: #{ex.message}" }
39+
stdout_failure "Unexpected error occured. Check logs for more info."
40+
exit(1)
41+
end
42+
logger.info { "cluster_tools has been uninstalled on the cluster" }
2943
end
3044
end

src/tasks/setup/cnf_conformance_setup.cr

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/tasks/setup/cnf_setup.cr

Lines changed: 24 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,34 @@
11
require "sam"
2-
require "file_utils"
3-
require "colorize"
4-
require "totem"
5-
require "yaml"
6-
require "./utils/utils.cr"
2+
require "../utils/utils.cr"
73

8-
task "generate_config" do |_, args|
9-
interactively_create_config()
10-
end
11-
12-
task "cnf_install", ["helm_local_install", "create_namespace"] do |_, args|
13-
if CNFManager.cnf_installed?
14-
stdout_warning "A CNF is already installed. Installation of multiple CNFs is not allowed."
15-
stdout_warning "To install a new CNF, uninstall the existing one by running: cnf_uninstall"
16-
exit 0
17-
end
18-
if ClusterTools.install
19-
stdout_success "ClusterTools installed"
20-
else
21-
stdout_failure "The ClusterTools installation timed out. Please check the status of the cluster-tools pods."
22-
exit 1
23-
end
24-
stdout_success "CNF installation start."
25-
CNFInstall.install_cnf(args)
26-
stdout_success "CNF installation complete."
27-
end
28-
29-
task "cnf_uninstall" do |_, args|
30-
CNFInstall.uninstall_cnf()
31-
end
4+
namespace "setup" do
5+
task "cnf_install", ["helm_local_install", "create_namespace"] do |_, args|
6+
logger = SLOG.for("cnf_install")
7+
logger.info { "Installing CNF to cluster" }
328

33-
def interactively_create_config
34-
new_config = {
35-
config_version: CNFInstall::Config::ConfigVersion::Latest.to_s,
36-
deployments: {
37-
helm_charts: [] of Hash(String, String),
38-
helm_dirs: [] of Hash(String, String),
39-
manifests: [] of Hash(String, String)
40-
}
41-
}
42-
43-
loop do
44-
puts "Select deployment type:"
45-
puts "1. Helm Chart"
46-
puts "2. Helm Directory"
47-
puts "3. Manifest Directory"
48-
puts "4. Finish and save configuration"
49-
choice = prompt("Enter your choice (1-4): ")
9+
if CNFManager.cnf_installed?
10+
stdout_warning "A CNF is already installed. Installation of multiple CNFs is not allowed."
11+
stdout_warning "To install a new CNF, uninstall the existing one by running: cnf_uninstall"
12+
exit 0
13+
end
5014

51-
case choice
52-
when "1"
53-
helm_chart = {
54-
"name" => prompt("Enter deployment name: "),
55-
"helm_repo_name" => prompt("Enter Helm repository name: "),
56-
"helm_repo_url" => prompt("Enter Helm repository URL: "),
57-
"helm_chart_name" => prompt("Enter Helm chart name: ")
58-
}
59-
helm_chart["helm_chart_name"] = helm_chart["helm_chart_name"]
60-
new_config[:deployments][:helm_charts] << helm_chart
61-
when "2"
62-
helm_dir = {
63-
"name" => prompt("Enter deployment name: "),
64-
"helm_directory" => prompt("Enter path to directory with Chart.yaml: ")
65-
}
66-
new_config[:deployments][:helm_dirs] << helm_dir
67-
when "3"
68-
manifest = {
69-
"name" => prompt("Enter deployment name: "),
70-
"manifest_directory" => prompt("Enter path to directory with manifest files: ")
71-
}
72-
new_config[:deployments][:manifests] << manifest
73-
when "4"
74-
break
15+
if ClusterTools.install
16+
stdout_success "ClusterTools installed"
7517
else
76-
puts "Invalid choice. Please try again."
18+
stdout_failure "The ClusterTools installation timed out. Please check the status of the cluster-tools pods."
19+
exit 1
7720
end
78-
end
7921

80-
yaml_config = new_config.to_yaml
81-
puts "Generated Configuration:"
82-
puts yaml_config
83-
84-
output_file = prompt("Choose output config path (leave empty for #{CONFIG_FILE}): ")
85-
if output_file.strip.empty?
86-
output_file = CONFIG_FILE
22+
stdout_success "CNF installation start."
23+
CNFInstall.install_cnf(args)
24+
logger.info { "CNF installed successfuly" }
25+
stdout_success "CNF installation ended."
8726
end
88-
File.write(output_file, yaml_config)
89-
puts "Configuration saved to #{output_file}"
90-
end
9127

92-
def prompt(message)
93-
print message
94-
gets.try(&.strip) || ""
28+
task "cnf_uninstall" do |_, args|
29+
logger = SLOG.for("cnf_uninstall")
30+
logger.info { "Uninstalling CNF from cluster" }
31+
CNFInstall.uninstall_cnf
32+
logger.info { "CNF uninstallation ended" }
33+
end
9534
end

0 commit comments

Comments
 (0)