kuber_kit 1.1.4 → 1.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70bdef220e67c9789122ab7eb7ee064dff475174ec1e497b0baf11566da6e1f
4
- data.tar.gz: 004b9a6c4e8265f1f3f498b1b42fa35a0447567ef428abef4b571cce635c0cd9
3
+ metadata.gz: 107bd2fce24cb2f396cbca12bb77b5b83c412f8a1e7f2bdf034b382235c9c570
4
+ data.tar.gz: fd76a3ca50d55f869e114dd1a5f3a1bae2eebee3c67bbde664c9365ea89ff606
5
5
  SHA512:
6
- metadata.gz: 1e60b51c8108814fc41f89b41a28732e59a8f5bddb938ee94d8cb765ccc5f2ea3de260aed0a52a212649389814884c40734c7f60fe77502e78e3814821c31790
7
- data.tar.gz: 5f165249b8d91cd8bc148f9cc5f3a3a9a57402355c371b30f7f8511fcb6bf8d0650a7ba7a08c072dcba550837e52aced3a1d9cec4959be98c18d5b526678fb29
6
+ metadata.gz: a13c1734350136c2474c3333fc2540096e95aabe05039f2eb0cbdb7fb426aa150e1413a3841d7329cbd09ada0f8302443c42df6875f3b486b2e35100bf84fc0e
7
+ data.tar.gz: f2278b48b2d37cdd526acdf57841505d524fefecc0eba83fa2929722d629e7398c8909fffe717c98ff41619aefce3411bfba2c0f1e18ebbbd11ee518eba5d557
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ **1.3.1**
2
+ - Fix upgrade command for helm strategy
3
+
4
+ **1.3.0**
5
+ - Allow sending custom apply command for k8s deploy strategy
6
+ - Added initial support for helm deploy strategy
7
+
8
+ **1.2.7**
9
+ - Added an option to skip deployment and only build images for `deploy` command
10
+
11
+ **1.2.6**
12
+ - Lock cli-ui version on 2.1.0 (2.2.x has some bugs)
13
+
14
+ **1.2.5**
15
+ - Improve handling ContextVars, ability to convert context var to OpenStruct
16
+
17
+ **1.2.4**
18
+ - Fix a mistake in setting env variables
19
+ - Added an option to set "use local deployment" variable
20
+ - Allow finding job resources in kit attach and kit log
21
+
22
+ **1.2.2**
23
+ - Support Ruby 3.2.0
24
+
1
25
  **1.2.1**
2
26
  - Update shell commands so that STDERR stream won't be merged for commands using the command result.
3
27
  - kit sh would also set current default configuration
data/README.md CHANGED
@@ -19,7 +19,8 @@ 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.4 |
22
+ | 2.7 | 1.1.3 |
23
+ | > 3.0 | 1.2.6 |
23
24
 
24
25
  ## Usage
25
26
 
data/kuber_kit.gemspec CHANGED
@@ -25,11 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = ">= 2.7.0"
27
27
 
28
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
29
- spec.add_dependency "contracts", '0.17.0'
30
- else
31
- spec.add_dependency "contracts", '0.16.0'
32
- end
28
+ spec.add_dependency "contracts", '0.16.0'
33
29
 
34
30
  spec.add_dependency "dry-auto_inject", "~> 0.9.0"
35
31
  spec.add_dependency "dry-core", "~> 0.8.1"
@@ -37,7 +33,7 @@ Gem::Specification.new do |spec|
37
33
  spec.add_dependency "dry-container", "~> 0.10.1"
38
34
 
39
35
  spec.add_dependency "thor"
40
- spec.add_dependency "cli-ui"
36
+ spec.add_dependency "cli-ui", '2.1.0'
41
37
  spec.add_dependency "net-ssh"
42
38
  spec.add_dependency "tty-prompt"
43
39
 
@@ -20,6 +20,7 @@ class KuberKit::Actions::ConfigurationLoader
20
20
  configurations_path = options[:configurations_path] || File.join(root_path, configs.configurations_dirname)
21
21
  configuration_name = options[:configuration] || ENV["KUBER_KIT_CONFIGURATION"]
22
22
  load_inventory = options.fetch(:load_inventory, true)
