kuber_kit 0.1.3 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/TODO.md +4 -2
  4. data/example/app_data/env_file.yml +10 -0
  5. data/example/infrastructure/templates.rb +5 -0
  6. data/example/services/env_file.rb +6 -0
  7. data/example/services/ruby_app.rb +2 -1
  8. data/lib/kuber_kit.rb +14 -4
  9. data/lib/kuber_kit/actions/configuration_loader.rb +2 -0
  10. data/lib/kuber_kit/actions/env_file_reader.rb +5 -5
  11. data/lib/kuber_kit/actions/image_compiler.rb +5 -13
  12. data/lib/kuber_kit/actions/kubectl_applier.rb +4 -2
  13. data/lib/kuber_kit/actions/service_deployer.rb +26 -3
  14. data/lib/kuber_kit/actions/service_reader.rb +5 -6
  15. data/lib/kuber_kit/actions/template_reader.rb +2 -0
  16. data/lib/kuber_kit/container.rb +24 -8
  17. data/lib/kuber_kit/core/artifacts/artifact_store.rb +8 -0
  18. data/lib/kuber_kit/core/configuration.rb +17 -11
  19. data/lib/kuber_kit/core/configuration_definition.rb +15 -4
  20. data/lib/kuber_kit/core/configuration_factory.rb +3 -2
  21. data/lib/kuber_kit/core/configuration_store.rb +2 -0
  22. data/lib/kuber_kit/core/context_helper/base_helper.rb +12 -7
  23. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +11 -8
  24. data/lib/kuber_kit/core/context_helper/service_helper.rb +9 -4
  25. data/lib/kuber_kit/core/image_store.rb +2 -0
  26. data/lib/kuber_kit/core/service.rb +21 -3
  27. data/lib/kuber_kit/core/service_definition.rb +15 -1
  28. data/lib/kuber_kit/core/service_factory.rb +6 -1
  29. data/lib/kuber_kit/core/service_store.rb +2 -0
  30. data/lib/kuber_kit/core/templates/template_store.rb +8 -0
  31. data/lib/kuber_kit/env_file_reader/action_handler.rb +12 -0
  32. data/lib/kuber_kit/env_file_reader/reader.rb +4 -4
  33. data/lib/kuber_kit/env_file_reader/{abstract_env_file_reader.rb → strategies/abstract.rb} +1 -1
  34. data/lib/kuber_kit/env_file_reader/{artifact_file_reader.rb → strategies/artifact_file.rb} +1 -1
  35. data/lib/kuber_kit/image_compiler/action_handler.rb +21 -0
  36. data/lib/kuber_kit/image_compiler/compiler.rb +2 -5
  37. data/lib/kuber_kit/preprocessing/text_preprocessor.rb +1 -1
  38. data/lib/kuber_kit/service_deployer/action_handler.rb +16 -0
  39. data/lib/kuber_kit/service_deployer/deployer.rb +28 -6
  40. data/lib/kuber_kit/service_deployer/strategies/abstract.rb +1 -1
  41. data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +11 -6
  42. data/lib/kuber_kit/service_deployer/strategy_detector.rb +6 -0
  43. data/lib/kuber_kit/service_reader/action_handler.rb +13 -0
  44. data/lib/kuber_kit/{service_deployer/service_reader.rb → service_reader/reader.rb} +1 -1
  45. data/lib/kuber_kit/shell/kubectl_commands.rb +8 -8
  46. data/lib/kuber_kit/version.rb +1 -1
  47. metadata +12 -6
  48. data/lib/kuber_kit/service_deployer/service_restarter.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c4c480432ebb2d98461e9549271f26e607e3790464fde89b30631a675e9bc85
4
- data.tar.gz: 04b4f46724bd31dd72467ffa0f073dd495dcaafecc7213ca57a6c70bbce1e4f7
3
+ metadata.gz: 37500e0f3feb9e241251e04ae72ed0cc618d5dadf3e1c660a05658a0e5fefa15
4
+ data.tar.gz: 82d7c67f5f421fed5cbb94f14ad153dcb6f6f2f068817ffd518f6c0ea7cfe3f8
5
5
  SHA512:
6
- metadata.gz: ef5601a6e9bd63a49154f6ae14ce77eebcbc0702bd89578fd413ec23226f7db0c37b60cffcd20d314bf1cfbd6fb98a8e050f9912be668aa3dce31dd6a5056cae
7
- data.tar.gz: 7b17416b8b1d98b706409b1b88c44679b61f1689bf6c38d449320789d843f8f9b74dd519e61af364639e9cf78e95e28fd6499817980e2d211a85f0bd98d0b210
6
+ metadata.gz: 63c544b4ee93bf01f7d36720effff85052643583b008d68327c10bcbceb5711bce976856da1e6c56c9f877720eb2735447574e534f9f97a966777156ee01bda3
7
+ data.tar.gz: d388233a8636e884ee033971bf8365f3b5e753dc43a22b5e03702dda764e0632003dc80448fd7a9f3378e98539e06bc25f8163dcd6c85fdd67afddba2f141c80
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.1.3)
4
+ kuber_kit (0.1.8)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- cli-ui (1.3.0)
13
+ cli-ui (1.4.0)
14
14
  coderay (1.1.3)
15
15
  concurrent-ruby (1.1.7)
16
16
  contracts-lite (0.15.0)
data/TODO.md CHANGED
@@ -1,4 +1,6 @@
1
- - rename service reader to service config reader
1
+ - limit amount of simultaneous image builds
2
+ - list services and require confirmation before deployment
2
3
  - service factory should make sure that template exists
3
4
  - add build servers support
