kuber_kit 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +1 -1
  4. data/kuber_kit.gemspec +1 -0
  5. data/lib/kuber_kit/actions/service_deployer.rb +33 -26
  6. data/lib/kuber_kit/actions/service_generator.rb +20 -0
  7. data/lib/kuber_kit/artifacts_sync/artifact_updater.rb +19 -9
  8. data/lib/kuber_kit/artifacts_sync/strategies/abstract.rb +9 -0
  9. data/lib/kuber_kit/artifacts_sync/strategies/git_updater.rb +46 -0
  10. data/lib/kuber_kit/artifacts_sync/strategies/null_updater.rb +12 -0
  11. data/lib/kuber_kit/cli.rb +27 -0
  12. data/lib/kuber_kit/configs.rb +3 -1
  13. data/lib/kuber_kit/container.rb +24 -4
  14. data/lib/kuber_kit/core/artifacts/abstract_artifact.rb +4 -0
  15. data/lib/kuber_kit/core/artifacts/git.rb +6 -1
  16. data/lib/kuber_kit/core/artifacts/local.rb +4 -0
  17. data/lib/kuber_kit/core/configuration.rb +10 -6
  18. data/lib/kuber_kit/core/configuration_definition.rb +30 -9
  19. data/lib/kuber_kit/core/configuration_factory.rb +3 -1
  20. data/lib/kuber_kit/core/context_helper/abstract_helper.rb +5 -0
  21. data/lib/kuber_kit/core/context_helper/base_helper.rb +1 -7
  22. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +3 -1
  23. data/lib/kuber_kit/core/context_helper/local_context_helper.rb +14 -0
  24. data/lib/kuber_kit/core/context_helper/service_helper.rb +15 -1
  25. data/lib/kuber_kit/core/dependencies/abstract_dependency_resolver.rb +7 -0
  26. data/lib/kuber_kit/core/service.rb +8 -5
  27. data/lib/kuber_kit/core/service_definition.rb +16 -4
  28. data/lib/kuber_kit/core/service_factory.rb +2 -1
  29. data/lib/kuber_kit/defaults.rb +9 -4
  30. data/lib/kuber_kit/image_compiler/image_builder.rb +1 -1
  31. data/lib/kuber_kit/service_deployer/service_dependency_resolver.rb +1 -1
  32. data/lib/kuber_kit/service_deployer/strategies/helm.rb +2 -2
  33. data/lib/kuber_kit/service_generator/action_handler.rb +16 -0
  34. data/lib/kuber_kit/service_generator/generator.rb +26 -0
  35. data/lib/kuber_kit/service_generator/strategies/abstract.rb +5 -0
  36. data/lib/kuber_kit/service_generator/strategies/helm.rb +33 -0
  37. data/lib/kuber_kit/service_generator/strategy_detector.rb +6 -0
  38. data/lib/kuber_kit/service_reader/reader.rb +2 -10
  39. data/lib/kuber_kit/shell/commands/git_commands.rb +10 -0
  40. data/lib/kuber_kit/template_reader/reader.rb +1 -0
  41. data/lib/kuber_kit/template_reader/renderer.rb +17 -0
  42. data/lib/kuber_kit/template_reader/strategies/artifact_file.rb +1 -0
  43. data/lib/kuber_kit/version.rb +1 -1
  44. data/lib/kuber_kit.rb +21 -3
  45. metadata +28 -5
  46. data/lib/kuber_kit/artifacts_sync/abstract_artifact_resolver.rb +0 -5
  47. data/lib/kuber_kit/artifacts_sync/git_artifact_resolver.rb +0 -31
  48. data/lib/kuber_kit/artifacts_sync/null_artifact_resolver.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31078802fb9b9050b29675dd4b364c667ea7dc0f554b395144166fa2b7e0ffce
4
- data.tar.gz: 585c56af43570387ee0ceb0985d0ceb2cbac7a4d5627103be1471f6757d2eabd
3
+ metadata.gz: e7a15c35161f8c5761166a3c41dbc90266cc3ae51d1cfa9072d3fa388d7989e2
4
+ data.tar.gz: d8099224340a4853898d990c3da88885db319c5b1025c660ae86427bf41dcaa2
5
5
  SHA512:
6
- metadata.gz: 50a194368b224a8b35a6b24a9a22897a9ed0c891eb6888fee5f9c3e788d4114618647b18a6cffe31772cff641b2ee37361bb02cc14838eb18ea1ecd5b1fab3dd
7
- data.tar.gz: dc9c31daed2206895a685aec0737656f387d9d08726f5897a8fb5b89bcce254683231b809ccf75b5b4e4a88ca39cb65ec41b2a688513ac559dd842510f09e823
6
+ metadata.gz: b7237d18746045b3a9017efd958191fc80339c321945bb6a4fceffa0320c15832e4b04710636b56977ab8df22bd0f5770bb970a83797e6c9a4aa22a4efea0093
7
+ data.tar.gz: 30e94daaafd019195a7ab46ffe07d619af7bcbbe06d87e288f4e3e50ca8e926a9270dfa7716b72cbfcec0d480a9fa2979422c676ea4df7a3fdd0dbc03ff2b4c0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ **1.3.3**
2
+ - Support "partials" in the templates with "render" method.
3
+ - Cleanup artifacts after deployment if cache_result: false
4
+ - Improve fetching git artifact when branch name has changed
5
+
6
+ **1.3.2**
7
+ - Added an ability to generate helm templates using `kit generate` command
8
+
1
9
  **1.3.1**
2
10
  - Fix upgrade command for helm strategy
3
11
 
data/README.md CHANGED
@@ -19,7 +19,7 @@ Please install specific kuber_kit version, depending on Ruby version.
19
19
  | Ruby Version | KuberKit Version |
20
20
  | ------------ | ------------ |
21
21
  | 2.6 | 1.0.1 |
22
- | 2.7 | 1.1.3 |
22
+ | 2.7 | 1.1.5 |
23
23
  | > 3.0 | 1.2.6 |
24
24
 
25
25
  ## Usage
data/kuber_kit.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "cli-ui", '2.1.0'
37
37
  spec.add_dependency "net-ssh"
38
38
  spec.add_dependency "tty-prompt"
39
+ spec.add_dependency 'ed25519'
39
40
 
40
41
  spec.add_development_dependency "bundler", "~> 2.2"
41
42
  spec.add_development_dependency "rake", "~> 10.0"
@@ -29,11 +29,11 @@ class KuberKit::Actions::ServiceDeployer
29
29
  services, tags = deployment_options_selector.call()
30
30
  end
31
31
 
32
- disabled_services = current_configuration.disabled_services.map(&:to_s)
33
- disabled_services += skip_services if skip_services
34
- default_services = current_configuration.default_services.map(&:to_s) - disabled_services
35
- initial_services = current_configuration.initial_services.map(&:to_s) - disabled_services
36
- initial_service_names = initial_services.map(&:to_sym)
32
+ disabled_services = current_configuration.disabled_services.map(&:to_s)
33
+ disabled_services += skip_services if skip_services
34
+ default_services = current_configuration.default_services.map(&:to_s) - disabled_services
35
+ pre_deploy_services = current_configuration.pre_deploy_services.map(&:to_s) - disabled_services
36
+ post_deploy_services = current_configuration.post_deploy_services.map(&:to_s) - disabled_services
37
37
 