23
+ use_local_deploy = options.fetch(:use_local_deploy, false)
23
24
 
24
25
  ui.print_debug "ConfigurationLoader", "Launching kuber_kit with:"
25
26
  ui.print_debug "ConfigurationLoader", " Root path: #{root_path.to_s.yellow}"
@@ -28,10 +29,11 @@ class KuberKit::Actions::ConfigurationLoader
28
29
  ui.print_debug "ConfigurationLoader", " Infrastructure path: #{infra_path.to_s.yellow}"
29
30
  ui.print_debug "ConfigurationLoader", " Configurations path: #{configurations_path.to_s.yellow}"
30
31
  ui.print_debug "ConfigurationLoader", " Configuration name: #{configuration_name.to_s.yellow}"
32
+ ui.print_debug "ConfigurationLoader", " Use local deploy: #{use_local_deploy.to_s.yellow}"
31
33
 
32
34
  ui.print_info("Logs", "See logs at: #{configs.log_file_path}")
33
35
 
34
- unless File.exists?(root_path)
36
+ unless File.exist?(root_path)
35
37
  ui.print_warning "ConfigurationLoader", "KuberKit root path #{root_path} doesn't exist. You may want to pass it --path parameter."
36
38
  end
37
39
 
@@ -39,6 +41,10 @@ class KuberKit::Actions::ConfigurationLoader
39
41
  raise KuberKit::Error, "The minimal required kuber_kit version is #{configs.kuber_kit_min_version}"
40
42
  end
41
43
 
44
+ if use_local_deploy
45
+ ENV["KUBER_KIT_USE_LOCAL_DEPLOYMENT"] = "true"
46
+ end
47
+
42
48
  load_configurations(configurations_path, configuration_name)
43
49
  load_infrastructure(infra_path)
44
50
 
@@ -7,17 +7,20 @@ class KuberKit::Actions::KubectlAttacher
7
7
  ]
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
- def call(pod_name, options)
10
+ def call(resource_name, options)
11
11
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
12
  kubectl_entrypoint = KuberKit.current_configuration.kubectl_entrypoint
13
13
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
14
14
 
15
- if !pod_name
16
- pod_name = resource_selector.call("attach")
15
+ if !resource_name
16
+ resource_name = resource_selector.call("attach", additional_resources: [
17
+ KuberKit::Kubernetes::Resources::POD,
18
+ KuberKit::Kubernetes::Resources::JOB
19
+ ])
17
20
  end
18
21
 
19
22
  kubectl_commands.exec(
20
- local_shell, pod_name, "bash", args: "-it",
23
+ local_shell, resource_name, "bash", args: "-it",
21
24
  kubeconfig_path: kubeconfig_path,
22
25
  interactive: true,
23
26
  namespace: deployer_namespace,
@@ -7,12 +7,15 @@ class KuberKit::Actions::KubectlLogs
7
7
  ]
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
- def call(pod_name, options)
10
+ def call(resource_name, options)
11
11
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
12
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
13
13
 
14
- if !pod_name
15
- pod_name = resource_selector.call("attach")
14
+ if !resource_name
15
+ resource_name = resource_selector.call("attach", additional_resources: [
16
+ KuberKit::Kubernetes::Resources::POD,
17
+ KuberKit::Kubernetes::Resources::JOB
18
+ ])
16
19
  end
17
20
 
18
21
  args = nil
@@ -21,7 +24,7 @@ class KuberKit::Actions::KubectlLogs
21
24
  end
22
25
 