4
- - add build vars support (use images instead of containers)
5
+ - add build vars support (use images instead of containers)
6
+ - template should be able to depend on image?
@@ -0,0 +1,10 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Secret
4
+ metadata:
5
+ name: env-secret-review
6
+ type: Opaque
7
+ stringData:
8
+ <% env_file(:test).each do |key, value| -%>
9
+ <%= key %>: "<%= value %>"
10
+ <% end -%>
@@ -1,4 +1,9 @@
1
1
  KuberKit.add_template(
2
2
  KuberKit::Core::Templates::ArtifactFile
3
3
  .new(:service, artifact_name: :kuber_kit_example_data, file_path: "service.yml")
4
+ )
5
+
6
+ KuberKit.add_template(
7
+ KuberKit::Core::Templates::ArtifactFile
8
+ .new(:env_file, artifact_name: :kuber_kit_example_data, file_path: "env_file.yml")
4
9
  )
@@ -0,0 +1,6 @@
1
+ KuberKit
2
+ .define_service(:env_file)
3
+ .template(:env_file)
4
+ .attributes(
5
+ deployment_restart_enabled: false
6
+ )
@@ -1,3 +1,4 @@
1
1
  KuberKit
2
2
  .define_service(:ruby_app)
3
- .template(:service)
3
+ .template(:service)
4
+ .images(:ruby_app)
@@ -82,6 +82,7 @@ module KuberKit
82
82
  end
83
83
 
84
84
  module ImageCompiler
85
+ autoload :ActionHandler, 'image_compiler/action_handler'
85
86
  autoload :Compiler, 'image_compiler/compiler'
86
87
  autoload :ImageBuilder, 'image_compiler/image_builder'
87
88
  autoload :ImageBuildDirCreator, 'image_compiler/image_build_dir_creator'
@@ -103,9 +104,13 @@ module KuberKit
103
104
  end
104
105
 
105
106
  module EnvFileReader
107
+ autoload :ActionHandler, 'env_file_reader/action_handler'
106
108
  autoload :Reader, 'env_file_reader/reader'
107
- autoload :AbstractEnvFileReader, 'env_file_reader/abstract_env_file_reader'
108
- autoload :ArtifactFileReader, 'env_file_reader/artifact_file_reader'
109
+
110
+ module Strategies
111
+ autoload :Abstract, 'env_file_reader/strategies/abstract'
112
+ autoload :ArtifactFile, 'env_file_reader/strategies/artifact_file'
113
+ end
109
114
  end
110
115
 
111
116
  module TemplateReader
@@ -115,9 +120,9 @@ module KuberKit
115
120
  end
116
121
 
117
122
  module ServiceDeployer
123
+ autoload :ActionHandler, 'service_deployer/action_handler'
124
+ autoload :StrategyDetector, 'service_deployer/strategy_detector'
118
125
  autoload :Deployer, 'service_deployer/deployer'
119
- autoload :ServiceRestarter, 'service_deployer/service_restarter'
120
- autoload :ServiceReader, 'service_deployer/service_reader'
121
126
  autoload :ServiceListResolver, 'service_deployer/service_list_resolver'
122
127
 
123
128
  module Strategies
@@ -126,6 +131,11 @@ module KuberKit
126
131
  end
127
132
  end
128
133
 
134
+ module ServiceReader
135
+ autoload :ActionHandler, 'service_reader/action_handler'
136
+ autoload :Reader, 'service_reader/reader'
137
+ end
138
+
129
139
  module Actions
130
140
  autoload :ImageCompiler, 'actions/image_compiler'
131
141
  autoload :EnvFileReader, 'actions/env_file_reader'
@@ -50,6 +50,8 @@ class KuberKit::Actions::ConfigurationLoader
50
50
  files = service_store.load_definitions(services_path)
51
51
  task.update_title("Loaded #{files.count} service definitions")
52
52
  end
53
+ rescue KuberKit::Error => e
54
+ ui.print_error("Error", e.message)
53
55
  end
54
56
 
55
57
  def load_configurations(configurations_path, configuration_name)
@@ -2,16 +2,16 @@ require 'json'
2
2
 
3
3
  class KuberKit::Actions::EnvFileReader
4
4
  include KuberKit::Import[
5
- "core.env_file_store",
6
- "env_file_reader.reader",
7
5
  "shell.local_shell",
8
- "ui"
6
+ "ui",
7
+ env_file_reader: "env_file_reader.action_handler",
9
8
  ]
10
9
 
11
10
  Contract Symbol, Hash => Any
12
11
  def call(env_file_name, options)
13
- env_file = env_file_store.get(env_file_name)
14
- result = reader.read(local_shell, env_file)
12
+ result = env_file_reader.call(local_shell, env_file_name)
15
13
  ui.print_info(env_file_name.to_s, JSON.pretty_generate(result))
14
+ rescue KuberKit::Error => e
15
+ ui.print_error("Error", e.message)
16
16
  end
17
17
  end
@@ -1,11 +1,10 @@
1
1
  class KuberKit::Actions::ImageCompiler
2
2
  include KuberKit::Import[
3
- "image_compiler.compiler",
4
3
  "image_compiler.image_dependency_resolver",
5
4
  "shell.local_shell",
6
5
  "tools.logger",
7
- "configs",
8
- "ui"
6
+ "ui",
7
+ image_compiler: "image_compiler.action_handler",
9
8
  ]
10
9
 
11
10
  Contract ArrayOf[Symbol], Hash => Any
@@ -22,6 +21,8 @@ class KuberKit::Actions::ImageCompiler
22
21
  end
23
22
 
24
23
  compile_simultaneously(image_names - resolved_dependencies, build_id)
24
+ rescue KuberKit::Error => e
25
+ ui.print_error("Error", e.message)
25
26
  end
26
27
 
27
28
  private
@@ -31,7 +32,7 @@ class KuberKit::Actions::ImageCompiler
31
32
 
32
33
  logger.info("Started compiling: #{image_name.to_s.green}")
33
34
  task_group.add("Compiling #{image_name.to_s.yellow}") do |task|
