kuber_kit 1.3.1 → 1.3.2

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: 31078802fb9b9050b29675dd4b364c667ea7dc0f554b395144166fa2b7e0ffce
4
- data.tar.gz: 585c56af43570387ee0ceb0985d0ceb2cbac7a4d5627103be1471f6757d2eabd
3
+ metadata.gz: a3a577fb45bf9933ff2168b199459df8bd3801246ec999e53d2f314a5cd76ca4
4
+ data.tar.gz: 50404be436a1821825e11109a9f34564b6cd162a0c7c8a20e27b023f55fcde9d
5
5
  SHA512:
6
- metadata.gz: 50a194368b224a8b35a6b24a9a22897a9ed0c891eb6888fee5f9c3e788d4114618647b18a6cffe31772cff641b2ee37361bb02cc14838eb18ea1ecd5b1fab3dd
7
- data.tar.gz: dc9c31daed2206895a685aec0737656f387d9d08726f5897a8fb5b89bcce254683231b809ccf75b5b4e4a88ca39cb65ec41b2a688513ac559dd842510f09e823
6
+ metadata.gz: e36744815c27471bbe4785cdaa83301b15080e15abd38a189a9ed06dbc38b6ec070a213018fca27e3b17ec61a24ca923461800aeb9ba5979cbaf909fcc90bbd5
7
+ data.tar.gz: d7720f929d549261f430cb4599ba4131f3472200aa53125355a7215f8e06c27a872a5cb7fb51be15ea93a333b56d82d2d2dd114c311e0ae9436671cb48920e37
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ **1.3.1**
2
+ - Added an ability to generate helm templates using `kit generate` command
3
+
1
4
  **1.3.1**
2
5
  - Fix upgrade command for helm strategy
3
6
 
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
@@ -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
data/lib/kuber_kit/cli.rb CHANGED
@@ -111,6 +111,16 @@ class KuberKit::CLI < Thor
111
111
  end
112
112
  end
113
113
 
114
+
115
+ desc "generate SERVICE_NAME PATH_NAME", "Generates a template for a given service in a given path"
116
+ def generate(service_name, path)
117
+ setup(options)
118
+
119
+ if KuberKit::Container['actions.configuration_loader'].call(options)
120
+ KuberKit::Container['actions.service_generator'].call(service_name.to_sym, path)
121
+ end
122
+ end
123
+
114
124
  desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
115
125
  def apply(file_path)
116
126
  setup(options)
@@ -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
@@ -301,6 +305,18 @@ class KuberKit::Container
301
305
  KuberKit::ServiceDeployer::ServiceDependencyResolver.new
302
306
  end
303
307
 
308
+ register "service_generator.action_handler" do
309
+ KuberKit::ServiceGenerator::ActionHandler.new
310
+ end
311
+
312
+ register "service_generator.strategy_detector" do
313
+ KuberKit::ServiceGenerator::StrategyDetector.new
314
+ end
315
+
316
+ register "service_generator.generator" do
317
+ KuberKit::ServiceGenerator::Generator.new
318
+ end
319
+
304
320
  register "service_reader.action_handler" do
305
321
  KuberKit::ServiceReader::ActionHandler.new
306
322
  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
 
@@ -50,6 +50,13 @@ class KuberKit::Core::Dependencies::AbstractDependencyResolver
50
50
  (deps + item_names).uniq
51
51
  end
52
52
 
53
+ # Get all dependencies for items (excluding the items themself), without any limitations
54
+ Contract Or[Symbol, ArrayOf[Symbol]] => Any
55
+ def get_all_deps(item_names)
56
+ deps = Array(item_names).map { |i| get_recursive_deps(i) }.flatten
57
+ deps.uniq - item_names
58
+ end
59
+
53
60
  def get_recursive_deps(item_name, dependency_tree: [])
54
61
  deps = get_deps(item_name)
55
62
 
@@ -1,25 +1,28 @@
1
1
  class KuberKit::Core::Service
2
2
  AttributeNotSet = Class.new(KuberKit::Error)
3
3
 
4
- attr_reader :name, :dependencies, :template_name, :tags, :images, :attributes, :deployer_strategy
4
+ attr_reader :name, :initializers, :template_name, :tags, :images, :attributes,
5
+ :deployer_strategy, :generator_strategy
5
6
 
6
7
  Contract KeywordArgs[
7
8
  name: Symbol,
8
- dependencies: ArrayOf[Symbol],
9
+ initializers: ArrayOf[Symbol],
9
10
  template_name: Maybe[Symbol],
10
11
  tags: ArrayOf[Symbol],
11
12
  images: ArrayOf[Symbol],
12
13
  attributes: HashOf[Symbol => Any],
13
- deployer_strategy: Maybe[Symbol]
14
+ deployer_strategy: Maybe[Symbol],
15
+ generator_strategy: Maybe[Symbol]
14
16
  ] => Any
15
- def initialize(name:, dependencies:, template_name:, tags:, images:, attributes:, deployer_strategy:)
17
+ def initialize(name:, initializers:, template_name:, tags:, images:, attributes:, deployer_strategy:, generator_strategy:)
16
18
  @name = name