23
26
  kubectl_commands.logs(
24
- local_shell, pod_name,
27
+ local_shell, resource_name,
25
28
  args: args,
26
29
  kubeconfig_path: kubeconfig_path,
27
30
  namespace: deployer_namespace
data/lib/kuber_kit/cli.rb CHANGED
@@ -11,6 +11,7 @@ class KuberKit::CLI < Thor
11
11
  class_option :debug, :type => :boolean, aliases: ["-d"]
12
12
  class_option :configuration, :type => :string, aliases: ["-C"]
13
13
  class_option :user, :type => :string, aliases: ["-u"]
14
+ class_option :use_local_deploy, :type => :boolean, aliases: ["-l"]
14
15
 
15
16
  desc "compile IMAGE_NAMES", "Compile image with IMAGE_NAMES (comma-separated)"
16
17
  def compile(image_names_str)
@@ -211,7 +212,7 @@ class KuberKit::CLI < Thor
211
212
  # We should load config before loading any bean, to make sure that bean won't be built with default config
212
213
  root_path = KuberKit::Container['tools.workdir_detector'].call(options)
213
214
  config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
214
- if File.exists?(config_file_path)
215
+ if File.exist?(config_file_path)
215
216
  require config_file_path
216
217
  end
217
218
  end
@@ -181,6 +181,10 @@ class KuberKit::Container
181
181
  KuberKit::Shell::Commands::SystemCommands.new
182
182
  end
183
183
 
184
+ register "shell.helm_commands" do
185
+ KuberKit::Shell::Commands::HelmCommands.new
186
+ end
187
+
184
188
  register "shell.local_shell" do
185
189
  KuberKit::Shell::LocalShell.new
186
190
  end
@@ -1,3 +1,4 @@
1
+ require 'ostruct'
1
2
  class KuberKit::Core::ContextHelper::ContextVars
2
3
  attr_reader :parent, :parent_name
3
4
 
@@ -37,12 +38,27 @@ class KuberKit::Core::ContextHelper::ContextVars
37
38
  dig(name)
38
39
  end
39
40
 
41
+ def keys
42
+ @context_vars.keys
43
+ end
44
+
40
45
  def to_h
41
- if @context_vars.is_a?(Hash)
42
- return @context_vars
43
- else
44
- return {value: @context_vars}
46
+ values = keys.map do |key|
47
+ value = get_variable_value(key)
48
+ hash_value = value.respond_to?(:to_h) ? value.to_h : value
49
+ [key, hash_value]
50
+ end
51
+ Hash[values]
52
+ end
53
+
54
+ def to_struct
55
+ values = keys.map do |key|
56
+ value = get_variable_value(key)
57
+ hash_value = value.respond_to?(:to_struct) ? value.to_struct : value
58
+ [key, hash_value]
45
59
  end
60
+ hash = Hash[values]
61
+ OpenStruct.new(hash)
46
62
  end
47
63
 
48
64
  def get_variable_value(variable_name)
@@ -39,6 +39,10 @@ class KuberKit::Defaults
39
39
  :docker_compose,
40
40
  KuberKit::ServiceDeployer::Strategies::DockerCompose.new
41
41
  )
42
+ container["service_deployer.deployer"].register_strategy(
43
+ :helm,
44
+ KuberKit::ServiceDeployer::Strategies::Helm.new
45
+ )
42
46
 
43
47
  container["shell_launcher.launcher"].register_strategy(
44
48
  :kubernetes,
@@ -0,0 +1,41 @@
1
+ class KuberKit::ServiceDeployer::Strategies::Helm < KuberKit::ServiceDeployer::Strategies::Abstract
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "shell.helm_commands",
5
+ "shell.bash_commands",
6
+ "configs",
7
+ ]
8
+
9
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
10
+ def deploy(shell, service)
11
+ service_config = reader.read(shell, service)
12
+ chart_root_path = File.join(configs.service_config_dir, "#{service.name}_chart")
13
+ chart_templates_path = File.join(chart_root_path, "templates")
14
+ chart_config_path = File.join(chart_root_path, "Chart.yaml")
15
+ release_path = File.join(chart_templates_path, "release.yaml")
16
+
17
+ bash_commands.mkdir_p(shell, File.dirname(chart_root_path))
18
+ bash_commands.mkdir_p(shell, File.dirname(chart_templates_path))
19
+
20
+ shell.write(release_path, service_config)
21
+ shell.write(chart_config_path, chart_config_content(service.uri))
22
+
23
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
24
+ namespace = KuberKit.current_configuration.deployer_namespace
25
+
26
+ upgrade_result = helm_commands.upgrade(shell, service.uri, chart_root_path, kubeconfig_path: kubeconfig_path, namespace: namespace)
27
+
28
+ upgrade_result
29
+ end
30
+
31
+ def chart_config_content(release_name)
32
+ query = <<-CHART
33
+ apiVersion: v2
34
+ name: #{release_name}
35
+ description: #{release_name}
36
+ type: application
37
+ version: 1.0.0
38
+ appVersion: "1.0.0"
39
+ CHART
40
+ end
41
+ end
@@ -10,7 +10,8 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
10
10
  :resource_name,
