sct 0.1.27 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/cluster/lib/.DS_Store +0 -0
  3. data/cluster/lib/cluster.rb +0 -0
  4. data/cluster/lib/cluster/commands_generator.rb +38 -50
  5. data/cluster/lib/cluster/module.rb +2 -2
  6. data/cluster/lib/cluster/resources/.DS_Store +0 -0
  7. data/cluster/lib/cluster/resources/corefile.yml +0 -0
  8. data/cluster/lib/cluster/runner.rb +173 -96
  9. data/sct/lib/.DS_Store +0 -0
  10. data/sct/lib/sct.rb +0 -0
  11. data/sct/lib/sct/.DS_Store +0 -0
  12. data/sct/lib/sct/cli_tools_distributor.rb +0 -0
  13. data/sct/lib/sct/command.rb +0 -0
  14. data/sct/lib/sct/commands/hostfile.rb +17 -13
  15. data/sct/lib/sct/commands/init.rb +0 -0
  16. data/sct/lib/sct/commands/mysqlproxy.rb +0 -0
  17. data/sct/lib/sct/commands_generator.rb +8 -8
  18. data/sct/lib/sct/tools.rb +0 -0
  19. data/sct/lib/sct/version.rb +1 -1
  20. data/sct_core/lib/.DS_Store +0 -0
  21. data/sct_core/lib/sct_core.rb +0 -0
  22. data/sct_core/lib/sct_core/.DS_Store +0 -0
  23. data/sct_core/lib/sct_core/command_executor.rb +0 -0
  24. data/sct_core/lib/sct_core/config.rb +0 -0
  25. data/sct_core/lib/sct_core/core_ext/string.rb +0 -0
  26. data/sct_core/lib/sct_core/helper.rb +29 -30
  27. data/sct_core/lib/sct_core/module.rb +0 -0
  28. data/sct_core/lib/sct_core/sct_pty.rb +0 -0
  29. data/sct_core/lib/sct_core/ui/implementations/shell.rb +0 -0
  30. data/sct_core/lib/sct_core/ui/interface.rb +0 -0
  31. data/sct_core/lib/sct_core/ui/ui.rb +0 -0
  32. data/sct_core/lib/sct_core/update_checker/update_checker.rb +2 -6
  33. data/shell/lib/shell.rb +1 -2
  34. data/shell/lib/shell/commands_generator.rb +2 -2
  35. data/shell/lib/shell/module.rb +2 -2
  36. data/shell/lib/shell/runner.rb +75 -26
  37. metadata +3 -10
  38. data/shell/README.md +0 -0
  39. data/shell/lib/shell/ClassLevelInheritableAttributes.rb +0 -25
  40. data/shell/lib/shell/docker/composer.rb +0 -16
  41. data/shell/lib/shell/docker/docker.rb +0 -218
  42. data/shell/lib/shell/docker/php.rb +0 -60
  43. data/shell/lib/shell/docker/yarn.rb +0 -17
  44. data/shell/lib/shell/tools.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff08000486ce837ef860abef5066f502d812fa618aee9cdc4ff1675de5e1db99
4
- data.tar.gz: 82bb9f318eb66683a659df692022039b2c9e27896190f4d40273fb27d375b095
3
+ metadata.gz: b2e41b42a8946aed6b8dbe5433b5c3ee3c81bff9d067468bbb1918a6e2c68923
4
+ data.tar.gz: 5ccbfd3297e07405b088c5ee403ee03bad743e8fa35503c3edf4d609e31ca9a5
5
5
  SHA512:
6
- metadata.gz: 4ec72ba0beb92e34c15e78a8d8ea8f25dc896ea783acf7404860bea66434c6c875ca41636e76f096024497badecadbb53917d5941eced8687e0df4076e00bb29
7
- data.tar.gz: 13360a17d8c27c6cd6707585a35fd0c13503296be34b2f8a9fe918f9470e6f40c68a5d4c3c7af319d00e7de66c12553b67710d7a3da1a65dcd3ce173dba3bfac
6
+ metadata.gz: 526a75d3b045b8f627a41fe54f7ddae8bf953c132e609371469059955769c7f13b4e87d0dbf8e0c8d3994d5cbf4bcbbb8d01ed3d4fb604f12deea3eccc80eebf
7
+ data.tar.gz: 89e5331e801bdacb9b8ce26ff4077bee6c9a86c51793cc7152680e4f684e455785e0186fb1045306316dac3eb6455580d1cf1c646db816e64b690dd26715f3da
File without changes
File without changes
@@ -9,63 +9,71 @@ module Cluster
9
9
  self.new.run
10
10
  end
11
11
 
12
- def run
12
+ def run
13
13
  program :name, 'cluster'
14
14
  program :version, Sct::VERSION
15
15
  program :description, 'CLI for \'cluster\' - Manage your local kubernetes cluster'
16
16
 
17
17
  global_option('--verbose') { $verbose = true }
18
18
 
19
- command :up do |c|
19
+ command :start do |c|
20
+ c.syntax = "sct cluster start"
21
+ c.description = "start the cluster"
20
22
 
21
- c.syntax = "sct cluster up"
22
- c.description = "Start the cluster"
23
- c.option '--clean', 'start a clean cluster. Old cluster will be purged if available.'
24
-
25
- c.action do |args, options|
26
- if options.clean
27
- Cluster::Runner.new.reset
28
- else
29
- Cluster::Runner.new.launch
30
- end
23
+ c.action do |args, options|
24
+ Cluster::Runner.new.start
31
25
  end
32
26
 
33
27
  end
34
28
 
35
- command :down do |c|
36
-
37
- c.syntax = 'sct cluster down'
29
+ command :stop do |c|
30
+ c.syntax = 'sct cluster stop'
38
31
  c.description = 'stop the cluster'
39
32
 
40
- c.action do |args, options|
41
- Cluster::Runner.new.down
33
+ c.action do |args, options|
34
+ Cluster::Runner.new.stop
42
35
  end
43
36
  end
44
37
 
45
- command :reset do |c|
38
+ command :restart do |c|
39
+ c.syntax = "sct cluster restart"
40
+ c.description = "restart the cluster"
41
+
42
+ c.action do |args, options|
43
+ Cluster::Runner.new.restart
44
+ end
45
+
46
+ end
47
+
48
+ command :delete do |c|
49
+ c.syntax = "sct cluster delete"
50
+ c.description = "delete the cluster"
51
+
52
+ c.action do |args, options|
53
+ Cluster::Runner.new.delete
54
+ end
55
+
56
+ end
46
57
 
58
+ command :reset do |c|
47
59
  c.syntax = 'sct cluster reset'
48
- c.description = 'reset your cluster and start with a clean cluster'
60
+ c.description = 'delete the cluster and start a new cluster'
49
61
 
50
- c.action do |args, options|
62
+ c.action do |args, options|
51
63
  Cluster::Runner.new.reset
52
64
  end
53
65
  end
54
66
 
55
- alias_command :'setup', :'reset'
56
-
57
67
  command :status do |c|
58
-
59
68
  c.syntax = 'sct cluster status'
60
69
  c.description = 'see the status of your cluster'
61
70
 
62
- c.action do |args, options|
71
+ c.action do |args, options|
63
72
  Cluster::Runner.new.status
64
73
  end
65
74
  end
66
75
 
67
76
  command :'update config' do |c|
68
-
69
77
  c.syntax = 'sct cluster update config'
70
78
  c.description = 'update the cluster configuration'
71
79
 
@@ -74,36 +82,16 @@ module Cluster
74
82
  end
75
83
  end
76
84
 
77
- command :'delete pods' do |c|
78
- c.syntax = 'sct cluster delete stalled pods'
79
- c.description = 'delete stalled pods from the cluster'
80
- c.option '--stalled', 'delete stalled pods'
81
- c.option '--all', 'delete all pods'
82
-
83
- c.action do |args, options|
84
-
85
- Cluster::Runner.new.delete_stalled_pods if options.stalled
86
- Cluster::Runner.new.delete_all_pods if options.all
87
-
88
- Cluster::Runner.new.delete_pods(args) if !args.empty?
89
-
90
- end
91
- end
92
-
93
- command :'apply pods' do |c|
94
- c.syntax = 'sct cluster apply pods'
95
- c.description = 'apply pods from the k8s folder'
85
+ command :'apply deployments' do |c|
86
+ c.syntax = 'sct cluster apply deployments'
87
+ c.description = 'apply deployments from the k8s folder'
96
88
 
