@@ -4,80 +4,82 @@ require "colorize"
44require " totem"
55require " http/client"
66require " halite"
7- require " ./utils/utils.cr"
7+ require " .. /utils/utils.cr"
88require " json"
99require " 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
8385end
0 commit comments