34
- compile_image(image_name, build_id)
35
+ image_compiler.call(local_shell, image_name, build_id)
35
36
 
36
37
  task.update_title("Compiled #{image_name.to_s.green}")
37
38
  logger.info("Finished compiling: #{image_name.to_s.green}")
@@ -41,16 +42,7 @@ class KuberKit::Actions::ImageCompiler
41
42
  task_group.wait
42
43
  end
43
44
 
44
- def compile_image(image_name, build_id)
45
- compile_dir = generate_compile_dir(build_id: build_id)
46
- compiler.compile(local_shell, image_name, compile_dir)
47
- end
48
-
49
45
  def generate_build_id
50
46
  Time.now.strftime("%H%M%S")
51
47
  end
52
-
53
- def generate_compile_dir(build_id:)
54
- File.join(configs.image_compile_dir, build_id)
55
- end
56
48
  end
@@ -7,11 +7,13 @@ class KuberKit::Actions::KubectlApplier
7
7
 
8
8
  Contract String, Hash => Any
9
9
  def call(file_path, options)
10
- kubecfg_path = KuberKit.current_configuration.kubecfg_path
10
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
11
  ui.create_task("Applying file: #{file_path}") do |task|
12
- kubectl_commands.apply_file(local_shell, file_path, kubecfg_path: kubecfg_path)
12
+ kubectl_commands.apply_file(local_shell, file_path, kubeconfig_path: kubeconfig_path)
13
13
  task.update_title("Applied file: #{file_path}")
14
14
  end
15
15
  nil
16
+ rescue KuberKit::Error => e
17
+ ui.print_error("Error", e.message)
16
18
  end
17
19
  end
@@ -1,10 +1,12 @@
1
1
  class KuberKit::Actions::ServiceDeployer
2
2
  include KuberKit::Import[
3
+ "actions.image_compiler",
3
4
  "service_deployer.service_list_resolver",
4
- "service_deployer.deployer",
5
+ "core.service_store",
5
6
  "shell.local_shell",
6
7
  "tools.logger",
7
- "ui"
8
+ "ui",
9
+ service_deployer: "service_deployer.action_handler",
8
10
  ]
9
11
 
10
12
  Contract KeywordArgs[
@@ -17,13 +19,30 @@ class KuberKit::Actions::ServiceDeployer
17
19
  tags: tags || []
18
20
  )
19
21
 
22
+ unless service_names.any?
23
+ ui.print_warning "WARNING", "No service found with given options, nothing will be deployed."
24
+ end
25
+
26
+ services = service_names.map do |service_name|
27
+ service_store.get_service(service_name.to_sym)
28
+ end
29
+
30
+ images_names = services.map(&:images).flatten.uniq
31
+
32
+ compile_images(images_names)
33
+ deploy_services(service_names)
34
+ rescue KuberKit::Error => e
35
+ ui.print_error("Error", e.message)
36
+ end
37
+
38
+ def deploy_services(service_names)
20
39
  task_group = ui.create_task_group
21
40
 
22
41
  service_names.each do |service_name|
23
42
 
24
43
  logger.info("Started deploying: #{service_name.to_s.green}")
25
44
  task_group.add("Deploying #{service_name.to_s.yellow}") do |task|
26
- deployer.deploy(local_shell, service_name.to_sym)
45
+ service_deployer.call(local_shell, service_name.to_sym)
27
46
 
28
47
  task.update_title("Deployed #{service_name.to_s.green}")
29
48
  logger.info("Finished deploying: #{service_name.to_s.green}")
@@ -32,4 +51,8 @@ class KuberKit::Actions::ServiceDeployer
32
51
 
33
52
  task_group.wait
34
53
  end
54
+
55
+ def compile_images(images_names)
56
+ image_compiler.call(images_names, {}) if images_names.any?
57
+ end
35
58
  end
@@ -1,17 +1,16 @@
1
1
  class KuberKit::Actions::ServiceReader
2
2
  include KuberKit::Import[
3
- "core.service_store",
4
- "service_deployer.service_reader",
5
3
  "shell.local_shell",
6
- "ui"
4
+ "ui",
5
+ service_reader: "service_reader.action_handler",
7
6
  ]
8
7
 
9
8
  Contract Symbol, Hash => Any
10
9
  def call(service_name, options)
11
- service = service_store.get_service(service_name)
12
-
13
- result = service_reader.read(local_shell, service)
10
+ result = service_reader.call(local_shell, service_name)
14
11
 
15
12
  ui.print_info(service_name.to_s, result)
13
+ rescue KuberKit::Error => e
14
+ ui.print_error("Error", e.message)
16
15
  end
17
16
  end
@@ -13,5 +13,7 @@ class KuberKit::Actions::TemplateReader
13
13
  result = reader.read(local_shell, template)
14
14
 
15
15
  ui.print_info(template_name.to_s, result)
16
+ rescue KuberKit::Error => e
17
+ ui.print_error("Error", e.message)
16
18
  end
17
19
  end
@@ -141,6 +141,10 @@ class KuberKit::Container
141
141
  KuberKit::Preprocessing::DirPreprocessor.new
142
142
  end
143
143
 
144
+ register "image_compiler.action_handler" do
145
+ KuberKit::ImageCompiler::ActionHandler.new
146
+ end
147
+
144
148
  register "image_compiler.compiler" do
145
149
  KuberKit::ImageCompiler::Compiler.new
146
150
  end
@@ -173,12 +177,16 @@ class KuberKit::Container
173
177
  KuberKit::ArtifactsSync::NullArtifactResolver.new
174
178
  end
175
179
 
180
+ register "env_file_reader.action_handler" do
181
+ KuberKit::EnvFileReader::ActionHandler.new
182
+ end
183
+
176
184
  register "env_file_reader.reader" do
177
185
  KuberKit::EnvFileReader::Reader.new
178
186
  end