97
89
  c.action do |args, options|
98
-
99
- Cluster::Runner.new.apply_pods
100
-
90
+ Cluster::Runner.new.apply_deployments
101
91
  end
102
92
  end
103
93
 
104
- default_command :status
105
-
106
94
  run!
107
95
  end
108
96
  end
109
- end
97
+ end
@@ -2,6 +2,6 @@ module Cluster
2
2
 
3
3
  # import the helper functionality from SCT
4
4
  Helpers = Sct::Helper
5
- UI = Sct::UI
5
+ UI = Sct::UI
6
6
 
7
- end
7
+ end
File without changes
@@ -1,118 +1,165 @@
1
1
  module Cluster
2
2
  class Runner
3
3
 
4
- def launch
5
- return UI.error("SCT has not been initialized. Run 'sct init' first.") unless SctCore::Config.exists
4
+ def start
5
+ SctCore::Helper.ensure_windows_administrator # "sct hostfile" will need it later on
6
+
7
+ existing_cluster = cluster_exists?
8
+
6
9
  start_cluster
7
- run_command "kubectl delete pod -n kube-system #{pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "registry-creds" } .compact.join(" ")}"
8
- run_command "kubectl rollout status -n kube-system deployment/registry-creds"
9
- post_start
10
- end
11
10
 
12
- def start_cluster
13
- if SctCore::Helper.operatingSystem == SctCore::Helper::MAC_OS
14
- run_command "#{SctCore::Helper.minikube} start --cpus=$(sysctl -n hw.ncpu) --memory=8G"
11
+ if existing_cluster
12
+ run_command "kubectl rollout restart -n kube-system deployment registry-creds"
13
+ run_command "kubectl rollout status -n kube-system deployment registry-creds"
15
14
  else
16
- run_command "#{SctCore::Helper.minikube} start --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=10G"
15
+ create_secrets
16
+ enable_addons
17
+ wait_for_gcr_secret
18
+ run_command "kubectl apply -f ~/development/spend-cloud/k8s/ingress.yml"
19
+ wait_for_ingress_ip
20
+ run_command "kubectl apply -f ~/development/spend-cloud/k8s/dependencies.yml"
21
+ wait_for_pods
22
+ create_keycloak_database_user
23
+ run_command "kubectl apply -f ~/development/spend-cloud/k8s/keycloak-server.yml"
24
+ wait_for_pods
25
+ run_command "kubectl apply -f ~/development/spend-cloud/k8s/"
17
26
  end
18
- run_command "#{SctCore::Helper.minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
19
- update_config
27
+
28
+ post_start
20
29
  end
21
30
 
22
- def post_start
23
- wait_for_pods
24
- run_command "sudo sct hostfile"
25
- UI.success("\n✔️ You can visit your environment at 👉 https://spend-cloud.spend.cloud.local 👌")
31
+ def stop
32
+ run_command "minikube stop"
33
+ end
34
+
35
+ def restart
36
+ SctCore::Helper.ensure_windows_administrator # "sct hostfile" will need it later on
37
+
38
+ stop
39
+ start
26
40
  end
27
41
 
28
- def down
29
- run_command "#{SctCore::Helper.minikube} stop"
42
+ def delete
43
+ run_command "minikube delete"
30
44
  end
31
45
 
32
46
  def reset
