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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d669438926fb5a86f3ca7fff7f37226330cdcc4f581e590ff8ef9720eae9134c
4
- data.tar.gz: 5ce659015d98f83c07ad3e643b70ffadb729722712c88c32364a9f9668b4717e
3
+ metadata.gz: 1a60a34aefa8bd114c7bcb0f877495619c6bc5d4060f3178d6810b767264e5d7
4
+ data.tar.gz: 8b6771ac06f2c9fb3c86c810657d3f0d0368fbb4f11d37f410b87a3e7586b0c7
5
5
  SHA512:
6
- metadata.gz: a3966b99289899afb257091b11424ba5a0c56d9c5f4385bcb519de32a37355445554922468070cc7520fbfc727435d8b0b41dd8f5cb73f097c6ffe3baf0a9f3f
7
- data.tar.gz: 1343042958b0e71cd5091db62b9646ad43e027833b2bd8df7cf742b1f73065992071e208110bb95a0020e2a66b00d8c12a8a91dd090cbd2bb195114dde3a68cc
6
+ metadata.gz: f342d97d51f6b6ad375e8d3a112cd13b186b9ea16ff34a517e62a62c50fb307b74aaeabbfc42de001a3c9a8960c09a0c3c9e5e3bab33f47cefeb260bee8dc992
7
+ data.tar.gz: cb67b78fd74831a2bc3b39c9ac035ff06f848c1b63dde2c5725ff2d73fc08247ef9f666f88c88ea3e4ffdfda963cbdcbc96756e591205a80bcc983eaab0742b7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.2.1)
4
+ kuber_kit (0.2.6)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
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
@@ -2,7 +2,6 @@
2
2
  # -*- encoding: utf-8 -*-
3
3
 
4
4
  require 'rubygems'
5
- require 'bundler/setup'
6
5
  require "kuber_kit"
7
6
 
8
7
  KuberKit::CLI.start(ARGV)
@@ -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 = service_store.all_definitions.values.map(&:to_service_attrs).map(&:tags).flatten.uniq.map(&:to_s)
71
-
72
- tags.push(specific_service_option)
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.all_definitions.values.map(&:service_name).uniq.map(&:to_s)
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], []]
@@ -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: Symbol,
8
- template_name: Symbol,
9
- tags: ArrayOf[Symbol],
10
- images: ArrayOf[Symbol],
11
- attributes: HashOf[Symbol => Any],
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: @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),
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: service_attrs.name,
16
- template_name: service_attrs.template_name,
17
- tags: service_attrs.tags,
18
- images: service_attrs.images,
19
- attributes: 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
- @ssh_shells = connect_to_ssh_shells(build_servers)
7
+ @build_servers = build_servers
8
+ @ssh_shells = []
8
9
  end
9
10
 
10
11
  def get_shell
11
- if @ssh_shells.any?
12
- @ssh_shells.sample
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 connect_to_ssh_shells(build_servers)
24
- build_servers.map do |bs|
25
- shell = @ssh_shell_class.new
26
- shell.connect(host: bs.host, user: bs.user, port: bs.port)
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
@@ -1,6 +1,6 @@
1
1
  class KuberKit::ServiceDeployer::StrategyDetector
2
2
  Contract KuberKit::Core::Service => Symbol
3
3
  def call(service)
4
- KuberKit.current_configuration.deploy_strategy
4
+ service.deploy_strategy || KuberKit.current_configuration.deploy_strategy
5
5
  end
6
6
  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 rolling_restart(shell, deployment_name, kubeconfig_path: nil, namespace: namespace)
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)
@@ -56,5 +56,7 @@ class KuberKit::Shell::SshSession
56
56
  end
57
57
 
58
58
  stdout_data
59
+ rescue Net::SSH::Exception => e
60
+ raise SshSessionError, "Shell command failed: #{command}\r\n#{e.message}"
59
61
  end
60
62
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.6"
3
3
  end
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.1
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-27 00:00:00.000000000 Z
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