179
187
 
180
- register "env_file_reader.artifact_file_reader" do
181
- KuberKit::EnvFileReader::ArtifactFileReader.new
188
+ register "env_file_reader.strategies.artifact_file" do
189
+ KuberKit::EnvFileReader::Strategies::ArtifactFile.new
182
190
  end
183
191
 
184
192
  register "template_reader.reader" do
@@ -189,16 +197,16 @@ class KuberKit::Container
189
197
  KuberKit::TemplateReader::ArtifactFileReader.new
190
198
  end
191
199
 
192
- register "service_deployer.deployer" do
193
- KuberKit::ServiceDeployer::Deployer.new
200
+ register "service_deployer.action_handler" do
201
+ KuberKit::ServiceDeployer::ActionHandler.new
194
202
  end
195
203
 
196
- register "service_deployer.service_restarter" do
197
- KuberKit::ServiceDeployer::ServiceRestarter.new
204
+ register "service_deployer.strategy_detector" do
205
+ KuberKit::ServiceDeployer::StrategyDetector.new
198
206
  end
199
207
 
200
- register "service_deployer.service_reader" do
201
- KuberKit::ServiceDeployer::ServiceReader.new
208
+ register "service_deployer.deployer" do
209
+ KuberKit::ServiceDeployer::Deployer.new
202
210
  end
203
211
 
204
212
  register "service_deployer.service_list_resolver" do
@@ -209,6 +217,14 @@ class KuberKit::Container
209
217
  KuberKit::ServiceDeployer::Strategies::Kubernetes.new
210
218
  end
211
219
 
220
+ register "service_reader.action_handler" do
221
+ KuberKit::ServiceReader::ActionHandler.new
222
+ end
223
+
224
+ register "service_reader.reader" do
225
+ KuberKit::ServiceReader::Reader.new
226
+ end
227
+
212
228
  register "ui" do
213
229
  if KuberKit.debug_mode?
214
230
  KuberKit::UI::Simple.new
@@ -42,4 +42,12 @@ class KuberKit::Core::Artifacts::ArtifactStore
42
42
  def reset!
43
43
  @@artifacts = {}
44
44
  end
45
+
46
+ def all_definitions
47
+ @@artifacts ||= {}
48
+ end
49
+
50
+ def exists?(artifact_name)
51
+ !all_definitions[artifact_name].nil?
52
+ end
45
53
  end
@@ -1,5 +1,5 @@
1
1
  class KuberKit::Core::Configuration
2
- attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubecfg_path, :deploy_strategy
2
+ attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path, :deploy_strategy, :services_attributes
3
3
 
4
4
  Contract KeywordArgs[
5
5
  name: Symbol,
@@ -7,16 +7,22 @@ class KuberKit::Core::Configuration
7
7
  registries: Hash,
8
8
  env_files: Hash,
9
9
  templates: Hash,
10
- kubecfg_path: Maybe[String],
11
- deploy_strategy: Symbol
10
+ kubeconfig_path: Maybe[String],
11
+ deploy_strategy: Symbol,
12
+ services_attributes: HashOf[Symbol => Hash]
12
13
  ] => Any
13
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubecfg_path:, deploy_strategy:)
14
- @name = name
15
- @artifacts = artifacts
16
- @registries = registries
17
- @env_files = env_files
18
- @templates = templates
19
- @kubecfg_path = kubecfg_path
20
- @deploy_strategy = deploy_strategy
14
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, deploy_strategy:, services_attributes:)
15
+ @name = name
16
+ @artifacts = artifacts
17
+ @registries = registries
18
+ @env_files = env_files
19
+ @templates = templates
20
+ @kubeconfig_path = kubeconfig_path
21
+ @deploy_strategy = deploy_strategy
22
+ @services_attributes = services_attributes
23
+ end
24
+
25
+ def service_attributes(service_name)
26
+ services_attributes[service_name.to_sym] || {}
21
27
  end
22
28
  end
@@ -10,6 +10,8 @@ class KuberKit::Core::ConfigurationDefinition
10
10
  @registries = {}
11
11
  @env_files = {}
12
12
  @templates = {}
13
+ @enabled_services = []
14
+ @services_attributes = {}
13
15
  end
14
16
 
15
17
  def to_attrs
@@ -19,8 +21,10 @@ class KuberKit::Core::ConfigurationDefinition
19
21
  registries: @registries,
20
22
  env_files: @env_files,
21
23
  templates: @templates,
22
- kubecfg_path: @kubecfg_path,
23
- deploy_strategy: @deploy_strategy
24
+ kubeconfig_path: @kubeconfig_path,
25
+ deploy_strategy: @deploy_strategy,
26
+ enabled_services: @enabled_services,
27
+ services_attributes: @services_attributes
24
28
  )
25
29
  end
26
30
 
@@ -60,8 +64,8 @@ class KuberKit::Core::ConfigurationDefinition
60
64
  self
61
65
  end
62
66
 
63
- def kubecfg_path(path)
64
- @kubecfg_path = path
67
+ def kubeconfig_path(path)
68
+ @kubeconfig_path = path
65
69
 
66
70
  self
67
71
  end
@@ -71,4 +75,11 @@ class KuberKit::Core::ConfigurationDefinition
71
75
 
72
76
  self
73
77
  end
78
+
79
+ def enabled_services(services_hash)
80
+ @enabled_services += services_hash.keys.map(&:to_sym)
81
+ @services_attributes = @services_attributes.merge(services_hash)
82
+
83
+ self
84
+ end
74
85
  end
@@ -23,8 +23,9 @@ class KuberKit::Core::ConfigurationFactory
23
23
  registries: registries,
24
24
  env_files: env_files,
25
25
  templates: templates,
26
- kubecfg_path: configuration_attrs.kubecfg_path,
27
- deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy
26
+ kubeconfig_path: configuration_attrs.kubeconfig_path,
27
+ deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy,
28
+ services_attributes: configuration_attrs.services_attributes
28
29
  )
