kuber_kit 0.2.2 → 0.2.7

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: 2164864d55b65ebdd1c62b766b16b3837ad7c3f676380a58b6f60b492b9eb0cd
4
- data.tar.gz: 4517a27f92f73b1732bc7e7c200a0a6e037523fe07c6652f06f534a10266e0f8
3
+ metadata.gz: e2735934312125fca63822a1f45333ae928f4e053d9b6e9509a99036285e171a
4
+ data.tar.gz: 3045f6fb2cbe3d77313af0c3740edc3ae2dcd838cc46c65f672d419d6590d815
5
5
  SHA512:
6
- metadata.gz: 919f25e6aac48e750283df32a25a29a56e9c0111fefd7be084d9382478a79348a8072c381ee4f2a8bd95fc1f77ea3b7345904d1d260d4a1ee6820f131f453cd6
7
- data.tar.gz: 441083ec69f68ad88e806c0e7ad95ad16a91547140f8649949187c088f778e1055c5e42c3b2813f9d4ff7557bacbdc65bb0ed3becdab36e5c7ffdc079d36eaea
6
+ metadata.gz: 613792df522946cf5b5fdf83447214549ca47976c5d5a3c2c24c32813535237674fb72e62ccca378ba437e0b3a2675047ed4db32e7a6f53dc8b2598377497ae4
7
+ data.tar.gz: e0f187c76817f7af79716816459683b731726b2ae296481229fbcee23f75c65b0d7e7d934da4c18330b5b20602c43688a1c4e02d7d9852a19bf68703df6cd819
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.2.2)
4
+ kuber_kit (0.2.7)
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,7 @@
1
+ - add config file support to kuber_kit root folder
2
+ - find a way to always deploy some service, e.g. for migrations and env_files
1
3
  - allow setting default configuration for kuberkit using env variable
4
+ - add ability to set container health checks
2
5
  - implement interactive shell.exec!
3
6
  - allow deploying only services enabled for specific configuration
4
7
  - 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
@@ -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,35 @@
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
+ delete_resource_if_exists(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
+
28
+ private
29
+ def delete_resource_if_exists(shell, resource_type, resource_name, kubeconfig_path:, namespace: )
30
+ unless kubectl_commands.resource_exists?(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
31
+ return false
32
+ end
33
+ kubectl_commands.delete_resource(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
34
+ end
35
+ 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,6 +41,23 @@ 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 resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
45
+ result = find_resources(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
46
+ result && result != ""
47
+ end
48
+
49
+ def find_resources(shell, resource_type, resource_name, jsonpath: ".items[*].metadata.name", kubeconfig_path: nil, namespace: nil)
50
+ command = %Q{get #{resource_type} --field-selector=metadata.name=#{resource_name} -o jsonpath='{#{jsonpath}}'}
51
+
52
+ kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
53
+ end
54
+
55
+ def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
56
+ command = %Q{delete #{resource_type} #{resource_name}}
57
+
58
+ kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
59
+ end
60
+
44
61
  def rolling_restart(shell, deployment_name, kubeconfig_path: nil, namespace: nil)
45
62
  patch_deployment(shell, deployment_name, {
46
63
  spec: {
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.7"
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.2
4
+ version: 0.2.7
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-30 00:00:00.000000000 Z
11
+ date: 2020-12-04 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