11
11
  :delete_if_exists,
12
12
  :restart_if_exists,
13
- :wait_for_rollout
13
+ :wait_for_rollout,
14
+ :apply_command
14
15
  ]
15
16
 
16
17
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
@@ -40,7 +41,12 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
40
41
  kubectl_commands.delete_resource(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
41
42
  end
42
43
 
43
- apply_result = kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: namespace)
44
+ apply_result = kubectl_commands.apply_file(
45
+ shell, config_path,
46
+ kubeconfig_path: kubeconfig_path,
47
+ namespace: namespace,
48
+ apply_command: strategy_options.fetch(:apply_command, "apply")
49
+ )
44
50
 
45
51
  restart_enabled = strategy_options.fetch(:restart_if_exists, true)
46
52
  wait_for_rollout = strategy_options.fetch(:wait_for_rollout, true)
@@ -44,7 +44,7 @@ class KuberKit::Shell::Commands::DockerCommands
44
44
  if status
45
45
  command_parts << "--filter=\"status=#{status}\""
46
46
  end
47
- command_parts << "--filter=\"name=#{container_name}\""
47
+ command_parts << "--filter=\"name=^/#{container_name}$\""
48
48
 
49
49
  shell.exec!(command_parts.join(" "))
50
50
  end
@@ -0,0 +1,42 @@
1
+ class KuberKit::Shell::Commands::HelmCommands
2
+ Contract KuberKit::Shell::AbstractShell, Or[String, ArrayOf[String]], KeywordArgs[
3
+ kubeconfig_path: Maybe[Or[
4
+ String, KuberKit::Core::ArtifactPath
5
+ ]],
6
+ namespace: Maybe[Or[Symbol, String]],
7
+ interactive: Optional[Bool],
8
+ ] => Any
9
+ def helm_run(shell, command_list, kubeconfig_path: nil, namespace: nil, interactive: false)
10
+ command_parts = []
11
+
12
+ if kubeconfig_path.is_a?(KuberKit::Core::ArtifactPath)
13
+ kubeconfig_path = artifact_path_resolver.call(kubeconfig_path)
14
+ end
15
+
16
+ if kubeconfig_path
17
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
18
+ end
19
+
20
+ command_parts << "helm"
21
+
22
+ if namespace
23
+ command_parts << "-n #{namespace}"
24
+ end
25
+
26
+ command_parts += Array(command_list).compact
27
+
28
+ if interactive
29
+ shell.interactive!(command_parts.join(" "))
30
+ else
31
+ shell.exec!(command_parts.join(" "))
32
+ end
33
+ end
34
+
35
+ def install(shell, release_name, chart_path, kubeconfig_path: nil, namespace: nil)
36
+ helm_run(shell, "install #{release_name} #{chart_path}", kubeconfig_path: kubeconfig_path, namespace: namespace)
37
+ end
38
+
39
+ def upgrade(shell, release_name, chart_path, kubeconfig_path: nil, namespace: nil)
40
+ helm_run(shell, "upgrade #{release_name} #{chart_path} --install", kubeconfig_path: kubeconfig_path, namespace: namespace)
41
+ end
42
+ end
@@ -39,8 +39,9 @@ class KuberKit::Shell::Commands::KubectlCommands
39
39
  end
40
40
  end
41
41
 
42
- def apply_file(shell, file_path, kubeconfig_path: nil, namespace: nil)
43
- kubectl_run(shell, "apply -f #{file_path}", kubeconfig_path: kubeconfig_path, namespace: namespace)
42
+ def apply_file(shell, file_path, kubeconfig_path: nil, namespace: nil, apply_command: nil)
43
+ apply_command ||= "apply"
44
+ kubectl_run(shell, "#{apply_command} -f #{file_path}", kubeconfig_path: kubeconfig_path, namespace: namespace)
44
45
  end
45
46
 
46
47
  def exec(shell, pod_name, command, args: nil, kubeconfig_path: nil, interactive: false, namespace: nil, entrypoint: nil)