29
30
  end
30
31
 
@@ -25,6 +25,7 @@ class KuberKit::Core::ConfigurationStore
25
25
  @@configuration_definitions[configuration_definition.configuration_name] = configuration_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(configuration_name)
29
30
  @@configuration_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ConfigurationStore
35
36
  @@configuration_definitions[configuration_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_configuration(configuration_name)
39
41
  definition = get_definition(configuration_name)
40
42
 
@@ -1,25 +1,30 @@
1
1
  class KuberKit::Core::ContextHelper::BaseHelper
2
2
  CONTRACT = RespondTo[:get_binding]
3
3
 
4
- attr_reader :shell, :artifact_store, :image_store
4
+ attr_reader :shell, :artifact_store, :image_store, :env_file_reader
5
5
 
6
- def initialize(image_store:, artifact_store:, shell:)
7
- @image_store = image_store
8
- @artifact_store = artifact_store
9
- @shell = shell
6
+ def initialize(image_store:, artifact_store:, shell:, env_file_reader:)
7
+ @image_store = image_store
8
+ @artifact_store = artifact_store
9
+ @shell = shell
10
+ @env_file_reader = env_file_reader
10
11
  end
11
12
 
12
13
  def image_url(image_name)
13
- image = @image_store.get_image(image_name)
14
+ image = @image_store.get_image(image_name.to_sym)
14
15
 
15
16
  image.remote_registry_url
16
17
  end
17
18
 
18
19
  def artifact_path(name, file_name = nil)
19
- artifact = @artifact_store.get(name)
20
+ artifact = @artifact_store.get(name.to_sym)
20
21
  [artifact.cloned_path, file_name].compact.join("/")
21
22
  end
22
23
 
24
+ def env_file(env_file_name)
25
+ @env_file_reader.call(@shell, env_file_name)
26
+ end
27
+
23
28
  def configuration_name
24
29
  KuberKit.current_configuration.name
25
30
  end
@@ -1,23 +1,26 @@
1
1
  class KuberKit::Core::ContextHelper::ContextHelperFactory
2
2
  include KuberKit::Import[
3
3
  "core.image_store",
4
- "core.artifact_store"
4
+ "core.artifact_store",
5
+ env_file_reader: "env_file_reader.action_handler"
5
6
  ]
6
7
 
7
8
  def build_image_context(shell)
8
9
  KuberKit::Core::ContextHelper::ImageHelper.new(
9
- image_store: image_store,
10
- artifact_store: artifact_store,
11
- shell: shell
10
+ image_store: image_store,
11
+ artifact_store: artifact_store,
12
+ shell: shell,
13
+ env_file_reader: env_file_reader
12
14
  )
13
15
  end
14
16
 
15
17
  def build_service_context(shell, service)
16
18
  KuberKit::Core::ContextHelper::ServiceHelper.new(
17
- image_store: image_store,
18
- artifact_store: artifact_store,
19
- shell: shell,
20
- service: service
19
+ image_store: image_store,
20
+ artifact_store: artifact_store,
21
+ shell: shell,
22
+ env_file_reader: env_file_reader,
23
+ service: service,
21
24
  )
22
25
  end
23
26
  end
@@ -1,9 +1,10 @@
1
1
  class KuberKit::Core::ContextHelper::ServiceHelper < KuberKit::Core::ContextHelper::BaseHelper
2
- def initialize(image_store:, artifact_store:, shell:, service:)
2
+ def initialize(image_store:, artifact_store:, shell:, env_file_reader:, service:)
3
3
  super(
4
- image_store: image_store,
5
- artifact_store: artifact_store,
6
- shell: shell
4
+ image_store: image_store,
5
+ artifact_store: artifact_store,
6
+ shell: shell,
7
+ env_file_reader: env_file_reader
7
8
  )
8
9
  @service = service
9
10
  end
@@ -15,4 +16,8 @@ class KuberKit::Core::ContextHelper::ServiceHelper < KuberKit::Core::ContextHelp
15
16
  def service_uri
16
17
  @service.uri
17
18
  end
19
+
20
+ def attribute(attribute_name, default: nil)
21
+ @service.attribute(attribute_name, default: default)
22
+ end
18
23
  end
@@ -25,6 +25,7 @@ class KuberKit::Core::ImageStore
25
25
  @@image_definitions[image_definition.image_name] = image_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(image_name)
29
30
  @@image_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ImageStore
35
36
  @@image_definitions[image_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_image(image_name)
39
41
  definition = get_definition(image_name)
40
42
 
@@ -1,18 +1,36 @@
1
1
  class KuberKit::Core::Service
2
- attr_reader :name, :template_name, :tags
2
+ AttributeNotSet = Class.new(Indocker::Error)
3
+
4
+ attr_reader :name, :template_name, :tags, :images, :attributes
3
5
 
4
6
  Contract KeywordArgs[
5
7
  name: Symbol,
6
8
  template_name: Symbol,
7
9
  tags: ArrayOf[Symbol],
10
+ images: ArrayOf[Symbol],
11
+ attributes: HashOf[Symbol => Any],
8
12
  ] => Any
9
- def initialize(name:, template_name:, tags:)
13
+ def initialize(name:, template_name:, tags:, images:, attributes:)
10
14
  @name = name
11
15
  @template_name = template_name
12
16
  @tags = tags
17
+ @images = images
18
+ @attributes = attributes
13
19
  end
14
20
 
15
21
  def uri
16
- name.to_s.sub("_", "-")
22
+ name.to_s.gsub("_", "-")
23
+ end
24
+
25
+ def attribute(attribute_name, default: nil)
26
+ if !attributes.has_key?(attribute_name.to_sym) && default.nil?
27
+ raise AttributeNotSet, "attribute #{attribute_name} was not set"
28
+ end
29
+
30
+ if !attributes.has_key?(attribute_name.to_sym) && !default.nil?
31
+ return default
32
+ end
33
+
34
+ attributes[attribute_name.to_sym]
17
35
  end
18
36
  end
@@ -10,7 +10,9 @@ class KuberKit::Core::ServiceDefinition
10
10
  OpenStruct.new(
11
11
  name: @service_name,
12
12
  template_name: get_value(@template_name),
13
- tags: Array(get_value(@tags)).map(&:to_sym)
13
+ tags: Array(get_value(@tags)).map(&:to_sym),
14
+ images: Array(get_value(@images)).map(&:to_sym),
15
+ attributes: get_value(@attributes),
14
16
  )
15
17
  end
16
18
 
@@ -26,6 +28,18 @@ class KuberKit::Core::ServiceDefinition
26
28
  self
27
29
  end
28
30
 
31
+ def images(*value, &block)
32
+ @images = block_given? ? block : Array(value).flatten
33
+
34
+ self
35
+ end
36
+
37
+ def attributes(value = nil, &block)
38
+ @attributes = block_given? ? block : value
39
+
40
+ self
41
+ end
42
+
29
43
  private
30
44
  def get_value(variable)
31
45
  variable.is_a?(Proc) ? variable.call : variable
@@ -8,10 +8,15 @@ class KuberKit::Core::ServiceFactory
8
8
  raise AttributeNotSetError, "Please set template for service using #template method"
9
9
  end
10
10
 
11
+ configuration_attributes = KuberKit.current_configuration.service_attributes(service_attrs.name)
12
+ attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
13
+
11
14
  KuberKit::Core::Service.new(
12
15
  name: service_attrs.name,
13
16
  template_name: service_attrs.template_name,
14
- tags: service_attrs.tags
17
+ tags: service_attrs.tags,
18
+ images: service_attrs.images,
19
+ attributes: attributes
15
20
  )
16
21
  end
17
22
  end
@@ -25,6 +25,7 @@ class KuberKit::Core::ServiceStore
25
25
  @@service_definitions[service_definition.service_name] = service_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(service_name)
29
30
  @@service_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ServiceStore
35
36
  @@service_definitions[service_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_service(service_name)
39
41
  definition = get_definition(service_name)
40
42
 
@@ -42,4 +42,12 @@ class KuberKit::Core::Templates::TemplateStore
42
42
  def reset!
43
43
  @@templates = {}
44
44
  end
45
+
46
+ def all_definitions
47
+ @@templates ||= {}
48
+ end
49
+
50
+ def exists?(template_name)
51
+ !all_definitions[template_name].nil?
52
+ end
45
53
  end
@@ -0,0 +1,12 @@
1
+ class KuberKit::EnvFileReader::ActionHandler
2
+ include KuberKit::Import[
3
+ "env_file_reader.reader",
4
+ "core.env_file_store",
5
+ ]
6
+
7
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
8
+ def call(shell, env_file_name)
9
+ env_file = env_file_store.get(env_file_name)
10
+ reader.read(shell, env_file)
11
+ end
12
+ end
@@ -2,14 +2,14 @@ class KuberKit::EnvFileReader::Reader
2
2
  ReaderNotFoundError = Class.new(KuberKit::NotFoundError)
3
3
 
4
4
  include KuberKit::Import[
5
- "env_file_reader.artifact_file_reader",
5
+ "env_file_reader.strategies.artifact_file",
6
6
  ]
7
7
 
8
8
  def use_reader(env_file_reader, env_file_class:)
9
9
  @@readers ||= {}
10
10
 
11
- if !env_file_reader.is_a?(KuberKit::EnvFileReader::AbstractEnvFileReader)
12
- raise ArgumentError.new("should be an instance of KuberKit::EnvFileReader::AbstractEnvFileReader, got: #{env_file_reader.inspect}")
11
+ if !env_file_reader.is_a?(KuberKit::EnvFileReader::Strategies::Abstract)
12
+ raise ArgumentError.new("should be an instance of KuberKit::EnvFileReader::Strategies::Abstract, got: #{env_file_reader.inspect}")
13
13
  end
14
14
 
15
15
  @@readers[env_file_class] = env_file_reader
@@ -26,7 +26,7 @@ class KuberKit::EnvFileReader::Reader
26
26
  end
27
27
 
28
28
  def add_default_readers
29
- use_reader(artifact_file_reader, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
29
+ use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
30
30
  end
31
31
 
32
32
  def reset!
@@ -1,4 +1,4 @@
1
- class KuberKit::EnvFileReader::AbstractEnvFileReader
1
+ class KuberKit::EnvFileReader::Strategies::Abstract
2
2
  def read(shell, env_file)
3
3
  raise KuberKit::NotImplementedError, "must be implemented"
4
4
  end
@@ -1,4 +1,4 @@
1
- class KuberKit::EnvFileReader::ArtifactFileReader < KuberKit::EnvFileReader::AbstractEnvFileReader
1
+ class KuberKit::EnvFileReader::Strategies::ArtifactFile < KuberKit::EnvFileReader::Strategies::Abstract
2
2
  include KuberKit::Import[
3
3
  "core.artifact_store"
4
4
  ]
@@ -0,0 +1,21 @@
1
+ class KuberKit::ImageCompiler::ActionHandler
2
+ include KuberKit::Import[
3
+ "image_compiler.compiler",
4
+ "core.image_store",
5
+ "configs",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
9
+ def call(shell, image_name, build_id)
10
+ image = image_store.get_image(image_name)
11
+
12
+ compile_dir = generate_compile_dir(build_id: build_id)
13
+
14
+ compiler.compile(shell, image, compile_dir)
15
+ end
16
+
17
+ private
18
+ def generate_compile_dir(build_id:)
19
+ File.join(configs.image_compile_dir, build_id)
20
+ end
21
+ end
@@ -3,13 +3,10 @@ class KuberKit::ImageCompiler::Compiler
3
3
  "image_compiler.image_build_dir_creator",
4
4
  "image_compiler.image_builder",
5
5
  "core.context_helper_factory",
6
- "core.image_store"
7
6
  ]
8
7
 
9
- Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
10
- def compile(shell, image_name, builds_dir)
11
- image = image_store.get_image(image_name)
12
-
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Image, String => Any
9
+ def compile(shell, image, builds_dir)
13
10
  image_build_dir = File.join(builds_dir, image.name.to_s)
14
11
 
15
12
  context_helper = context_helper_factory.build_image_context(shell)
@@ -2,6 +2,6 @@ require 'erb'
2
2
 
3
3
  class KuberKit::Preprocessing::TextPreprocessor
4
4
  def compile(template, context_helper: nil)
5
- ERB.new(template).result(context_helper&.get_binding)
5
+ ERB.new(template, nil, '-').result(context_helper&.get_binding)
6
6
  end
7
7
  end
@@ -0,0 +1,16 @@
1
+ class KuberKit::ServiceDeployer::ActionHandler
2
+ include KuberKit::Import[
3
+ "service_deployer.deployer",
4
+ "service_deployer.strategy_detector",
5
+ "core.service_store",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
9
+ def call(shell, service_name)
10
+ service = service_store.get_service(service_name)
11
+
12
+ strategy_name = strategy_detector.call(service)
13
+
14
+ deployer.deploy(shell, service, strategy_name)
15
+ end
16
+ end
@@ -1,15 +1,37 @@
1
1
  class KuberKit::ServiceDeployer::Deployer
2
+ StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
+
2
4
  include KuberKit::Import[
3
- "service_deployer.service_restarter",
4
5
  "core.service_store",
6
+ "service_deployer.strategies.kubernetes"
5
7
  ]
6
8
 
7
- Contract KuberKit::Shell::AbstractShell, Symbol => Any
8
- def deploy(shell, service_name)
9
- service = service_store.get_service(service_name)
9
+ def register_strategy(strategy_name, strategy)
10
+ @@strategies ||= {}
11
+
12
+ if !strategy.is_a?(KuberKit::ServiceDeployer::Strategies::Abstract)
13
+ raise ArgumentError.new("should be an instance of KuberKit::ServiceDeployer::Strategies::Abstract, got: #{strategy.inspect}")
14
+ end
15
+
16
+ @@strategies[strategy_name] = strategy
17
+ end
18
+
19
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
20
+ def deploy(shell, service, strategy_name)
21
+ add_default_strategies
10
22
 
11
- strategy_name = KuberKit.current_configuration.deploy_strategy
23
+ deployer = @@strategies[strategy_name]
24
+
25
+ raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?
26
+
27
+ deployer.deploy(shell, service)
28
+ end
29
+
30
+ def add_default_strategies
31
+ register_strategy(:kubernetes, kubernetes)
32
+ end
12
33
 
13
- service_restarter.restart(shell, service, strategy_name)
34
+ def reset!
35
+ @@strategies = {}
14
36
  end
15
37
  end
@@ -1,5 +1,5 @@
1
1
  class KuberKit::ServiceDeployer::Strategies::Abstract
2
- def restart(shell, service)
2
+ def deploy(shell, service)
3
3
  raise KuberKit::NotImplementedError, "must be implemented"
4
4
  end
5
5
  end
@@ -1,18 +1,23 @@
1
1
  class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeployer::Strategies::Abstract
2
2
  include KuberKit::Import[
3
- "service_deployer.service_reader",
3
+ "service_reader.reader",
4
4
  "shell.kubectl_commands",
5
5
  "configs",
6
6
  ]
7
7
 
8
8
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
9
- def restart(shell, service)
10
- service_config = service_reader.read(shell, service)
9
+ def deploy(shell, service)
10
+ service_config = reader.read(shell, service)
11
11
  config_path = "#{configs.service_config_dir}/#{service.name}.yml"
12
12
  shell.write(config_path, service_config)
13
13
 
14
- kubecfg_path = KuberKit.current_configuration.kubecfg_path
15
- kubectl_commands.apply_file(shell, config_path, kubecfg_path: kubecfg_path)
16
- kubectl_commands.rolling_restart(shell, service.uri, kubecfg_path: kubecfg_path)
14
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
15
+ kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path)
16
+
17
+ deployment_restart_enabled = service.attribute(:deployment_restart_enabled, default: true)
18
+ deployment_restart_name = service.attribute(:deployment_restart_name, default: service.uri)
19
+ if deployment_restart_enabled
20
+ kubectl_commands.rolling_restart(shell, deployment_restart_name, kubeconfig_path: kubeconfig_path)
21
+ end
17
22
  end
18
23
  end
@@ -0,0 +1,6 @@
1
+ class KuberKit::ServiceDeployer::StrategyDetector
2
+ Contract KuberKit::Core::Service => Symbol
3
+ def call(service)
4
+ KuberKit.current_configuration.deploy_strategy
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ class KuberKit::ServiceReader::ActionHandler
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "core.service_store",
5
+ ]
6
+
7
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
8
+ def call(shell, service_name)
9
+ service = service_store.get_service(service_name)
10
+
11
+ reader.read(shell, service)
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- class KuberKit::ServiceDeployer::ServiceReader
1
+ class KuberKit::ServiceReader::Reader
2
2
  include KuberKit::Import[
3
3
  "core.template_store",
4
4
  "core.context_helper_factory",
@@ -2,10 +2,10 @@ require 'json'
2
2
  require 'shellwords'
3
3
 
4
4
  class KuberKit::Shell::KubectlCommands
5
- def apply_file(shell, file_path, kubecfg_path: nil)
5
+ def apply_file(shell, file_path, kubeconfig_path: nil)
6
6
  command_parts = []
7
- if kubecfg_path
8
- command_parts << "KUBECFG=#{kubecfg_path}"
7
+ if kubeconfig_path
8
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
9
9
  end
10
10
 
11
11
  command_parts << "kubectl apply -f #{file_path}"
@@ -13,7 +13,7 @@ class KuberKit::Shell::KubectlCommands
13
13
  shell.exec!(command_parts.join(" "))
14
14
  end
15
15
 
16
- def rolling_restart(shell, deployment_name, kubecfg_path: nil)
16
+ def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
17
17
  patch_deployment(shell, deployment_name, {
18
18
  spec: {
19
19
  template: {
@@ -24,13 +24,13 @@ class KuberKit::Shell::KubectlCommands
24
24
  }
25
25
  }
26
26
  }
27
- }, kubecfg_path: kubecfg_path)
27
+ }, kubeconfig_path: kubeconfig_path)
28
28
  end
29
29
 
30
- def patch_deployment(shell, deployment_name, specs, kubecfg_path: nil)
30
+ def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil)
31
31
  command_parts = []
