kuber_kit 1.2.2 → 1.2.5

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: 7f69884ef6e30281b67385b81819ffed74011f7a01e9358a0f1b77a7444331e5
4
- data.tar.gz: e6cd8ab2e34d054a52080820b0d3ecf1839311a65b4c4549c78d174b55a98fc0
3
+ metadata.gz: bf57924285ae666f588c17e429237e45bf7fc1666683354a4b55de25592a994f
4
+ data.tar.gz: f8b7bcf9bcc1d82f9f3489d1d2b6763f281ca0398ef494b78ae11054c4c35019
5
5
  SHA512:
6
- metadata.gz: 720a65d065a919c187c81d29d07813a6ab5cb8c5522c18cbe62fa9bb8dac5f148c6936ec7c56d4bfc6075b482569e4619bae81cc4dec8c01beb4c006182a4935
7
- data.tar.gz: 063c4d468b3a0ffcb32e48ea71648f84ab4aa334dc64cc5efdfad5aa3ca9f6a08517733a15de79b89fc2c302543d1947a5af46fb65bf01c175094d8fc328027c
6
+ metadata.gz: ed268c5ca27198e9b9842d6f706f83cf83506e9abf8bb95bb23ed97a439b7ae8e9c867c6f88a2ad3a35a9cc2b8e969adbdd88363257e55f02b445f4075df933c
7
+ data.tar.gz: d2480528964184aadd99b9697898dcbc0da94cb7e8deac75496ea0bf7b47e7013c6c1824f897b4eb46b56b9ba954075b1740bc7ac3bc9ae9bb3d62b60dd2ce64
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ **1.2.5**
2
+ - Improve handling ContextVars, ability to convert context var to OpenStruct
3
+
4
+ **1.2.4**
5
+ - Fix a mistake in setting env variables
6
+ - Added an option to set "use local deployment" variable
7
+ - Allow finding job resources in kit attach and kit log
8
+
1
9
  **1.2.2**
2
10
  - Support Ruby 3.2.0
3
11
 
@@ -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,6 +29,7 @@ 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
 
@@ -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
 
@@ -84,6 +90,10 @@ class KuberKit::Actions::ConfigurationLoader
84
90
  configuration_name = first_configurations.configuration_name
85
91
  end
86
92
 
93
+ if configuration_store.count > 1 && configuration_name
94
+ ui.print_info("Configuration", "Using configuration: #{configuration_name.to_s.cyan}")
95
+ end
96
+
87
97
  if configuration_store.count > 1 && configuration_name.nil?
88
98
  options = all_configurations.map(&:configuration_name).map(&:to_s)
89
99
  configuration_name = ui.prompt("Please select configuration name (or set it using -C option)", options)
@@ -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)
@@ -1,15 +1,21 @@
1
+ require 'ostruct'
1
2
  class KuberKit::Core::ContextHelper::ContextVars
2
3
  attr_reader :parent, :parent_name
3
4
 
4
5
  BuildArgUndefined = Class.new(KuberKit::Error)
5
6
 
6
- def initialize(context_vars, parent_name = nil, parent = nil)
7
+ def initialize(context_vars, parent_name = nil)
7
8
  @context_vars = context_vars
8
9
  @parent_name = parent_name
9
- @parent = parent
10
10
  end
11
11
 
12
- def read(*variable_names)
12
+ def read(*variable_names, default: nil)
13
+ dig(*variable_names)
14
+ rescue BuildArgUndefined
15
+ return default
16
+ end
17
+
18
+ def dig(*variable_names)
13
19
  result = self
14
20
  variable_names.each do |var|
15
21
  result = result.get_variable_value(var)
@@ -18,7 +24,7 @@ class KuberKit::Core::ContextHelper::ContextVars
18
24
  end
19
25
 
20
26
  def variable_defined?(*variable_names)
21
- read(*variable_names)
27
+ dig(*variable_names)
22
28
  return true
23
29
  rescue BuildArgUndefined
24
30
  return false
@@ -29,15 +35,30 @@ class KuberKit::Core::ContextHelper::ContextVars
29
35
  raise ArgumentError.new("context args does not accept any arguments")
30
36
  end
31
37
 
32
- read(name)
38
+ dig(name)
39
+ end
40
+
41
+ def keys
42
+ @context_vars.keys
33
43
  end
34
44
 
35
45
  def to_h
36
- if @context_vars.is_a?(Hash)
37
- return @context_vars
38
- else
39
- 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]
40
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]
59
+ end
60
+ hash = Hash[values]
61
+ OpenStruct.new(hash)
41
62
  end
42
63
 
43
64
  def get_variable_value(variable_name)
@@ -46,23 +67,16 @@ class KuberKit::Core::ContextHelper::ContextVars
46
67
  end
47
68
 
48
69
  if value.is_a?(Hash)
49
- return self.class.new(value, variable_name, self)
70
+ return self.class.new(value, format_arg(variable_name))
50
71
  end
51
72
 
52
73
  value
53
74
  end
54
75
 
55
76
  private
77
+
56
78
 
57
79
  def format_arg(name)
58
- string = [@parent_name, name].compact.join(".")
59
- parent = @parent
60
-
61
- while parent do
62
- string = [parent.parent_name, string].compact.join(".")
63
- parent = parent.parent
64
- end
65
-
66
- string
80
+ [@parent_name, name].compact.join(".")
67
81
  end
68
82
  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
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.5"
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: 1.2.2
4
+ version: 1.2.5
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-02-05 00:00:00.000000000 Z
11
+ date: 2023-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -397,7 +397,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
397
  - !ruby/object:Gem::Version
398
398
  version: '0'
399
399
  requirements: []
400
- rubygems_version: 3.3.7
400
+ rubygems_version: 3.4.1
401
401
  signing_key:
402
402
  specification_version: 4
403
403
  summary: Docker Containers Build & Deployment