33
- run_command "#{SctCore::Helper.minikube} delete"
34
- start_cluster
35
- create_secrets
36
- enable_addons
37
- wait_for_gcr_secret
38
- run_command "kubectl apply -f ~/development/spend-cloud/k8s/ingress.yml"
39
- wait_for_ingress_ip
40
- run_command "kubectl apply -f ~/development/spend-cloud/k8s/dependencies.yml"
41
- wait_for_pods
42
- run_command "kubectl apply -f ~/development/spend-cloud/k8s/"
43
- post_start
47
+ SctCore::Helper.ensure_windows_administrator # "sct hostfile" will need it later on
48
+
49
+ delete
50
+ start
44
51
  end
45
52
 
46
- def enable_addons
47
- enable_addon "registry-creds"
48
- enable_addon "ingress"
53
+ def status
54
+ print_contexts
55
+ print_minikube_status
56
+
57
+ if get_minikube_status.find_all { |status| status[1] == 'Stopped' }.count == 0
58
+ print_pods_status("kube-system")
59
+ print_pods_status
60
+ else
61
+ UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
62
+ end
49
63
  end
50
64
 
51
- def enable_addon(addon)
52
- run_command "#{SctCore::Helper.minikube} addons enable #{addon}"
65
+ def update_config
66
+ run_command "kubectl config use-context minikube"
53
67
 
54
- deployment = deployments("kube-system").find { |deployment| deployment[:name].include? addon }
68
+ run_command "kubectl replace -n kube-system -f #{File.expand_path('resources/corefile.yml', __dir__)}"
69
+ run_command "kubectl rollout restart -n kube-system deployment coredns"
70
+ run_command "kubectl rollout status -n kube-system deployment coredns"
71
+ end
55
72
 
56
- run_command "kubectl rollout status -n kube-system deployment/#{deployment[:name]}"
73
+ def apply_deployments
74
+ run_command "kubectl apply -f ~/development/spend-cloud/k8s/"
57
75
  end
58
76
 
59
- def wait_for_pods
60
- UI.important("Waiting for pods to become ready...")
61
77
 
62
- while ! pods.all? { |pod| pod[:status] == "Running" }
63
- delete_stalled_pods
78
+ def cluster_exists?
79
+ if system "minikube status", { out: "/dev/null" }
80
+ # cluster exists and is running
81
+ return true
82
+ end
64
83
 
65
- sleep 5
84
+ if $?.exitstatus == 85
85
+ # cluster does not exist
86
+ return false
66
87
  end
67
88
 
68
- UI.success("Pods are now ready.")
89
+ # cluster exists but is stopped
90
+ return true
69
91
  end
70
92
 
71
- def delete_stalled_pods(feedback: false)
72
-
73
- return UI.success("No stalled pods found") unless !pods.to_a.empty?
74
-
75
- stalled_pods = pods.select { |pod| pod[:stalled] }
76
-
77
- if stalled_pods.empty?
78
- UI.success("There are no stalled pods.") if feedback
93
+ def start_cluster
94
+ if SctCore::Helper.operatingSystem == SctCore::Helper::MAC_OS
95
+ run_command "minikube start --driver=hyperkit --vm=true --cpus=$(sysctl -n hw.ncpu) --memory=8G"
79
96
  else
80
- run_command "kubectl delete pods #{stalled_pods.map { |pod| pod[:name] } .join(" ")}"
97
+ run_command "minikube start --driver=docker --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=3G"
81
98
  end
99
+ update_config
82
100
  end
83
101
 
84
- def delete_all_pods
85
- run_command "kubectl delete pods --all"
102
+ def post_start
103
+ wait_for_pods
104
+ copy_proactive_accounts_file
105
+ if SctCore::Helper.operatingSystem != SctCore::Helper::WINDOWS
106
+ UI.success("\nAdding SSH tunnel to port 443!")
107
+ run_command "sudo ssh -f -N -i $(minikube ssh-key) docker@$(minikube ip) -L 443:127.0.0.1:443"
108
+ end
109
+ # run_command "sudo sct hostfile"
110
+ run_command "minikube tunnel &", { out: "/dev/null", err: "/dev/null" } if SctCore::Helper::is_windows? # leave this running detached forever in the background
111
+ UI.success("\n✔️ You can visit your environment at 👉 https://spend-cloud.dev.spend.cloud 👌")
86
112
  end