32
- if kubecfg_path
33
- command_parts << "KUBECFG=#{kubecfg_path}"
32
+ if kubeconfig_path
33
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
34
34
  end
35
35
 
36
36
  specs_json = JSON.dump(specs).gsub('"', '\"')
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.8"
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.1.3
4
+ version: 0.1.8
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-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -144,6 +144,7 @@ files:
144
144
  - TODO.md
145
145
  - bin/console
146
146
  - bin/kit
147
+ - example/app_data/env_file.yml
147
148
  - example/app_data/service.yml
148
149
  - example/app_data/test.env
149
150
  - example/app_data/test.txt
@@ -163,6 +164,7 @@ files:
163
164
  - example/infrastructure/env_files.rb
164
165
  - example/infrastructure/registries.rb
165
166
  - example/infrastructure/templates.rb
167
+ - example/services/env_file.rb
166
168
  - example/services/ruby_app.rb
167
169
  - kuber_kit.gemspec
168
170
  - lib/kuber_kit.rb
@@ -212,13 +214,15 @@ files:
212
214
  - lib/kuber_kit/core/templates/abstract_template.rb
213
215
  - lib/kuber_kit/core/templates/artifact_file.rb
214
216
  - lib/kuber_kit/core/templates/template_store.rb
215
- - lib/kuber_kit/env_file_reader/abstract_env_file_reader.rb
216
- - lib/kuber_kit/env_file_reader/artifact_file_reader.rb
217
+ - lib/kuber_kit/env_file_reader/action_handler.rb
217
218
  - lib/kuber_kit/env_file_reader/reader.rb
