kuber_kit 0.4.9 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/example/services/compose_app.rb +1 -1
- data/lib/kuber_kit.rb +3 -0
- data/lib/kuber_kit/actions/kubectl_env.rb +19 -0
- data/lib/kuber_kit/actions/service_checker.rb +32 -0
- data/lib/kuber_kit/cli.rb +18 -0
- data/lib/kuber_kit/container.rb +12 -0
- data/lib/kuber_kit/kubernetes/resource_selector.rb +33 -0
- data/lib/kuber_kit/kubernetes/resources_fetcher.rb +7 -30
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +4 -4
- data/lib/kuber_kit/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da99b8b516e2fa2eb9090dc78084bc4b3d40f6d5856e4d3ecbbb993b1cbdef5d
|
4
|
+
data.tar.gz: 73c76c08809d116b0c5f317959b45e5fb513b518592f791d8a0d32a185a5d88c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5953d83da7b07ebe1ee9be3ee803c6662c2a585bbc4b01a66ba9eb3232df86f11c6f9991e3e6ffd992828d25b5b9fc554bdb71ecd396026941b78f23448acb80
|
7
|
+
data.tar.gz: a36e8746b7caddea4fe4342df5be1bd7c5304856a613e42b805b119013b9f31cc40c5de9be8587b2f13850f8bc9aa1e1e0179f88904d9ec1b0d3617285261a9b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kuber_kit (0.
|
4
|
+
kuber_kit (0.5.0)
|
5
5
|
cli-ui
|
6
6
|
contracts-lite
|
7
7
|
dry-auto_inject
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
docile (1.3.2)
|
21
21
|
dry-auto_inject (0.7.0)
|
22
22
|
dry-container (>= 0.3.4)
|
23
|
-
dry-configurable (0.12.
|
23
|
+
dry-configurable (0.12.1)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
dry-core (~> 0.5, >= 0.5.0)
|
26
26
|
dry-container (0.7.2)
|
data/lib/kuber_kit.rb
CHANGED
@@ -165,12 +165,14 @@ module KuberKit
|
|
165
165
|
autoload :TemplateReader, 'actions/template_reader'
|
166
166
|
autoload :ServiceReader, 'actions/service_reader'
|
167
167
|
autoload :ServiceDeployer, 'actions/service_deployer'
|
168
|
+
autoload :ServiceChecker, 'actions/service_checker'
|
168
169
|
autoload :ConfigurationLoader, 'actions/configuration_loader'
|
169
170
|
autoload :KubectlApplier, 'actions/kubectl_applier'
|
170
171
|
autoload :KubectlAttacher, 'actions/kubectl_attacher'
|
171
172
|
autoload :KubectlConsole, 'actions/kubectl_console'
|
172
173
|
autoload :KubectlDescribe, 'actions/kubectl_describe'
|
173
174
|
autoload :KubectlLogs, 'actions/kubectl_logs'
|
175
|
+
autoload :KubectlEnv, 'actions/kubectl_env'
|
174
176
|
end
|
175
177
|
|
176
178
|
module Extensions
|
@@ -178,6 +180,7 @@ module KuberKit
|
|
178
180
|
end
|
179
181
|
|
180
182
|
module Kubernetes
|
183
|
+
autoload :ResourceSelector, 'kubernetes/resource_selector'
|
181
184
|
autoload :ResourcesFetcher, 'kubernetes/resources_fetcher'
|
182
185
|
end
|
183
186
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class KuberKit::Actions::KubectlEnv
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.local_shell",
|
4
|
+
"ui"
|
5
|
+
]
|
6
|
+
|
7
|
+
Contract Hash => Any
|
8
|
+
def call(options)
|
9
|
+
configuration = KuberKit.current_configuration
|
10
|
+
kubeconfig_path = configuration.kubeconfig_path
|
11
|
+
ui.print_info("ENV", "export KUBECONFIG=#{kubeconfig_path}")
|
12
|
+
|
13
|
+
true
|
14
|
+
rescue KuberKit::Error => e
|
15
|
+
ui.print_error("Error", e.message)
|
16
|
+
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Actions::ServiceChecker
|
2
|
+
include KuberKit::Import[
|
3
|
+
"kubernetes.resources_fetcher",
|
4
|
+
"shell.local_shell",
|
5
|
+
"core.service_store",
|
6
|
+
"ui",
|
7
|
+
]
|
8
|
+
|
9
|
+
Contract Hash => Any
|
10
|
+
def call(options)
|
11
|
+
services = service_store.all_definitions.values.map(&:service_name).map(&:to_s)
|
12
|
+
|
13
|
+
enabled_services = KuberKit.current_configuration.enabled_services.map(&:to_s)
|
14
|
+
if enabled_services.any?
|
15
|
+
services = services.select{ |s| enabled_services.include?(s) }
|
16
|
+
end
|
17
|
+
|
18
|
+
deployments = resources_fetcher.call("deployments")
|
19
|
+
|
20
|
+
missing_services = services.select{ |s| !deployments.include?(s.gsub("_", "-")) }
|
21
|
+
|
22
|
+
ui.print_warning("Warning", "This command will only check services deployed using k8s")
|
23
|
+
|
24
|
+
ui.print_info("Missing", missing_services.inspect)
|
25
|
+
|
26
|
+
{}
|
27
|
+
rescue KuberKit::Error => e
|
28
|
+
ui.print_error("Error", e.message)
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -86,6 +86,15 @@ class KuberKit::CLI < Thor
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
desc "check", "Check to make sure that all services are deployed"
|
90
|
+
def check()
|
91
|
+
setup(options)
|
92
|
+
|
93
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
94
|
+
KuberKit::Container['actions.service_checker'].call(options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
89
98
|
desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
|
90
99
|
def apply(file_path)
|
91
100
|
setup(options)
|
@@ -132,6 +141,15 @@ class KuberKit::CLI < Thor
|
|
132
141
|
end
|
133
142
|
end
|
134
143
|
|
144
|
+
desc "env", "Show environment variables for given configuration"
|
145
|
+
def env()
|
146
|
+
setup(options)
|
147
|
+
|
148
|
+
if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
|
149
|
+
KuberKit::Container['actions.kubectl_env'].call(options)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
135
153
|
desc "version", "Print current version"
|
136
154
|
def version
|
137
155
|
puts KuberKit::VERSION
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -21,6 +21,10 @@ class KuberKit::Container
|
|
21
21
|
KuberKit::Actions::ServiceDeployer.new
|
22
22
|
end
|
23
23
|
|
24
|
+
register "actions.service_checker" do
|
25
|
+
KuberKit::Actions::ServiceChecker.new
|
26
|
+
end
|
27
|
+
|
24
28
|
register "actions.configuration_loader" do
|
25
29
|
KuberKit::Actions::ConfigurationLoader.new
|
26
30
|
end
|
@@ -45,6 +49,10 @@ class KuberKit::Container
|
|
45
49
|
KuberKit::Actions::KubectlLogs.new
|
46
50
|
end
|
47
51
|
|
52
|
+
register "actions.kubectl_env" do
|
53
|
+
KuberKit::Actions::KubectlEnv.new
|
54
|
+
end
|
55
|
+
|
48
56
|
register "configs" do
|
49
57
|
KuberKit::Configs.new
|
50
58
|
end
|
@@ -269,6 +277,10 @@ class KuberKit::Container
|
|
269
277
|
KuberKit::ServiceReader::Reader.new
|
270
278
|
end
|
271
279
|
|
280
|
+
register "kubernetes.resource_selector" do
|
281
|
+
KuberKit::Kubernetes::ResourceSelector.new
|
282
|
+
end
|
283
|
+
|
272
284
|
register "kubernetes.resources_fetcher" do
|
273
285
|
KuberKit::Kubernetes::ResourcesFetcher.new
|
274
286
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class KuberKit::Kubernetes::ResourceSelector
|
2
|
+
include KuberKit::Import[
|
3
|
+
"kubernetes.resources_fetcher",
|
4
|
+
"shell.local_shell",
|
5
|
+
"ui"
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract String, KeywordArgs[
|
9
|
+
include_ingresses: Optional[Bool],
|
10
|
+
include_pods: Optional[Bool]
|
11
|
+
] => Any
|
12
|
+
def call(action_name, include_ingresses: false, include_pods: false)
|
13
|
+
deployments = resources_fetcher.call("deployments")
|
14
|
+
options = deployments.map{|d| "deploy/#{d}" }
|
15
|
+
options << "ingresses" if include_ingresses
|
16
|
+
options << "pods" if include_pods
|
17
|
+
option = ui.prompt("Please select resource to #{action_name}", options)
|
18
|
+
|
19
|
+
if option == "ingresses" && include_ingresses
|
20
|
+
ingresses = resources_fetcher.call("ingresses")
|
21
|
+
options = ingresses.map{|d| "ingresses/#{d}" }
|
22
|
+
return ui.prompt("Please select ingress to #{action_name}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
if option == "pods" && include_pods
|
26
|
+
ingresses = resources_fetcher.call("pods")
|
27
|
+
options = ingresses.map{|d| "pods/#{d}" }
|
28
|
+
return ui.prompt("Please select pod to #{action_name}", options)
|
29
|
+
end
|
30
|
+
|
31
|
+
option
|
32
|
+
end
|
33
|
+
end
|
@@ -2,40 +2,17 @@ class KuberKit::Kubernetes::ResourcesFetcher
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"ui"
|
6
5
|
]
|
7
6
|
|
8
|
-
Contract String
|
9
|
-
|
10
|
-
|
11
|
-
] => Any
|
12
|
-
def call(action_name, include_ingresses: false, include_pods: false)
|
13
|
-
deployments = get_resources("deployments")
|
14
|
-
options = deployments.split(" ").map{|d| "deploy/#{d}" }
|
15
|
-
options << "ingresses" if include_ingresses
|
16
|
-
options << "pods" if include_pods
|
17
|
-
option = ui.prompt("Please select resource to #{action_name}", options)
|
18
|
-
|
19
|
-
if option == "ingresses" && include_ingresses
|
20
|
-
ingresses = get_resources("ingresses")
|
21
|
-
options = ingresses.split(" ").map{|d| "ingresses/#{d}" }
|
22
|
-
return ui.prompt("Please select ingress to #{action_name}", options)
|
23
|
-
end
|
24
|
-
|
25
|
-
if option == "pods" && include_pods
|
26
|
-
ingresses = get_resources("pods")
|
27
|
-
options = ingresses.split(" ").map{|d| "pods/#{d}" }
|
28
|
-
return ui.prompt("Please select pod to #{action_name}", options)
|
29
|
-
end
|
7
|
+
Contract String => ArrayOf[String]
|
8
|
+
def call(resource_type)
|
9
|
+
current_configuration = KuberKit.current_configuration
|
30
10
|
|
31
|
-
option
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_resources(type)
|
35
11
|
kubectl_commands.get_resources(
|
36
|
-
local_shell,
|
37
|
-
jsonpath:
|
38
|
-
|
12
|
+
local_shell, resource_type,
|
13
|
+
jsonpath: ".items[*].metadata.name",
|
14
|
+
kubeconfig_path: current_configuration.kubeconfig_path,
|
15
|
+
namespace: current_configuration.deployer_namespace
|
39
16
|
)
|
40
17
|
end
|
41
18
|
end
|
@@ -60,19 +60,19 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
60
60
|
command_parts << "-o jsonpath='{#{jsonpath}}'"
|
61
61
|
end
|
62
62
|
|
63
|
-
result = kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
63
|
+
result = kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace).to_s
|
64
64
|
|
65
65
|
# Hide warnings manually, until appropriate kubectl option will be available
|
66
|
-
result = result.split("\n").reject{|n| n.start_with?("Warning:") }.join("\n")
|
66
|
+
result = result.split("\n").reject{|n| n.start_with?("Warning:") }.join("\n")
|
67
67
|
|
68
|
-
result
|
68
|
+
Array(result.split(" ")).reject(&:empty?)
|
69
69
|
end
|
70
70
|
|
71
71
|
def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
72
72
|
result = get_resources(shell, resource_type,
|
73
73
|
field_selector: "metadata.name=#{resource_name}", kubeconfig_path: kubeconfig_path, namespace: namespace
|
74
74
|
)
|
75
|
-
result
|
75
|
+
result.any?
|
76
76
|
end
|
77
77
|
|
78
78
|
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
data/lib/kuber_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuber_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -209,7 +209,9 @@ files:
|
|
209
209
|
- lib/kuber_kit/actions/kubectl_attacher.rb
|
210
210
|
- lib/kuber_kit/actions/kubectl_console.rb
|
211
211
|
- lib/kuber_kit/actions/kubectl_describe.rb
|
212
|
+
- lib/kuber_kit/actions/kubectl_env.rb
|
212
213
|
- lib/kuber_kit/actions/kubectl_logs.rb
|
214
|
+
- lib/kuber_kit/actions/service_checker.rb
|
213
215
|
- lib/kuber_kit/actions/service_deployer.rb
|
214
216
|
- lib/kuber_kit/actions/service_reader.rb
|
215
217
|
- lib/kuber_kit/actions/template_reader.rb
|
@@ -273,6 +275,7 @@ files:
|
|
273
275
|
- lib/kuber_kit/image_compiler/image_builder.rb
|
274
276
|
- lib/kuber_kit/image_compiler/image_dependency_resolver.rb
|
275
277
|
- lib/kuber_kit/image_compiler/version_tag_builder.rb
|
278
|
+
- lib/kuber_kit/kubernetes/resource_selector.rb
|
276
279
|
- lib/kuber_kit/kubernetes/resources_fetcher.rb
|
277
280
|
- lib/kuber_kit/preprocessing/file_preprocessor.rb
|
278
281
|
- lib/kuber_kit/preprocessing/text_preprocessor.rb
|