87
113
 
88
- def delete_pods(args)
89
- run_command "kubectl delete pods #{args.join(" ")}"
114
+ def enable_addons
115
+ enable_addon "registry-creds"
116
+ enable_addon "ingress"
90
117
  end
91
118
 
92
- def apply_pods
93
- run_command "kubectl apply -f ~/development/spend-cloud/k8s/"
119
+ def enable_addon(addon)
120
+ run_command "minikube addons enable #{addon}"
121
+
122
+ deployment = deployments("kube-system").find { |deployment| deployment[:name].include? addon }
123
+
124
+ run_command "kubectl rollout status -n kube-system deployment #{deployment[:name]}"
94
125
  end
95
126
 
96
- def update_config
97
- if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
98
- windows_home_path = SctCore::Helper.windowsHomePath
99
- kube_file_path = windows_home_path+"/.kube/config"
127
+ def wait_for_pods
128
+ UI.important("Waiting for pods to become ready...")
129
+
130
+ previous_lines = 0
100
131
 
101
- if !File.exists?(kube_file_path)
102
- return UI.error("#{kube_file_path} doesn't exist")
132
+ while ! pods.all? { |pod| pod[:ready] }
133
+ pods_status_lines = get_pods_status.to_s.lines.map { |line| line.chomp }
134
+
135
+ current_lines = pods_status_lines.length
136
+
137
+ line_difference = current_lines - previous_lines
138
+
139
+ if line_difference < 0 # there are now less lines than before
140
+ line_difference.abs.times do
141
+ print "\033[1A\033[K" # move the cursor up a line and clear the line
142
+ end
143
+
144
+ print "\033[#{current_lines}A" # move the cursor all the way up to the start of the table
145
+ elsif previous_lines > 0
146
+ print "\033[#{previous_lines}A" # move the cursor all the way up to the start of the table
103
147
  end
104
148
 
105
- run_command "sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config"
149
+ pods_status_lines.each do |line|
150
+ print "#{line}\033[K#{$/}" # print the content of the line, clear remaining characters and add a new line
151
+ end
152
+
153
+ previous_lines = current_lines
106
154
 
107
- UI.success("#{kube_file_path} copied to ~/.kube/minikube-config")
155
+ sleep 5
108
156
  end
109
157
 
110
- run_command "kubectl config use-context minikube"
158
+ previous_lines.times do
159
+ print "\033[1A\033[K" # move the cursor up a line and clear the line
160
+ end
111
161
 
112
- run_command "kubectl replace -n kube-system -f #{File.expand_path('resources/corefile.yml', __dir__)}"
113
- old_list = pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "coredns" }.compact
114
- run_command "kubectl delete pod -n kube-system #{old_list.join(" ")}" unless old_list.to_a.empty?
115
- run_command "kubectl rollout status -n kube-system deployment/coredns"
162
+ UI.success("Pods are now ready.")
116
163
  end
117
164
 
118
165
  def deployments(namespace = "default")
@@ -150,13 +197,15 @@ module Cluster
150
197
  columns = line.split(" ")
151
198
 
152
199
  name = columns[0]
200
+ ready = columns[1].split("/").reduce { |l, r| l == r }
201
+ replicas = columns[1]
153
202
  status = columns[2]
154
- stalled = status == "ErrImagePull" || status == "ImagePullBackOff"
155
203
 
156
204
  {
157
205
  name: name,
158
- status: status,
159
- stalled: stalled
206
+ ready: ready,
207
+ replicas: replicas,
208
+ status: status
160
209
  }
161
210
  end
162
211
  end
@@ -193,18 +242,6 @@ module Cluster
193
242
  UI.success("Ingress IP is now available.")
194
243
  end
195
244
 
196
- def status
197
- print_contexts
198
- print_minikube_status
199
-
200
- if get_minikube_status.find_all { |status| status[1] == 'Stopped' }.count == 0
201
- print_pods_status("kube-system")
202
- print_pods_status
203
- else
204
- UI.important("Please check your minikube status. If all services are stopped you should start the minikube first.")
205
- end
206
- end
207
-
208
245
  def print_contexts
