kuber_kit 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/TODO.md +2 -0
- data/bin/kit +0 -1
- data/lib/kuber_kit.rb +1 -0
- data/lib/kuber_kit/actions/service_deployer.rb +17 -4
- data/lib/kuber_kit/container.rb +4 -0
- data/lib/kuber_kit/core/service.rb +9 -7
- data/lib/kuber_kit/core/service_definition.rb +12 -5
- data/lib/kuber_kit/core/service_factory.rb +6 -5
- data/lib/kuber_kit/image_compiler/build_server_pool.rb +10 -9
- data/lib/kuber_kit/service_deployer/deployer.rb +3 -1
- data/lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb +27 -0
- data/lib/kuber_kit/service_deployer/strategy_detector.rb +1 -1
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +7 -1
- data/lib/kuber_kit/shell/local_shell.rb +2 -2
- data/lib/kuber_kit/shell/ssh_session.rb +2 -0
- data/lib/kuber_kit/shell/ssh_shell.rb +3 -2
- data/lib/kuber_kit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a60a34aefa8bd114c7bcb0f877495619c6bc5d4060f3178d6810b767264e5d7
|
4
|
+
data.tar.gz: 8b6771ac06f2c9fb3c86c810657d3f0d0368fbb4f11d37f410b87a3e7586b0c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f342d97d51f6b6ad375e8d3a112cd13b186b9ea16ff34a517e62a62c50fb307b74aaeabbfc42de001a3c9a8960c09a0c3c9e5e3bab33f47cefeb260bee8dc992
|
7
|
+
data.tar.gz: cb67b78fd74831a2bc3b39c9ac035ff06f848c1b63dde2c5725ff2d73fc08247ef9f666f88c88ea3e4ffdfda963cbdcbc96756e591205a80bcc983eaab0742b7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,13 +17,13 @@ gem 'kuber_kit'
|
|
17
17
|
### Launch compilation
|
18
18
|
|
19
19
|
```
|
20
|
-
bin/kit compile ruby_app,ruby_app2 --path=./example
|
20
|
+
bundle exec bin/kit compile ruby_app,ruby_app2 --path=./example
|
21
21
|
```
|
22
22
|
|
23
23
|
### Launch deployment
|
24
24
|
|
25
25
|
```
|
26
|
-
bin/kit compile -s ruby_app,ruby_app2 --path=./example
|
26
|
+
bundle exec bin/kit compile -s ruby_app,ruby_app2 --path=./example
|
27
27
|
```
|
28
28
|
|
29
29
|
|
data/TODO.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
- find a way to launch job on each run, e.g. for migrations
|
1
2
|
- allow setting default configuration for kuberkit using env variable
|
3
|
+
- add ability to set container health checks
|
2
4
|
- implement interactive shell.exec!
|
3
5
|
- allow deploying only services enabled for specific configuration
|
4
6
|
- list services and require confirmation before deployment
|
data/bin/kit
CHANGED
data/lib/kuber_kit.rb
CHANGED
@@ -141,6 +141,7 @@ module KuberKit
|
|
141
141
|
module Strategies
|
142
142
|
autoload :Abstract, 'service_deployer/strategies/abstract'
|
143
143
|
autoload :Kubernetes, 'service_deployer/strategies/kubernetes'
|
144
|
+
autoload :KubernetesRunner, 'service_deployer/strategies/kubernetes_runner'
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
@@ -67,9 +67,16 @@ class KuberKit::Actions::ServiceDeployer
|
|
67
67
|
def show_tags_selection()
|
68
68
|
specific_service_option = "deploy specific service"
|
69
69
|
|
70
|
-
tags =
|
71
|
-
|
72
|
-
|
70
|
+
tags = [specific_service_option]
|
71
|
+
tags += service_store
|
72
|
+
.all_definitions
|
73
|
+
.values
|
74
|
+
.map(&:to_service_attrs)
|
75
|
+
.map(&:tags)
|
76
|
+
.flatten
|
77
|
+
.uniq
|
78
|
+
.sort
|
79
|
+
.map(&:to_s)
|
73
80
|
|
74
81
|
ui.prompt("Please select which tag to deploy", tags) do |selected_tag|
|
75
82
|
if selected_tag == specific_service_option
|
@@ -81,7 +88,13 @@ class KuberKit::Actions::ServiceDeployer
|
|
81
88
|
end
|
82
89
|
|
83
90
|
def show_service_selection()
|
84
|
-
services = service_store
|
91
|
+
services = service_store
|
92
|
+
.all_definitions
|
93
|
+
.values
|
94
|
+
.map(&:service_name)
|
95
|
+
.uniq
|
96
|
+
.sort
|
97
|
+
.map(&:to_s)
|
85
98
|
|
86
99
|
ui.prompt("Please select which service to deploy", services) do |selected_service|
|
87
100
|
return [[selected_service], []]
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -225,6 +225,10 @@ class KuberKit::Container
|
|
225
225
|
KuberKit::ServiceDeployer::Strategies::Kubernetes.new
|
226
226
|
end
|
227
227
|
|
228
|
+
register "service_deployer.strategies.kubernetes_runner" do
|
229
|
+
KuberKit::ServiceDeployer::Strategies::KubernetesRunner.new
|
230
|
+
end
|
231
|
+
|
228
232
|
register "service_reader.action_handler" do
|
229
233
|
KuberKit::ServiceReader::ActionHandler.new
|
230
234
|
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
class KuberKit::Core::Service
|
2
2
|
AttributeNotSet = Class.new(Indocker::Error)
|
3
3
|
|
4
|
-
attr_reader :name, :template_name, :tags, :images, :attributes
|
4
|
+
attr_reader :name, :template_name, :tags, :images, :attributes, :deploy_strategy
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
7
|
-
name:
|
8
|
-
template_name:
|
9
|
-
tags:
|
10
|
-
images:
|
11
|
-
attributes:
|
7
|
+
name: Symbol,
|
8
|
+
template_name: Symbol,
|
9
|
+
tags: ArrayOf[Symbol],
|
10
|
+
images: ArrayOf[Symbol],
|
11
|
+
attributes: HashOf[Symbol => Any],
|
12
|
+
deploy_strategy: Maybe[Symbol]
|
12
13
|
] => Any
|
13
|
-
def initialize(name:, template_name:, tags:, images:, attributes:)
|
14
|
+
def initialize(name:, template_name:, tags:, images:, attributes:, deploy_strategy:)
|
14
15
|
@name = name
|
15
16
|
@template_name = template_name
|
16
17
|
@tags = tags
|
17
18
|
@images = images
|
18
19
|
@attributes = attributes
|
20
|
+
@deploy_strategy = deploy_strategy
|
19
21
|
end
|
20
22
|
|
21
23
|
def uri
|
@@ -8,11 +8,12 @@ class KuberKit::Core::ServiceDefinition
|
|
8
8
|
|
9
9
|
def to_service_attrs
|
10
10
|
OpenStruct.new(
|
11
|
-
name:
|
12
|
-
template_name:
|
13
|
-
tags:
|
14
|
-
images:
|
15
|
-
attributes:
|
11
|
+
name: @service_name,
|
12
|
+
template_name: get_value(@template_name),
|
13
|
+
tags: Array(get_value(@tags)).map(&:to_sym),
|
14
|
+
images: Array(get_value(@images)).map(&:to_sym),
|
15
|
+
attributes: get_value(@attributes),
|
16
|
+
deploy_strategy: get_value(@deploy_strategy),
|
16
17
|
)
|
17
18
|
end
|
18
19
|
|
@@ -40,6 +41,12 @@ class KuberKit::Core::ServiceDefinition
|
|
40
41
|
self
|
41
42
|
end
|
42
43
|
|
44
|
+
def deploy_strategy(value = nil, &block)
|
45
|
+
@deploy_strategy = block_given? ? block : value
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
43
50
|
private
|
44
51
|
def get_value(variable)
|
45
52
|
variable.is_a?(Proc) ? variable.call : variable
|
@@ -12,11 +12,12 @@ class KuberKit::Core::ServiceFactory
|
|
12
12
|
attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
|
13
13
|
|
14
14
|
KuberKit::Core::Service.new(
|
15
|
-
name:
|
16
|
-
template_name:
|
17
|
-
tags:
|
18
|
-
images:
|
19
|
-
attributes:
|
15
|
+
name: service_attrs.name,
|
16
|
+
template_name: service_attrs.template_name,
|
17
|
+
tags: service_attrs.tags,
|
18
|
+
images: service_attrs.images,
|
19
|
+
attributes: attributes,
|
20
|
+
deploy_strategy: service_attrs.deploy_strategy,
|
20
21
|
)
|
21
22
|
end
|
22
23
|
end
|
@@ -4,12 +4,15 @@ class KuberKit::ImageCompiler::BuildServerPool
|
|
4
4
|
def initialize(local_shell:, build_servers:, ssh_shell_class:)
|
5
5
|
@local_shell = local_shell
|
6
6
|
@ssh_shell_class = ssh_shell_class
|
7
|
-
@
|
7
|
+
@build_servers = build_servers
|
8
|
+
@ssh_shells = []
|
8
9
|
end
|
9
10
|
|
10
11
|
def get_shell
|
11
|
-
if @
|
12
|
-
@
|
12
|
+
if @build_servers.any?
|
13
|
+
shell = connect_to_ssh_shell(@build_servers.sample)
|
14
|
+
@ssh_shells << shell
|
15
|
+
shell
|
13
16
|
else
|
14
17
|
@local_shell
|
15
18
|
end
|
@@ -20,11 +23,9 @@ class KuberKit::ImageCompiler::BuildServerPool
|
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
shell
|
28
|
-
end
|
26
|
+
def connect_to_ssh_shell(bs)
|
27
|
+
shell = @ssh_shell_class.new
|
28
|
+
shell.connect(host: bs.host, user: bs.user, port: bs.port)
|
29
|
+
shell
|
29
30
|
end
|
30
31
|
end
|
@@ -3,7 +3,8 @@ class KuberKit::ServiceDeployer::Deployer
|
|
3
3
|
|
4
4
|
include KuberKit::Import[
|
5
5
|
"core.service_store",
|
6
|
-
"service_deployer.strategies.kubernetes"
|
6
|
+
"service_deployer.strategies.kubernetes",
|
7
|
+
"service_deployer.strategies.kubernetes_runner"
|
7
8
|
]
|
8
9
|
|
9
10
|
def register_strategy(strategy_name, strategy)
|
@@ -29,6 +30,7 @@ class KuberKit::ServiceDeployer::Deployer
|
|
29
30
|
|
30
31
|
def add_default_strategies
|
31
32
|
register_strategy(:kubernetes, kubernetes)
|
33
|
+
register_strategy(:kubernetes_runner, kubernetes_runner)
|
32
34
|
end
|
33
35
|
|
34
36
|
def reset!
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class KuberKit::ServiceDeployer::Strategies::KubernetesRunner < KuberKit::ServiceDeployer::Strategies::Abstract
|
2
|
+
include KuberKit::Import[
|
3
|
+
"service_reader.reader",
|
4
|
+
"shell.kubectl_commands",
|
5
|
+
"configs",
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
9
|
+
def deploy(shell, service)
|
10
|
+
service_config = reader.read(shell, service)
|
11
|
+
config_path = "#{configs.service_config_dir}/#{service.name}.yml"
|
12
|
+
shell.write(config_path, service_config)
|
13
|
+
|
14
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
15
|
+
deploy_namespace = KuberKit.current_configuration.deploy_namespace
|
16
|
+
|
17
|
+
deployment_resource_name = service.attribute(:deployment_resource_name, default: service.uri)
|
18
|
+
deployment_resource_type = service.attribute(:deployment_resource_type, default: "job")
|
19
|
+
|
20
|
+
deployment_delete_enabled = service.attribute(:deployment_delete_enabled, default: true)
|
21
|
+
if deployment_delete_enabled
|
22
|
+
kubectl_commands.delete_resource(shell, deployment_resource_type, deployment_resource_name, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
23
|
+
end
|
24
|
+
|
25
|
+
kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
26
|
+
end
|
27
|
+
end
|
@@ -41,7 +41,13 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
41
41
|
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: interactive, namespace: namespace)
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
45
|
+
command = %Q{delete #{resource_type} #{resource_name}}
|
46
|
+
|
47
|
+
kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
48
|
+
end
|
49
|
+
|
50
|
+
def rolling_restart(shell, deployment_name, kubeconfig_path: nil, namespace: nil)
|
45
51
|
patch_deployment(shell, deployment_name, {
|
46
52
|
spec: {
|
47
53
|
template: {
|
@@ -30,8 +30,8 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
30
30
|
result
|
31
31
|
end
|
32
32
|
|
33
|
-
def sync(local_path, remote_path, exclude: nil)
|
34
|
-
rsync_commands.rsync(self, local_path, remote_path, exclude: exclude)
|
33
|
+
def sync(local_path, remote_path, exclude: nil, delete: true)
|
34
|
+
rsync_commands.rsync(self, local_path, remote_path, exclude: exclude, delete: delete)
|
35
35
|
end
|
36
36
|
|
37
37
|
def read(file_path)
|
@@ -38,11 +38,12 @@ class KuberKit::Shell::SshShell < KuberKit::Shell::LocalShell
|
|
38
38
|
raise ShellError.new(e.message)
|
39
39
|
end
|
40
40
|
|
41
|
-
def sync(local_path, remote_path, exclude: nil)
|
41
|
+
def sync(local_path, remote_path, exclude: nil, delete: true)
|
42
42
|
rsync_commands.rsync(
|
43
43
|
local_shell, local_path, remote_path,
|
44
44
|
target_host: "#{ssh_session.user}@#{ssh_session.host}",
|
45
|
-
exclude: exclude
|
45
|
+
exclude: exclude,
|
46
|
+
delete: delete
|
46
47
|
)
|
47
48
|
end
|
48
49
|
|
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.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -257,6 +257,7 @@ files:
|
|
257
257
|
- lib/kuber_kit/service_deployer/service_list_resolver.rb
|
258
258
|
- lib/kuber_kit/service_deployer/strategies/abstract.rb
|
259
259
|
- lib/kuber_kit/service_deployer/strategies/kubernetes.rb
|
260
|
+
- lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb
|
260
261
|
- lib/kuber_kit/service_deployer/strategy_detector.rb
|
261
262
|
- lib/kuber_kit/service_reader/action_handler.rb
|
262
263
|
- lib/kuber_kit/service_reader/reader.rb
|