17
- @dependencies = dependencies
19
+ @initializers = initializers
18
20
  @template_name = template_name
19
21
  @tags = tags
20
22
  @images = images
21
23
  @attributes = attributes
22
24
  @deployer_strategy = deployer_strategy
25
+ @generator_strategy = generator_strategy
23
26
  end
24
27
 
25
28
  def uri
@@ -1,26 +1,32 @@
1
1
  class KuberKit::Core::ServiceDefinition
2
- attr_reader :service_name, :template_name, :dependencies
2
+ attr_reader :service_name, :template_name, :dependencies, :initializers
3
3
 
4
4
  Contract Or[Symbol, String] => Any
5
5
  def initialize(service_name)
6
6
  @service_name = service_name.to_sym
7
- @dependencies = []
7
+ @initializers = []
8
8
  end
9
9
 
10
10
  def to_service_attrs
11
11
  OpenStruct.new(
12
12
  name: @service_name,
13
- dependencies: @dependencies,
13
+ initializers: @initializers,
14
14
  template_name: get_value(@template_name),
15
15
  tags: Array(get_value(@tags)).map(&:to_sym),
16
16
  images: Array(get_value(@images)).map(&:to_sym),
17
17
  attributes: get_value(@attributes),
18
18
  deployer_strategy: get_value(@deployer_strategy),
19
+ generator_strategy: get_value(@generator_strategy),
19
20
  )
20
21
  end
21
22
 
22
23
  def depends_on(*value, &block)
23
- @dependencies = Array(value).flatten
24
+ initialize_with(value)
25
+ self
26
+ end
27
+
28
+ def initialize_with(*value, &block)
29
+ @initializers = Array(value).flatten
24
30
  self
25
31
  end
26
32
 
@@ -54,6 +60,12 @@ class KuberKit::Core::ServiceDefinition
54
60
  self
55
61
  end
56
62
 
63
+ def generator_strategy(value = nil, &block)
64
+ @generator_strategy = block_given? ? block : value
65
+
66
+ self
67
+ end
68
+
57
69
  private
58
70
  def get_value(variable)
59
71
  variable.is_a?(Proc) ? variable.call : variable
@@ -7,12 +7,13 @@ class KuberKit::Core::ServiceFactory
7
7
 
8
8
  KuberKit::Core::Service.new(
9
9
  name: service_attrs.name,
10
- dependencies: service_attrs.dependencies,
10
+ initializers: service_attrs.initializers,
11
11
  template_name: service_attrs.template_name,
12
12
  tags: service_attrs.tags,
13
13
  images: service_attrs.images,
14
14
  attributes: attributes,
15
15
  deployer_strategy: service_attrs.deployer_strategy,
16
+ generator_strategy: service_attrs.generator_strategy,
16
17
  )
17
18
  end
18
19
  end
@@ -44,6 +44,11 @@ class KuberKit::Defaults
44
44
  KuberKit::ServiceDeployer::Strategies::Helm.new
45
45
  )
46
46
 
47
+ container["service_generator.generator"].register_strategy(
48
+ :helm,
49
+ KuberKit::ServiceGenerator::Strategies::Helm.new
50
+ )
51
+
47
52
  container["shell_launcher.launcher"].register_strategy(
48
53
  :kubernetes,
49
54
  KuberKit::ShellLauncher::Strategies::Kubernetes.new
@@ -5,7 +5,7 @@ class KuberKit::ServiceDeployer::ServiceDependencyResolver < KuberKit::Core::Dep
5
5
  ]
6
6
 
7
7
  def get_deps(service_name)
8
- service_store.get_definition(service_name).dependencies
8
+ service_store.get_definition(service_name).initializers
9
9
  end
10
10
 
11
11
  def dependency_batch_size
@@ -14,8 +14,8 @@ class KuberKit::ServiceDeployer::Strategies::Helm < KuberKit::ServiceDeployer::S
14
14
  chart_config_path = File.join(chart_root_path, "Chart.yaml")
15
15
  release_path = File.join(chart_templates_path, "release.yaml")
16
16
 
17
- bash_commands.mkdir_p(shell, File.dirname(chart_root_path))
18
- bash_commands.mkdir_p(shell, File.dirname(chart_templates_path))
17
+ bash_commands.mkdir_p(shell, chart_root_path)
18
+ bash_commands.mkdir_p(shell, chart_templates_path)
19
19
 
20
20
  shell.write(release_path, service_config)
21
21
  shell.write(chart_config_path, chart_config_content(service.uri))