219
+ - lib/kuber_kit/env_file_reader/strategies/abstract.rb
220
+ - lib/kuber_kit/env_file_reader/strategies/artifact_file.rb
218
221
  - lib/kuber_kit/extensions/colored_string.rb
219
222
  - lib/kuber_kit/extensions/contracts.rb
220
223
  - lib/kuber_kit/extensions/indocker_compat.rb
221
224
  - lib/kuber_kit/extensions/inspectable.rb
225
+ - lib/kuber_kit/image_compiler/action_handler.rb
222
226
  - lib/kuber_kit/image_compiler/compiler.rb
223
227
  - lib/kuber_kit/image_compiler/image_build_dir_creator.rb
224
228
  - lib/kuber_kit/image_compiler/image_builder.rb
@@ -227,12 +231,14 @@ files:
227
231
  - lib/kuber_kit/preprocessing/dir_preprocessor.rb
228
232
  - lib/kuber_kit/preprocessing/file_preprocessor.rb
229
233
  - lib/kuber_kit/preprocessing/text_preprocessor.rb
234
+ - lib/kuber_kit/service_deployer/action_handler.rb
230
235
  - lib/kuber_kit/service_deployer/deployer.rb
231
236
  - lib/kuber_kit/service_deployer/service_list_resolver.rb