38
38
  service_names = service_list_resolver.resolve(
39
39
  services: services || [],
@@ -50,17 +50,19 @@ class KuberKit::Actions::ServiceDeployer
50
50
  all_service_names = service_dependency_resolver.get_all(service_names)
51
51
  end
52
52
 
53
+ all_service_names_with_hooks = (pre_deploy_services.map(&:to_sym) + all_service_names + post_deploy_services.map(&:to_sym)).uniq
54
+
53
55
  unless all_service_names.any?
54
56
  ui.print_warning "ServiceDeployer", "No service found with given options, nothing will be deployed."
55
57
  return false
56
58
  end
57
59
 
58
- unless allow_deployment?(require_confirmation: require_confirmation, service_names: (initial_service_names + all_service_names).uniq)
60
+ unless allow_deployment?(require_confirmation: require_confirmation, service_names: all_service_names_with_hooks)
59
61
  return false
60
62
  end
61
63
 
62
64
  # Compile images for all services and dependencies
63
- images_names = get_image_names(service_names: (initial_service_names + all_service_names).uniq)
65
+ images_names = get_image_names(service_names: all_service_names_with_hooks.uniq)
64
66
  unless skip_compile
65
67
  compilation_result = compile_images(images_names)
66
68
 
@@ -72,33 +74,31 @@ class KuberKit::Actions::ServiceDeployer
72
74
  return deployment_result
73
75
  end
74
76
 
75
- # First deploy initial services.
77
+ # First, deploy pre-deploy services.
76
78
  # This feature is used to deploy some services, required for deployment of other services, e.g. env files
77
79
  # Note: Initial services are deployed without dependencies
78
- initial_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
79
- ui.print_debug("ServiceDeployer", "Scheduling to compile: #{batch_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
80
+ pre_deploy_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
81
+ deploy_simultaneously(batch_service_names, deployment_result)
82
+ end
80
83
 
81
- if deployment_result.succeeded?
84
+ # Next, deploy all initializers simultaneously.
85
+ # Note: In earlier versions, KuberKit would deploy all dependencies in the order defined by dependency tree.
86
+ # Now it would deploy all dependencies (initializers) at the same time, even if one initializer depends on another initializer.
87
+ unless skip_dependencies
88
+ initializers = service_dependency_resolver.get_all_deps(service_names)
89
+ initializers.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
82
90
  deploy_simultaneously(batch_service_names, deployment_result)
83
91
  end
84
92
  end
85
93
 
86
- if skip_dependencies
87
- service_names.each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
88
- ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{batch_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
89
-
90
- if deployment_result.succeeded?
91
- deploy_simultaneously(batch_service_names, deployment_result)
92
- end
93
- end
94
- else
95
- service_dependency_resolver.each_with_deps(service_names) do |dep_service_names|
96
- ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{dep_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
94
+ # Next, deploy all requested services.
95
+ service_names.each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
96
+ deploy_simultaneously(batch_service_names, deployment_result)
97
+ end
97
98
 
98
- if deployment_result.succeeded?
99
- deploy_simultaneously(dep_service_names, deployment_result)
100
- end
101
- end
99
+ # Last, deploy post-deploy services.
100
+ post_deploy_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
101
+ deploy_simultaneously(batch_service_names, deployment_result)
102
102
  end
103
103
 
104
104
  deployment_result
@@ -116,6 +116,13 @@ class KuberKit::Actions::ServiceDeployer
116
116
 
117
117
  private
118
118
  def deploy_simultaneously(service_names, deployment_result)
119
+ unless deployment_result.succeeded?
120
+ ui.print_debug("ServiceDeployer", "Deploymet already failed. Canceling: #{service_names.inspect}")
121
+ return
122
+ end
123
+
124
+ ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
125
+
119
126
  task_group = ui.create_task_group
120
127
 
121
128
  service_names.each do |service_name|
@@ -0,0 +1,20 @@
1
+ class KuberKit::Actions::ServiceGenerator
2
+ include KuberKit::Import[
3
+ "shell.local_shell",
4
+ "service_generator.action_handler",
5
+ "ui",
6
+ ]
7
+
8
+ Contract Symbol, String => Any
9
+ def call(service_name, path)
10
+ expanded_path = File.expand_path(path)
11
+ puts expanded_path
12
+ action_handler.call(local_shell, service_name, expanded_path)
13
+
14
+ true
15
+ rescue KuberKit::Error => e
16
+ ui.print_error("Error", e.message)
17
+
18
+ false
19
+ end
20
+ end
@@ -1,27 +1,37 @@
1
1
  class KuberKit::ArtifactsSync::ArtifactUpdater
2
- ResolverNotFoundError = Class.new(KuberKit::NotFoundError)
2
+ StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
3
 
4
4
  include KuberKit::Import[
5
5
  "ui"
6
6
  ]
7
7
 
8
- def use_resolver(artifact_resolver, artifact_class:)
9
- @@resolvers ||= {}
8
+ def use_strategy(strategy, artifact_class:)
9
+ @@strategies ||= {}
10
10
 
11
- if !artifact_resolver.is_a?(KuberKit::ArtifactsSync::AbstractArtifactResolver)
12
- raise ArgumentError.new("should be an instance of KuberKit::ArtifactsSync::AbstractArtifactResolver, got: #{artifact_resolver.inspect}")
11
+ if !strategy.is_a?(KuberKit::ArtifactsSync::Strategies::Abstract)
12
+ raise ArgumentError.new("should be an instance of KuberKit::ArtifactsSync::Strategies::Abstract, got: #{strategy.inspect}")
13
13
  end
14
14
 
15
- @@resolvers[artifact_class] = artifact_resolver
15
+ @@strategies[artifact_class] = strategy
16
16
  end
17
17
 
18
18
  def update(shell, artifact)
19
- resolver = @@resolvers[artifact.class]
19
+ strategy = @@strategies[artifact.class]
20
20
 
21
21
  ui.print_debug "ArtifactUpdater", "Updating artifact #{artifact.name.to_s.green}"
22
22
 
23
- raise ResolverNotFoundError, "Can't find resolver for artifact #{artifact}" if resolver.nil?
23
+ raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?
24
24
 
25
- resolver.resolve(shell, artifact)
25
+ strategy.update(shell, artifact)
26
+ end
27
+
28
+ def cleanup(shell, artifact)
29
+ strategy = @@strategies[artifact.class]
30
+
31
+ ui.print_debug "ArtifactUpdater", "Cleaning artifact #{artifact.name.to_s.green}"
32
+
33
+ raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?
34
+
35
+ strategy.cleanup(shell, artifact)
26
36
  end
27
37
  end
@@ -0,0 +1,9 @@
1
+ class KuberKit::ArtifactsSync::Strategies::Abstract
2
+ def update(shell, artifact)
3
+ raise KuberKit::NotImplementedError, "must be implemented"
4
+ end
5
+
6
+ def cleanup(shell, artifact)
7
+ raise KuberKit::NotImplementedError, "must be implemented"
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ class KuberKit::ArtifactsSync::Strategies::GitUpdater < KuberKit::ArtifactsSync::Strategies::Abstract
2
+
3
+ include KuberKit::Import[
4
+ "shell.git_commands",
5
+ "shell.bash_commands",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
9
+ def update(shell, artifact)
10
+ already_cloned = artifact_already_cloned?(
11
+ shell: shell,
12
+ repo_path: artifact.cloned_path,
13
+ artifact: artifact
14
+ )
15
+
16
+ if already_cloned
17
+ git_commands.force_pull_repo(shell,
18
+ path: artifact.cloned_path, branch: artifact.branch
19
+ )
20
+ else
21
+ git_commands.download_repo(shell,
22
+ remote_url: artifact.remote_url, path: artifact.cloned_path, branch: artifact.branch
23
+ )
24
+ end
25
+ end
26
+
27
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
28
+ def cleanup(shell, artifact)
29
+ bash_commands.rm_rf(shell, artifact.cloned_path)
30
+ end
31
+
32
+ private
33
+ def artifact_already_cloned?(shell:, repo_path:, artifact:)
34
+ target_remote_url = git_commands.get_remote_url(shell, repo_path)
35
+ if target_remote_url != artifact.remote_url
36
+ return false
37
+ end
38
+
39
+ target_branch = git_commands.get_branch_name(shell, repo_path)
40
+ if target_branch != artifact.branch
41
+ return false
42
+ end
43
+
44
+ return true
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ class KuberKit::ArtifactsSync::Strategies::NullUpdater < KuberKit::ArtifactsSync::Strategies::Abstract
2
+
3
+ Contract KuberKit::Shell::AbstractShell, Any => Any
4
+ def update(shell, artifact)
5
+ return true
6
+ end
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Any => Any
9
+ def cleanup(shell, artifact)
10
+ return true
11
+ end
12
+ end
data/lib/kuber_kit/cli.rb CHANGED
@@ -24,6 +24,8 @@ class KuberKit::CLI < Thor
24
24
  action_result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
25
25
  end
26
26
 
27
+ clean_artifacts(options)
28
+
27
29
  if action_result && action_result.succeeded?
28
30
  time = (Time.now.to_i - started_at)
29
31
  print_result("Image compilation finished! (#{time}s)", result: {
@@ -64,6 +66,8 @@ class KuberKit::CLI < Thor
64
66
  )
65
67
  end
66
68
 
69
+ clean_artifacts(options)
70
+
67
71
  if action_result && action_result.succeeded?
68
72
  time = (Time.now.to_i - started_at)
69
73
  print_result("Service deployment finished! (#{time}s)", result: {
@@ -111,6 +115,16 @@ class KuberKit::CLI < Thor
111
115
  end
112
116
  end
113
117
 
118
+
119
+ desc "generate SERVICE_NAME PATH_NAME", "Generates a template for a given service in a given path"
120
+ def generate(service_name, path)
121
+ setup(options)
122
+
123
+ if KuberKit::Container['actions.configuration_loader'].call(options)
124
+ KuberKit::Container['actions.service_generator'].call(service_name.to_sym, path)
125
+ end
126
+ end
127
+
114
128
  desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
115
129
  def apply(file_path)
116
130
  setup(options)
@@ -220,4 +234,17 @@ class KuberKit::CLI < Thor
220
234
  def print_result(message, data = {})
221
235
  KuberKit::Container['ui'].print_result(message, data)
222
236
  end
237
+
238
+ def clean_artifacts(options)
239
+ artifacts = KuberKit.current_configuration.artifacts.values
240
+ artifacts_to_clean = artifacts.select(&:cleanup_needed?)
241
+
242
+ return unless artifacts_to_clean.any?
243
+
244
+ artifacts_to_clean.each do |artifact|
245
+ KuberKit::Container['artifacts_sync.artifact_updater'].cleanup(
246
+ KuberKit::Container['shell.local_shell'], artifact
247
+ )
248
+ end
249
+ end
223
250
  end
@@ -5,7 +5,8 @@ class KuberKit::Configs
5
5
  :image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :image_compile_dir, :remote_image_compile_dir,
6
6
  :kuber_kit_dirname, :kuber_kit_min_version, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
7
7
  :artifact_clone_dir, :service_config_dir, :deployer_strategy, :compile_simultaneous_limit, :deploy_simultaneous_limit,
8
- :additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir, :shell_launcher_strategy, :shell_launcher_sets_configration
8
+ :additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir, :shell_launcher_strategy,
9
+ :shell_launcher_sets_configration, :generator_strategy
9
10
  ]
10
11
  DOCKER_IGNORE_LIST = [
11
12
  'Dockerfile',
@@ -60,6 +61,7 @@ class KuberKit::Configs
60
61
  set :log_file_path, File.join(absolute_kuber_kit_path, "deploy.log")
61
62
  set :env_file_compile_dir, File.join(absolute_kuber_kit_path, "env_files")
62
63
  set :shell_launcher_sets_configration, true
64
+ set :generator_strategy, :helm
63
65
  end
64
66
 
65
67
  def items
@@ -25,6 +25,10 @@ class KuberKit::Container
25
25
  KuberKit::Actions::ServiceChecker.new
26
26
  end
27
27
 
28
+ register "actions.service_generator" do
29
+ KuberKit::Actions::ServiceGenerator.new
30
+ end
31
+
28
32
  register "actions.configuration_loader" do
29
33
  KuberKit::Actions::ConfigurationLoader.new
30
34
  end
@@ -233,12 +237,12 @@ class KuberKit::Container
233
237
  KuberKit::ArtifactsSync::ArtifactUpdater.new
234
238
  end
235
239
 
236
- register "artifacts_sync.git_artifact_resolver" do
237
- KuberKit::ArtifactsSync::GitArtifactResolver.new
240
+ register "artifacts_sync.strategies.git_updater" do
241
+ KuberKit::ArtifactsSync::Strategies::GitUpdater.new
238
242
  end
239
243
 
240
- register "artifacts_sync.null_artifact_resolver" do
241
- KuberKit::ArtifactsSync::NullArtifactResolver.new
244
+ register "artifacts_sync.strategies.null_updater" do
245
+ KuberKit::ArtifactsSync::Strategies::NullUpdater.new
242
246
  end
243
247
 
244
248
  register "env_file_reader.action_handler" do
@@ -273,6 +277,10 @@ class KuberKit::Container
273
277
  KuberKit::TemplateReader::Reader.new
274
278
  end
275
279
 
280
+ register "template_reader.renderer" do
281
+ KuberKit::TemplateReader::Renderer.new
282
+ end
283
+
276
284
  register "template_reader.strategies.artifact_file" do
277
285
  KuberKit::TemplateReader::Strategies::ArtifactFile.new
278
286
  end
@@ -301,6 +309,18 @@ class KuberKit::Container
301
309
  KuberKit::ServiceDeployer::ServiceDependencyResolver.new
302
310
  end
303
311
 
312
+ register "service_generator.action_handler" do
313
+ KuberKit::ServiceGenerator::ActionHandler.new
314
+ end
315
+
316
+ register "service_generator.strategy_detector" do
317
+ KuberKit::ServiceGenerator::StrategyDetector.new
318
+ end
319
+
320
+ register "service_generator.generator" do
321
+ KuberKit::ServiceGenerator::Generator.new
322
+ end
323
+
304
324
  register "service_reader.action_handler" do
305
325
  KuberKit::ServiceReader::ActionHandler.new
306
326
  end
@@ -14,4 +14,8 @@ class KuberKit::Core::Artifacts::AbstractArtifact
14
14
  def sync_description
15
15
  raise KuberKit::NotImplementedError, "must be implemented"
16
16
  end
17
+
18
+ def cleanup_needed?
19
+ raise KuberKit::NotImplementedError, "must be implemented"
20
+ end
17
21
  end
@@ -5,12 +5,13 @@ class KuberKit::Core::Artifacts::Git < KuberKit::Core::Artifacts::AbstractArtifa
5
5
  DEFAULT_REMOTE_NAME = "origin"
6
6
  DEFAULT_BRANCH = "master"
7
7
 
8
- def setup(remote_url:, remote_name: DEFAULT_REMOTE_NAME, branch: DEFAULT_BRANCH, clone_path: nil, ssh_key: DEFAULT_SSH_KEY)
8
+ def setup(remote_url:, remote_name: DEFAULT_REMOTE_NAME, branch: DEFAULT_BRANCH, clone_path: nil, ssh_key: DEFAULT_SSH_KEY, cache_result: true)
9
9
  @remote_name = remote_name
10
10
  @remote_url = remote_url
11
11
  @branch = branch
12
12
  @clone_path = clone_path
13
13
  @ssh_key = ssh_key
14
+ @cache_result = cache_result
14
15
  self
15
16
  end
16
17
 
@@ -23,4 +24,8 @@ class KuberKit::Core::Artifacts::Git < KuberKit::Core::Artifacts::AbstractArtifa
23
24
  def sync_description
24
25
  "#{remote_url}:#{branch}"
25
26
  end
27
+
28
+ def cleanup_needed?
29
+ !@cache_result
30
+ end
26
31
  end
@@ -15,4 +15,8 @@ class KuberKit::Core::Artifacts::Local < KuberKit::Core::Artifacts::AbstractArti
15
15
  def sync_description
16
16
  "local"
17
17
  end
18
+
19
+ def cleanup_needed?
20
+ false
21
+ end
18
22
  end
@@ -1,9 +1,9 @@
1
1
  class KuberKit::Core::Configuration
2
2
  attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path, :kubectl_entrypoint,
3
3
  :services_attributes, :enabled_services, :disabled_services, :default_services,
4
- :initial_services, :build_servers, :global_build_vars,
4
+ :pre_deploy_services, :post_deploy_services, :build_servers, :global_build_vars,
5
5
  :deployer_strategy, :deployer_namespace, :deployer_require_confirmation,
6
- :shell_launcher_strategy
6
+ :shell_launcher_strategy, :generator_strategy
7
7
 
8
8
  Contract KeywordArgs[
9
9
  name: Symbol,
@@ -17,18 +17,20 @@ class KuberKit::Core::Configuration
17
17
  enabled_services: ArrayOf[Symbol],
18
18
  disabled_services: ArrayOf[Symbol],
19
19
  default_services: ArrayOf[Symbol],
20
- initial_services: ArrayOf[Symbol],
20
+ pre_deploy_services: ArrayOf[Symbol],
21
+ post_deploy_services: ArrayOf[Symbol],
21
22
  build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer],
22
23
  global_build_vars: HashOf[Symbol => Any],
23
24
  deployer_strategy: Symbol,
24
25
  deployer_namespace: Maybe[Or[Symbol, String]],
25
26
  deployer_require_confirmation: Bool,
26
27
  shell_launcher_strategy: Symbol,
28
+ generator_strategy: Symbol,
27
29
  ] => Any
28
30
  def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, kubectl_entrypoint:,
29
31
  services_attributes:, enabled_services:, disabled_services:, default_services:,
30
- initial_services:, build_servers:, global_build_vars:,
31
- deployer_strategy:, deployer_namespace:, deployer_require_confirmation:, shell_launcher_strategy:)
32
+ pre_deploy_services:, post_deploy_services:, build_servers:, global_build_vars:,
33
+ deployer_strategy:, deployer_namespace:, deployer_require_confirmation:, shell_launcher_strategy:, generator_strategy:)
32
34
  @name = name
33
35
  @artifacts = artifacts
34
36
  @registries = registries
@@ -41,12 +43,14 @@ class KuberKit::Core::Configuration
41
43
  @enabled_services = enabled_services
42
44
  @disabled_services = disabled_services
43
45
  @default_services = default_services
44
- @initial_services = initial_services
46
+ @pre_deploy_services = pre_deploy_services
47
+ @post_deploy_services = post_deploy_services
45
48
  @global_build_vars = global_build_vars
46
49
  @deployer_strategy = deployer_strategy
47
50
  @deployer_namespace = deployer_namespace
48
51
  @deployer_require_confirmation = deployer_require_confirmation
49
52
  @shell_launcher_strategy = shell_launcher_strategy
53
+ @generator_strategy = generator_strategy
50
54
  end
51
55
 
52
56
  def service_attributes(service_name)
@@ -9,13 +9,14 @@ class KuberKit::Core::ConfigurationDefinition
9
9
  @artifacts = {}
10
10
  @registries = {}
11
11
  @env_files = {}
12
- @templates = {}
13
- @build_servers = []
14
- @enabled_services = []
15
- @disabled_services = []
16
- @default_services = []
17
- @initial_services = []
18
- @services_attributes = {}
12
+ @templates = {}
13
+ @build_servers = []
14
+ @enabled_services = []
15
+ @disabled_services = []
16
+ @default_services = []
17
+ @pre_deploy_services = []
18
+ @post_deploy_services = []
19
+ @services_attributes = {}
19
20
  end
20
21
 
21
22
  def to_attrs
@@ -30,7 +31,8 @@ class KuberKit::Core::ConfigurationDefinition
30
31
  enabled_services: @enabled_services,
31
32
  disabled_services: @disabled_services,
32
33
  default_services: @default_services,
33
- initial_services: @initial_services,
34
+ pre_deploy_services: @pre_deploy_services,
35
+ post_deploy_services: @post_deploy_services,
34
36
  build_servers: @build_servers,
35
37
  services_attributes: @services_attributes,
36
38
  global_build_vars: @global_build_vars,
@@ -38,6 +40,7 @@ class KuberKit::Core::ConfigurationDefinition
38
40
  deployer_namespace: @deployer_namespace,
39
41
  deployer_require_confirmation: @deployer_require_confirmation || false,
40
42
  shell_launcher_strategy: @shell_launcher_strategy,
43
+ generator_strategy: @generator_strategy,
41
44
  )
42
45
  end
43
46
 
@@ -109,6 +112,12 @@ class KuberKit::Core::ConfigurationDefinition
109
112
  self
110
113
  end
111
114
 
115
+ def generator_strategy(strategy)
116
+ @generator_strategy = strategy
117
+
118
+ self
119
+ end
120
+
112
121
  def deployer_require_confirmation
113
122
  @deployer_require_confirmation = true
114
123
 
@@ -143,7 +152,19 @@ class KuberKit::Core::ConfigurationDefinition
143
152
  end
144
153
 
145
154
  def initial_services(services)
146
- @initial_services += services.map(&:to_sym)
155
+ unless KuberKit.deprecation_warnings_disabled?
156
+ puts "WARNING: initial_services is deprecated, please use pre_deploy_services instead"
157
+ end
158
+ pre_deploy_services(services)
159
+ end
160
+
161
+ def pre_deploy_services(services)
162
+ @pre_deploy_services += services.map(&:to_sym)
163
+ return self
164
+ end
165
+
166
+ def post_deploy_services(services)
167
+ @post_deploy_services += services.map(&:to_sym)
147
168
  return self
148
169
  end
149
170
 
@@ -32,12 +32,14 @@ class KuberKit::Core::ConfigurationFactory
32
32
  enabled_services: configuration_attrs.enabled_services,
33
33
  disabled_services: configuration_attrs.disabled_services,
34
34
  default_services: configuration_attrs.default_services,
35
- initial_services: configuration_attrs.initial_services,
35
+ pre_deploy_services: configuration_attrs.pre_deploy_services,
36
+ post_deploy_services: configuration_attrs.post_deploy_services,
36
37
  global_build_vars: configuration_attrs.global_build_vars || {},
37
38
  deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
38
39
  deployer_namespace: configuration_attrs.deployer_namespace,
39
40
  deployer_require_confirmation: configuration_attrs.deployer_require_confirmation,
40
41
  shell_launcher_strategy: configuration_attrs.shell_launcher_strategy || configs.shell_launcher_strategy,
42
+ generator_strategy: configuration_attrs.generator_strategy || configs.generator_strategy,
41
43
  )
42
44
  end
43
45
 
@@ -0,0 +1,5 @@
1
+ class KuberKit::Core::ContextHelper::AbstractHelper
2
+ def get_binding
3
+ binding
4
+ end
5
+ end
@@ -1,6 +1,4 @@
1
- class KuberKit::Core::ContextHelper::BaseHelper
2
- CONTRACT = RespondTo[:get_binding]
3
-
1
+ class KuberKit::Core::ContextHelper::BaseHelper < KuberKit::Core::ContextHelper::AbstractHelper
4
2
  attr_reader :shell, :artifact_store, :image_store, :env_file_reader
5
3
 
6
4
  def initialize(image_store:, artifact_store:, shell:, env_file_reader:)
@@ -39,8 +37,4 @@ class KuberKit::Core::ContextHelper::BaseHelper
39
37
  end
40
38
  global_build_vars
41
39
  end
42
-
43
- def get_binding
44
- binding
45
- end
46
40
  end
@@ -2,7 +2,8 @@ class KuberKit::Core::ContextHelper::ContextHelperFactory
2
2
  include KuberKit::Import[
3
3
  "core.image_store",
4
4
  "core.artifact_store",
5
- env_file_reader: "env_file_reader.action_handler"
5
+ template_renderer: "template_reader.renderer",
6
+ env_file_reader: "env_file_reader.action_handler"
6
7
  ]
7
8
 
8
9
  def build_image_context(shell, image)
@@ -22,6 +23,7 @@ class KuberKit::Core::ContextHelper::ContextHelperFactory
22
23
  shell: shell,
23
24
  env_file_reader: env_file_reader,
24
25
  service: service,
26
+ template_renderer: template_renderer
25
27
  )
26
28
  end
27
29
  end
@@ -0,0 +1,14 @@
1
+ class KuberKit::Core::ContextHelper::LocalContextHelper < KuberKit::Core::ContextHelper::AbstractHelper
2
+ def initialize(parent_context_helper:, variables:)
3
+ @parent_context_helper = parent_context_helper
4
+ @variables = variables
5
+ end
6
+
7
+ def method_missing(method_name, *args, &block)
8
+ if @variables.has_key?(method_name)
9
+ @variables[method_name]
10
+ else
11
+ @parent_context_helper.send(method_name, *args, &block)
12
+ end
13
+ end
14
+ end