swarm_cluster_cli_ope 0.4.2 → 0.5.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +45 -1
- data/lib/swarm_cluster_cli_ope/cli.rb +4 -0
- data/lib/swarm_cluster_cli_ope/k8s.rb +114 -0
- data/lib/swarm_cluster_cli_ope/k8s_rsync/password +1 -0
- data/lib/swarm_cluster_cli_ope/k8s_rsync/rsyncd.conf +14 -0
- data/lib/swarm_cluster_cli_ope/k8s_rsync/rsyncd.secrets +1 -0
- data/lib/swarm_cluster_cli_ope/shell_command_execution.rb +1 -1
- data/lib/swarm_cluster_cli_ope/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f02b47b55fab368037fbf3d391666784ad5db6d4427a3265a1ca09a21b5961
|
4
|
+
data.tar.gz: f496d6f56870aa9e61a40b8ae195b3925c4482b81f60d1023d2db2cafb3bd838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00a4f6ff88d19d303c978b34c9cc8483639a3deba3f9fd36767f87486ec314c0b0c29a554ce5cc5f7369b4a0d736ab8b2b72a37698210e78d167bc065f0252b6
|
7
|
+
data.tar.gz: 195f8d4ba4bdbc948f235aa3d0b61bf6e48f9e7f210c37ce72e7eb8fc2d8bd4722a98624626e7b1f7d10ce18ab8b2918253173a15c0ce76d3c3a278c1c5f9eac
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swarm_cluster_cli_ope (0.
|
4
|
+
swarm_cluster_cli_ope (0.5.0.pre.1)
|
5
5
|
activesupport
|
6
6
|
open4
|
7
7
|
thor (~> 1.0)
|
@@ -16,22 +16,66 @@ GEM
|
|
16
16
|
minitest (~> 5.1)
|
17
17
|
tzinfo (~> 1.1)
|
18
18
|
zeitwerk (~> 2.2, >= 2.2.2)
|
19
|
+
addressable (2.7.0)
|
20
|
+
public_suffix (>= 2.0.2, < 5.0)
|
19
21
|
concurrent-ruby (1.1.7)
|
22
|
+
domain_name (0.5.20190701)
|
23
|
+
unf (>= 0.0.5, < 1.0.0)
|
24
|
+
ffi (1.13.1)
|
25
|
+
ffi-compiler (1.0.1)
|
26
|
+
ffi (>= 1.0.0)
|
27
|
+
rake
|
28
|
+
http (4.4.1)
|
29
|
+
addressable (~> 2.3)
|
30
|
+
http-cookie (~> 1.0)
|
31
|
+
http-form_data (~> 2.2)
|
32
|
+
http-parser (~> 1.2.0)
|
33
|
+
http-accept (1.7.0)
|
34
|
+
http-cookie (1.0.3)
|
35
|
+
domain_name (~> 0.5)
|
36
|
+
http-form_data (2.3.0)
|
37
|
+
http-parser (1.2.1)
|
38
|
+
ffi-compiler (>= 1.0, < 2.0)
|
20
39
|
i18n (1.8.5)
|
21
40
|
concurrent-ruby (~> 1.0)
|
41
|
+
jsonpath (1.0.5)
|
42
|
+
multi_json
|
43
|
+
to_regexp (~> 0.2.1)
|
44
|
+
kubeclient (4.9.1)
|
45
|
+
http (>= 3.0, < 5.0)
|
46
|
+
jsonpath (~> 1.0)
|
47
|
+
recursive-open-struct (~> 1.1, >= 1.1.1)
|
48
|
+
rest-client (~> 2.0)
|
49
|
+
mime-types (3.3.1)
|
50
|
+
mime-types-data (~> 3.2015)
|
51
|
+
mime-types-data (3.2020.1104)
|
22
52
|
minitest (5.14.2)
|
53
|
+
multi_json (1.15.0)
|
54
|
+
netrc (0.11.0)
|
23
55
|
open4 (1.3.4)
|
56
|
+
public_suffix (4.0.6)
|
24
57
|
rake (12.3.3)
|
58
|
+
recursive-open-struct (1.1.3)
|
59
|
+
rest-client (2.1.0)
|
60
|
+
http-accept (>= 1.7.0, < 2.0)
|
61
|
+
http-cookie (>= 1.0.2, < 2.0)
|
62
|
+
mime-types (>= 1.16, < 4.0)
|
63
|
+
netrc (~> 0.8)
|
25
64
|
thor (1.0.1)
|
26
65
|
thread_safe (0.3.6)
|
66
|
+
to_regexp (0.2.1)
|
27
67
|
tzinfo (1.2.7)
|
28
68
|
thread_safe (~> 0.1)
|
69
|
+
unf (0.1.4)
|
70
|
+
unf_ext
|
71
|
+
unf_ext (0.0.7.7)
|
29
72
|
zeitwerk (2.4.0)
|
30
73
|
|
31
74
|
PLATFORMS
|
32
75
|
ruby
|
33
76
|
|
34
77
|
DEPENDENCIES
|
78
|
+
kubeclient
|
35
79
|
rake (~> 12.0)
|
36
80
|
swarm_cluster_cli_ope!
|
37
81
|
|
@@ -14,6 +14,10 @@ module SwarmClusterCliOpe
|
|
14
14
|
class_option :environment, required: false, type: :string, aliases: [:e],
|
15
15
|
desc: "Esegue tutte le operazioni nell'env scelto, il file di configurazione dovrà avere il nome: #{Configuration.cfgs_project_file_name}.ENV"
|
16
16
|
|
17
|
+
|
18
|
+
desc "k8s SUBCOMMAND ...ARGS", "Gestisce un set di comandi specifici per K8s"
|
19
|
+
subcommand "k8s", K8s
|
20
|
+
|
17
21
|
desc "install", "Creazione della configurazione base della gemma"
|
18
22
|
|
19
23
|
def install
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'kubeclient'
|
2
|
+
module SwarmClusterCliOpe
|
3
|
+
class K8s < Thor
|
4
|
+
include LoggerConcern
|
5
|
+
include ConfigurationConcern
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def self.exit_on_failure?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
desc "rsync <src> <dst>", "esegue un rsync dalla cartella (viene sincronizzato il contenuto)"
|
14
|
+
|
15
|
+
|
16
|
+
def rsync(src, dst)
|
17
|
+
if yes? "Attenzione, i dati locali o remoti verranno sovrascritti/cancellati?[y,yes]"
|
18
|
+
|
19
|
+
reg_exp = /(?<pod_name>.*)\:(?<path>.*)/
|
20
|
+
if File.exist?(src)
|
21
|
+
# il src é la cartella, quindi la destizione è il pod
|
22
|
+
direction = :upload
|
23
|
+
local_path = src
|
24
|
+
podname = dst.match(reg_exp)[:pod_name]
|
25
|
+
podpath = dst.match(reg_exp)[:path]
|
26
|
+
else
|
27
|
+
direction = :download
|
28
|
+
podname = src.match(reg_exp)[:pod_name]
|
29
|
+
podpath = src.match(reg_exp)[:path]
|
30
|
+
local_path = dst
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "#{src} #{direction} #{dst}"
|
34
|
+
|
35
|
+
cfgs.env(options[:environment]) do |cfgs|
|
36
|
+
config = Kubeclient::Config.read(ENV['KUBECONFIG'] || "#{Dir.home}/.kube/config")
|
37
|
+
|
38
|
+
context = config.context # attuale contesto
|
39
|
+
|
40
|
+
puts "Stiamo utilizzando il contesto: #{context.api_endpoint}"
|
41
|
+
|
42
|
+
base_cmd = ["kubectl", "-n #{cfgs.stack_name}"]
|
43
|
+
|
44
|
+
cmd = ShellCommandExecution.new([*base_cmd, "exec #{podname}", "--", 'bash -c "apt update && apt install -yq rsync psmisc"'])
|
45
|
+
if cmd.execute.failed?
|
46
|
+
puts "Problemi nell'installazione di rsync nel pod"
|
47
|
+
else
|
48
|
+
cmd = ShellCommandExecution.new([*base_cmd, "cp", File.expand_path("../k8s_rsync/rsyncd.conf", __FILE__), "#{podname}:/tmp/."])
|
49
|
+
copy_1 = cmd.execute.failed?
|
50
|
+
cmd = ShellCommandExecution.new([*base_cmd, "cp", File.expand_path("../k8s_rsync/rsyncd.secrets", __FILE__), "#{podname}:/tmp/."])
|
51
|
+
copy_2 = cmd.execute.failed?
|
52
|
+
cmd = ShellCommandExecution.new([*base_cmd, "exec #{podname}", "--", 'bash -c "chmod 600 /tmp/rsyncd.secrets && chown root /tmp/*"'])
|
53
|
+
chmod = cmd.execute.failed?
|
54
|
+
if copy_1 or copy_2 or chmod
|
55
|
+
puts "problema nella copia dei file di configurazione nel pod"
|
56
|
+
else
|
57
|
+
|
58
|
+
|
59
|
+
cmd = ShellCommandExecution.new([*base_cmd, "exec -i #{podname}", "--", 'bash -c "rsync --daemon --config=/tmp/rsyncd.conf --verbose --log-file=/tmp/rsync.log"'])
|
60
|
+
if cmd.execute.failed?
|
61
|
+
puts "Rsync non startato"
|
62
|
+
else
|
63
|
+
local_port = rand(30000..40000)
|
64
|
+
|
65
|
+
p = IO.popen([*base_cmd, "port-forward #{podname} #{local_port}:873"].join(" "))
|
66
|
+
pid = p.pid
|
67
|
+
puts "PID in execuzione port forward:#{pid}"
|
68
|
+
|
69
|
+
sleep 1
|
70
|
+
|
71
|
+
# lanciamo il comando quindi per far rsync
|
72
|
+
rsync_command = [
|
73
|
+
"rsync -az --no-o --no-g",
|
74
|
+
"--delete",
|
75
|
+
"--password-file=#{ File.expand_path("../k8s_rsync/password", __FILE__)}"
|
76
|
+
]
|
77
|
+
|
78
|
+
if direction == :upload
|
79
|
+
rsync_command << local_path
|
80
|
+
rsync_command << "rsync://root@0.0.0.0:#{local_port}/archives#{podpath}"
|
81
|
+
else
|
82
|
+
rsync_command << "rsync://root@0.0.0.0:#{local_port}/archives#{podpath}"
|
83
|
+
rsync_command << local_path
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
cmd = ShellCommandExecution.new(rsync_command)
|
88
|
+
cmd.execute
|
89
|
+
|
90
|
+
sleep 1
|
91
|
+
Process.kill("INT", pid)
|
92
|
+
|
93
|
+
|
94
|
+
puts "Eseguo pulizia"
|
95
|
+
cmd = ShellCommandExecution.new([*base_cmd, "exec -i #{podname}", "--", 'bash -c "killall rsync"'])
|
96
|
+
cmd.execute
|
97
|
+
cmd = ShellCommandExecution.new([*base_cmd, "exec -i #{podname}", "--", 'bash -c "rm -fr /tmp/rsyncd*"'])
|
98
|
+
cmd.execute
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
root
|
@@ -0,0 +1 @@
|
|
1
|
+
root:root
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swarm_cluster_cli_ope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marino Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -97,6 +97,10 @@ files:
|
|
97
97
|
- lib/swarm_cluster_cli_ope/commands/task.rb
|
98
98
|
- lib/swarm_cluster_cli_ope/configuration.rb
|
99
99
|
- lib/swarm_cluster_cli_ope/configuration_concern.rb
|
100
|
+
- lib/swarm_cluster_cli_ope/k8s.rb
|
101
|
+
- lib/swarm_cluster_cli_ope/k8s_rsync/password
|
102
|
+
- lib/swarm_cluster_cli_ope/k8s_rsync/rsyncd.conf
|
103
|
+
- lib/swarm_cluster_cli_ope/k8s_rsync/rsyncd.secrets
|
100
104
|
- lib/swarm_cluster_cli_ope/logger_concern.rb
|
101
105
|
- lib/swarm_cluster_cli_ope/manager.rb
|
102
106
|
- lib/swarm_cluster_cli_ope/models/base.rb
|
@@ -139,9 +143,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
143
|
version: 2.3.0
|
140
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
145
|
requirements:
|
142
|
-
- - "
|
146
|
+
- - ">"
|
143
147
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
148
|
+
version: 1.3.1
|
145
149
|
requirements: []
|
146
150
|
rubygems_version: 3.0.8
|
147
151
|
signing_key:
|