@@ -0,0 +1,16 @@
1
+ class KuberKit::ServiceGenerator::ActionHandler
2
+ include KuberKit::Import[
3
+ "service_generator.generator",
4
+ "service_generator.strategy_detector",
5
+ "core.service_store",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
9
+ def call(shell, service_name, export_path)
10
+ service = service_store.get_service(service_name)
11
+
12
+ strategy_name = strategy_detector.call(service)
13
+
14
+ generator.generate(shell, service, export_path, strategy_name)
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ class KuberKit::ServiceGenerator::Generator
2
+ StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
+
4
+ include KuberKit::Import[
5
+ "core.service_store",
6
+ ]
7
+
8
+ def register_strategy(strategy_name, strategy)
9
+ @@strategies ||= {}
10
+
11
+ if !strategy.is_a?(KuberKit::ServiceGenerator::Strategies::Abstract)
12
+ raise ArgumentError.new("should be an instance of KuberKit::ServiceGenerator::Strategies::Abstract, got: #{strategy.inspect}")
13
+ end
14
+
15
+ @@strategies[strategy_name] = strategy
16
+ end
17
+
18
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, String, Symbol => Any
19
+ def generate(shell, service, export_path, strategy_name)
20
+ generator = @@strategies[strategy_name]
21
+
22
+ raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if generator.nil?
23
+
24
+ generator.generate(shell, service, export_path)
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ class KuberKit::ServiceGenerator::Strategies::Abstract
2
+ def generate(shell, service, export_path)
3
+ raise KuberKit::NotImplementedError, "must be implemented"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ class KuberKit::ServiceGenerator::Strategies::Helm < KuberKit::ServiceGenerator::Strategies::Abstract
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "shell.bash_commands",
5
+ "configs",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, String => Any
9
+ def generate(shell, service, export_path)
10
+ service_config = reader.read(shell, service)
11
+ chart_root_path = File.join(export_path, "#{service.name}_chart")
12
+ chart_templates_path = File.join(chart_root_path, "templates")
13
+ chart_config_path = File.join(chart_root_path, "Chart.yaml")
14
+ release_path = File.join(chart_templates_path, "release.yaml")
15
+
16
+ bash_commands.mkdir_p(shell, chart_root_path)
17
+ bash_commands.mkdir_p(shell, chart_templates_path)
18
+
19
+ shell.write(release_path, service_config)
20
+ shell.write(chart_config_path, chart_config_content(service.uri))
21
+ end
22
+
23
+ def chart_config_content(release_name)
24
+ query = <<-CHART
25
+ apiVersion: v2
26
+ name: #{release_name}
27
+ description: #{release_name}
28
+ type: application
29
+ version: 1.0.0
30
+ appVersion: "1.0.0"
31
+ CHART
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ class KuberKit::ServiceGenerator::StrategyDetector
2
+ Contract KuberKit::Core::Service => Symbol
3
+ def call(service)
4
+ service.generator_strategy || KuberKit.current_configuration.generator_strategy
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
data/lib/kuber_kit.rb CHANGED
@@ -171,6 +171,17 @@ module KuberKit
171
171
  end
172
172
  end
173
173
 
174
+ module ServiceGenerator
175
+ autoload :ActionHandler, 'service_generator/action_handler'
176
+ autoload :StrategyDetector, 'service_generator/strategy_detector'
177
+ autoload :Generator, 'service_generator/generator'
178
+
179
+ module Strategies
180
+ autoload :Abstract, 'service_generator/strategies/abstract'
181
+ autoload :Helm, 'service_generator/strategies/helm'
182
+ end
183
+ end
184
+
174
185
  module ServiceReader
175
186
  autoload :ActionHandler, 'service_reader/action_handler'
176
187
  autoload :Reader, 'service_reader/reader'
@@ -194,6 +205,7 @@ module KuberKit
194
205
  autoload :ServiceReader, 'actions/service_reader'
195
206
  autoload :ServiceDeployer, 'actions/service_deployer'
196
207
  autoload :ServiceChecker, 'actions/service_checker'
208
+ autoload :ServiceGenerator, 'actions/service_generator'
197
209
  autoload :ConfigurationLoader, 'actions/configuration_loader'
198
210
  autoload :KubectlApplier, 'actions/kubectl_applier'
199
211
  autoload :KubectlAttacher, 'actions/kubectl_attacher'
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: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Khaziev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -259,6 +259,7 @@ files:
259
259
  - lib/kuber_kit/actions/kubectl_logs.rb
260
260
  - lib/kuber_kit/actions/service_checker.rb
261
261
  - lib/kuber_kit/actions/service_deployer.rb
262
+ - lib/kuber_kit/actions/service_generator.rb
262
263
  - lib/kuber_kit/actions/service_reader.rb
263
264
  - lib/kuber_kit/actions/shell_launcher.rb
264
265
  - lib/kuber_kit/actions/template_reader.rb
@@ -346,6 +347,11 @@ files:
346
347
  - lib/kuber_kit/service_deployer/strategies/helm.rb
347
348
  - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
348
349
  - lib/kuber_kit/service_deployer/strategy_detector.rb
350
+ - lib/kuber_kit/service_generator/action_handler.rb
351
+ - lib/kuber_kit/service_generator/generator.rb
352
+ - lib/kuber_kit/service_generator/strategies/abstract.rb
353
+ - lib/kuber_kit/service_generator/strategies/helm.rb
354
+ - lib/kuber_kit/service_generator/strategy_detector.rb
349
355
  - lib/kuber_kit/service_reader/action_handler.rb
350
356
  - lib/kuber_kit/service_reader/reader.rb
351
357
  - lib/kuber_kit/shell/abstract_shell.rb