209
246
  output = `kubectl config get-contexts`
210
247
 
@@ -223,12 +260,11 @@ module Cluster
223
260
  end
224
261
 
225
262
  def print_minikube_status
226
-
227
263
  puts Terminal::Table.new title: "Minikube status".green, headings: ['Name', 'Status'], rows: get_minikube_status
228
264
  end
229
265
 
230
266
  def get_minikube_status
231
- output = `#{SctCore::Helper.minikube} status`
267
+ output = `minikube status`
232
268
 
233
269
  lines = output.split "\n"
234
270
 
@@ -240,25 +276,66 @@ module Cluster
240
276
  end
241
277
 
242
278
  def print_pods_status(namespace = "default")
279
+ output = get_pods_status(namespace)
243
280
 
244
- pods_list = pods(namespace)
281
+ puts output if output
282
+ end
245
283
 
246
- if pods_list.to_a.empty?
247
- return
248
- end
284
+ def get_pods_status(namespace = "default")
285
+ rows = pods(namespace).map do |pod|
286
+ status = pod[:status]
287
+ replicas = pod[:replicas]
249
288
 
250
- rows = pods_list.map do |pod|
251
289
  [
252
290
  pod[:name],
253
- pod[:status] == "Running" ? pod[:status].green : pod[:status].red
291
+ status == "Running" ? status.green : status.red,
292
+ pod[:ready] ? replicas.green : replicas.red
254
293
  ]
255
294
  end
256
295
 
257
- puts Terminal::Table.new title: "Pods (namespace: #{namespace})".green, headings: ['Name', 'Status'], rows: rows
296
+ if rows.empty?
297
+ return
298
+ end
299
+
300
+ return Terminal::Table.new title: "Pods (namespace: #{namespace})".green, headings: ['Name', 'Status', 'Replicas ready'], rows: rows
301
+ end
302
+
303
+ def copy_proactive_accounts_file
304
+ container_name = "proactive-config"
305
+ pod_id = pods().select {|pod| pod[:name].start_with?(container_name)}.first[:name]
306
+
307
+ begin
308
+ UI.important("Checking ProActive accounts file...")
309
+ run_command "kubectl exec #{pod_id} -- test -e /data/proactive_accounts.ini", [:out, :err] => File::NULL
310
+ rescue => e
311
+ UI.important("Copying ProActive accounts file to deployments...")
312
+ src_path = "#{Dir.home()}/development/spend-cloud/k8s/conf/proactive_accounts.ini"
313
+ command = "kubectl cp #{src_path} #{pod_id}:/data/proactive_accounts.ini -c #{container_name}"
314
+ run_command command
315
+ end
316
+
317
+ UI.success("ProActive accounts file is available")
318
+ end
319
+
320
+ def create_keycloak_database_user
321
+ container_name = "mysql-service"
322
+ pod_id = pods().select {|pod| pod[:name].start_with?(container_name)}.first[:name]
323
+
324
+ UI.important("Creating keycloak user")
325
+ create_user = "CREATE USER 'keycloak'@'%' IDENTIFIED BY 'keycloak';"
326
+ run_command "kubectl exec #{pod_id} -- mysql -e '#{create_user}' >> /dev/null"
327
+
328
+ UI.important("Creating keycloak database")
329
+ create_database = "CREATE DATABASE keycloak CHARACTER SET utf8 COLLATE UTF8_UNICODE_CI;"
330
+ run_command "kubectl exec #{pod_id} -- mysql -e '#{create_database}' >> /dev/null"
331
+
332
+ UI.important("Granting privileges to keycloak user")
333
+ grant_privileges = "GRANT ALL PRIVILEGES ON keycloak.* TO 'keycloak'@'%';"
334
+ run_command "kubectl exec #{pod_id} -- mysql -e '#{grant_privileges}' >> /dev/null"
258
335
  end
259
336
 
260
- def run_command command
261
- if ! system command
337
+ def run_command command, options = {}
338
+ if ! system command, options
262
339
  raise command.red
263
340
  end
264
341
  end