@@ -138,7 +138,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
138
138
  def ensure_directory_exists(file_path)
139
139
  dir_path = File.dirname(file_path)
140
140
 
141
- unless Dir.exists?(dir_path)
141
+ unless Dir.exist?(dir_path)
142
142
  FileUtils.mkdir_p(dir_path)
143
143
  end
144
144
  end
@@ -26,6 +26,6 @@ class KuberKit::ShellLauncher::Strategies::Kubernetes < KuberKit::ShellLauncher:
26
26
  env_vars << "KUBER_KIT_CONFIGURATION=#{KuberKit.current_configuration.name}"
27
27
  end
28
28
 
29
- shell.replace!(env: ["KUBECONFIG=#{kubeconfig_path}", "KUBER_KIT_SHELL_CONFIGURATION=#{KuberKit.current_configuration.name}"])
29
+ shell.replace!(env: env_vars)
30
30
  end
31
31
  end
@@ -45,7 +45,7 @@ class KuberKit::Tools::LoggerFactory
45
45
  private
46
46
  def prepare_log_file(file_path)
47
47
  dir_path = File.dirname(file_path)
48
- unless Dir.exists?(dir_path)
48
+ unless Dir.exist?(dir_path)
49
49
  FileUtils.mkdir_p(dir_path)
50
50
  end
51
51
  FileUtils.touch(file_path)
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "1.1.4"
2
+ VERSION = "1.1.5"
3
3
  end
data/lib/kuber_kit.rb CHANGED
@@ -104,6 +104,7 @@ module KuberKit
104
104
  autoload :RsyncCommands, 'shell/commands/rsync_commands'
105
105
  autoload :KubectlCommands, 'shell/commands/kubectl_commands'
106
106
  autoload :SystemCommands, 'shell/commands/system_commands'
107
+ autoload :HelmCommands, 'shell/commands/helm_commands'
107
108
  end
108
109
  end
109
110
 
@@ -166,6 +167,7 @@ module KuberKit
166
167
  autoload :Docker, 'service_deployer/strategies/docker'
167
168
  autoload :DockerCompose, 'service_deployer/strategies/docker_compose'
168
169
  autoload :Kubernetes, 'service_deployer/strategies/kubernetes'
170
+ autoload :Helm, 'service_deployer/strategies/helm'
169
171
  end
170
172
  end
171
173
 
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.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Khaziev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-17 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: cli-ui
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 2.1.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 2.1.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: net-ssh
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -343,6 +343,7 @@ files:
343
343
  - lib/kuber_kit/service_deployer/strategies/abstract.rb
344
344
  - lib/kuber_kit/service_deployer/strategies/docker.rb
345
345
  - lib/kuber_kit/service_deployer/strategies/docker_compose.rb
346
+ - lib/kuber_kit/service_deployer/strategies/helm.rb
346
347
  - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
347
348
  - lib/kuber_kit/service_deployer/strategy_detector.rb
348
349
  - lib/kuber_kit/service_reader/action_handler.rb
@@ -353,6 +354,7 @@ files:
353
354
  - lib/kuber_kit/shell/commands/docker_commands.rb
354
355
  - lib/kuber_kit/shell/commands/docker_compose_commands.rb
355
356
  - lib/kuber_kit/shell/commands/git_commands.rb
357
+ - lib/kuber_kit/shell/commands/helm_commands.rb
356
358
  - lib/kuber_kit/shell/commands/kubectl_commands.rb
357
359
  - lib/kuber_kit/shell/commands/rsync_commands.rb
358
360
  - lib/kuber_kit/shell/commands/system_commands.rb
@@ -382,7 +384,7 @@ homepage: https://github.com/ArtStation/kuber_kit
382
384
  licenses:
383
385
  - MIT
384
386
  metadata: {}
385
- post_install_message:
387
+ post_install_message:
386
388
  rdoc_options: []
387
389
  require_paths:
388
390
  - lib
@@ -398,7 +400,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
400
  version: '0'
399
401
  requirements: []
400
402
  rubygems_version: 3.1.6
401
- signing_key:
403
+ signing_key:
402
404
  specification_version: 4
403
405
  summary: Docker Containers Build & Deployment
404
406
  test_files: []