232
- - lib/kuber_kit/service_deployer/service_reader.rb
233
- - lib/kuber_kit/service_deployer/service_restarter.rb
234
237
  - lib/kuber_kit/service_deployer/strategies/abstract.rb
235
238
  - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
239
+ - lib/kuber_kit/service_deployer/strategy_detector.rb
240
+ - lib/kuber_kit/service_reader/action_handler.rb
241
+ - lib/kuber_kit/service_reader/reader.rb
236
242
  - lib/kuber_kit/shell/abstract_shell.rb
237
243
  - lib/kuber_kit/shell/bash_commands.rb
238
244
  - lib/kuber_kit/shell/command_counter.rb
@@ -1,37 +0,0 @@
1
- class KuberKit::ServiceDeployer::ServiceRestarter
2
- StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
-
4
- include KuberKit::Import[
5
- "core.service_store",
6
- "service_deployer.strategies.kubernetes"
7
- ]
8
-
9
- def register_strategy(strategy_name, strategy)
10
- @@strategies ||= {}
11
-
12
- if !strategy.is_a?(KuberKit::ServiceDeployer::Strategies::Abstract)
13
- raise ArgumentError.new("should be an instance of KuberKit::ServiceDeployer::Strategies::Abstract, got: #{strategy.inspect}")
14
- end
15
-
16
- @@strategies[strategy_name] = strategy
17
- end
18
-
19
- Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
20
- def restart(shell, service, strategy_name)
21
- add_default_strategies
22
-
23
- restarter = @@strategies[strategy_name]
24
-
25
- raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if restarter.nil?
26
-
27
- restarter.restart(shell, service)
28
- end
29
-
30
- def add_default_strategies
31
- register_strategy(:kubernetes, kubernetes)
32
- end
33
-
34
- def reset!
35
- @@strategies = {}
36
- end
37
- end