kuber_kit 0.8.8 → 0.9.0

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: 2d30438270f3b2b82520081fc47903c6a19fdf916369bb238a387bc99b8fa7ab
4
- data.tar.gz: 661c969777f171ead96170c795f04d4cce93989eec75de7a89bf65f8e4711e62
3
+ metadata.gz: 6eb3dda64697fc3174d3ae031a7eba5be1f57e80d0c8c43829ff3b36edca38b2
4
+ data.tar.gz: 85a77edc9bdc91c09c6ba6f3e677df032168c66a69a563ddd9087734fa9636bc
5
5
  SHA512:
6
- metadata.gz: 7db454d99455a028a8a235efb4873ea199f38800e818e868d54dc29626ab2694f73e4264a3ec61aa5a355e1b4aaeebabf17fee92efb9e630407dacb004513ee9
7
- data.tar.gz: 00412d664f4beb3ae004a04b916dc75bb7d7284a1a4c8add1a283f2039953fdcd4e84e219432e6fde1fe3a1111af54eec07cdc9b8671b59f9c501dd1dd12ce9c
6
+ metadata.gz: 1696812c543f40ec81cb7c4c7804f4f02e739cf7ccff6820f37b884f7965a0822ceb1b2dbc42e7ca9d696f7d539d5b0e44ff6142991178bd9316bdd98276ca09
7
+ data.tar.gz: 8887273eba2ca2b3f714249d4da29dfb826477e08da4f09d06ab9974c5a32e8b698bbeb2f9b0bb7a6cbd75884aba3bedca6adc71ee7d7e53a1a8d3637b798d7f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ **0.9.0**
2
+ - Allow skipping confirmation during deployment
3
+ - Added `kit sh` command to create a new shell
4
+ - Do not expand directory path in config
5
+
1
6
  **0.8.4-0.8.8**
2
7
  - Added initial services support, to deploy before all other servies
3
8
  - Allow namespace as symbol in kubectl commands
@@ -0,0 +1,18 @@
1
+ class KuberKit::Actions::ShellLauncher
2
+ include KuberKit::Import[
3
+ "shell.local_shell",
4
+ "shell_launcher.action_handler",
5
+ "ui",
6
+ ]
7
+
8
+ Contract nil => Any
9
+ def call()
10
+ action_handler.call(local_shell)
11
+
12
+ true
13
+ rescue KuberKit::Error => e
14
+ ui.print_error("Error", e.message)
15
+
16
+ false
17
+ end
18
+ end
data/lib/kuber_kit/cli.rb CHANGED
@@ -41,6 +41,7 @@ class KuberKit::CLI < Thor
41
41
  method_option :skip_compile, :type => :boolean, aliases: ["-B"]
42
42
  method_option :skip_dependencies, :type => :boolean, aliases: ["-D"]
43
43
  method_option :require_confirmation, :type => :boolean, aliases: ["-r"]
44
+ method_option :skip_confirmation, :type => :boolean, aliases: ["-R"]
44
45
  def deploy
45
46
  setup(options)
46
47
 
@@ -48,6 +49,7 @@ class KuberKit::CLI < Thor
48
49
  require_confirmation = options[:require_confirmation] ||
49
50
  KuberKit.current_configuration.deployer_require_confirmation ||
50
51
  false
52
+ require_confirmation = false if options[:skip_confirmation]
51
53
  started_at = Time.now.to_i
52
54
  action_result = KuberKit::Container['actions.service_deployer'].call(
53
55
  services: (options[:services] || []).flatten.uniq,
@@ -161,6 +163,15 @@ class KuberKit::CLI < Thor
161
163
  end
162
164
  end
163
165
 
166
+ desc "sh", "Create a new shell with KUBECONFIG env variable in place"
167
+ def sh()
168
+ setup(options)
169
+
170
+ if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
171
+ KuberKit::Container['actions.shell_launcher'].call()
172
+ end
173
+ end
174
+
164
175
  desc "get RESOURCE_NAME", "List pods matching RESOURCE_NAME using kubectl"
165
176
  def get(pod_name = nil)
166
177
  setup(options)
@@ -5,7 +5,7 @@ class KuberKit::Configs
5
5
  :image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :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
8
+ :additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir, :shell_launcher_strategy
9
9
  ]
10
10
  DOCKER_IGNORE_LIST = [
11
11
  'Dockerfile',
@@ -34,7 +34,7 @@ class KuberKit::Configs
34
34
  end
35
35
 
36
36
  def add_default_configs
37
- home_kuber_kit_path = File.expand_path(File.join("~", ".kuber_kit"))
37
+ home_kuber_kit_path = File.join("~", ".kuber_kit")
38
38
 
39
39
  set :image_dockerfile_name, "Dockerfile"
40
40
  set :image_build_context_dir, "build_context"
@@ -50,6 +50,7 @@ class KuberKit::Configs
50
50
  set :artifact_clone_dir, File.join(home_kuber_kit_path, "artifacts")
51
51
  set :service_config_dir, File.join(home_kuber_kit_path, "services")
52
52
  set :deployer_strategy, :kubernetes
53
+ set :shell_launcher_strategy, :kubernetes
53
54
  set :compile_simultaneous_limit, 5
54
55
  set :deploy_simultaneous_limit, 5
55
56
  set :additional_images_paths, []
@@ -57,6 +57,10 @@ class KuberKit::Container
57
57
  KuberKit::Actions::KubectlEnv.new
58
58
  end
59
59
 
60
+ register "actions.shell_launcher" do
61
+ KuberKit::Actions::ShellLauncher.new
62
+ end
63
+
60
64
  register "configs" do
61
65
  KuberKit::Configs.new
62
66
  end
@@ -293,18 +297,6 @@ class KuberKit::Container
293
297
  KuberKit::ServiceDeployer::ServiceDependencyResolver.new
294
298
  end
295
299
 
296
- register "service_deployer.strategies.kubernetes" do
297
- KuberKit::ServiceDeployer::Strategies::Kubernetes.new
298
- end
299
-
300
- register "service_deployer.strategies.docker" do
301
- KuberKit::ServiceDeployer::Strategies::Docker.new
302
- end
303
-
304
- register "service_deployer.strategies.docker_compose" do
305
- KuberKit::ServiceDeployer::Strategies::DockerCompose.new
306
- end
307
-
308
300
  register "service_reader.action_handler" do
309
301
  KuberKit::ServiceReader::ActionHandler.new
310
302
  end
@@ -313,6 +305,14 @@ class KuberKit::Container
313
305
  KuberKit::ServiceReader::Reader.new
314
306
  end
315
307
 
308
+ register "shell_launcher.action_handler" do
309
+ KuberKit::ShellLauncher::ActionHandler.new
310
+ end
311
+
312
+ register "shell_launcher.launcher" do
313
+ KuberKit::ShellLauncher::Launcher.new
314
+ end
315
+
316
316
  register "kubernetes.resource_selector" do
317
317
  KuberKit::Kubernetes::ResourceSelector.new
318
318
  end
@@ -2,7 +2,8 @@ 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
4
  :initial_services, :build_servers, :global_build_vars,
5
- :deployer_strategy, :deployer_namespace, :deployer_require_confirmation
5
+ :deployer_strategy, :deployer_namespace, :deployer_require_confirmation,
6
+ :shell_launcher_strategy
6
7
 
7
8
  Contract KeywordArgs[
8
9
  name: Symbol,
@@ -21,12 +22,13 @@ class KuberKit::Core::Configuration
21
22
  global_build_vars: HashOf[Symbol => Any],
22
23
  deployer_strategy: Symbol,
23
24
  deployer_namespace: Maybe[Or[Symbol, String]],
24
- deployer_require_confirmation: Bool,
25
+ deployer_require_confirmation: Bool,
26
+ shell_launcher_strategy: Symbol,
25
27
  ] => Any
26
28
  def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, kubectl_entrypoint:,
27
29
  services_attributes:, enabled_services:, disabled_services:, default_services:,
28
30
  initial_services:, build_servers:, global_build_vars:,
29
- deployer_strategy:, deployer_namespace:, deployer_require_confirmation:)
31
+ deployer_strategy:, deployer_namespace:, deployer_require_confirmation:, shell_launcher_strategy:)
30
32
  @name = name
31
33
  @artifacts = artifacts
32
34
  @registries = registries
@@ -43,7 +45,8 @@ class KuberKit::Core::Configuration
43
45
  @global_build_vars = global_build_vars
44
46
  @deployer_strategy = deployer_strategy
45
47
  @deployer_namespace = deployer_namespace
46
- @deployer_require_confirmation = deployer_require_confirmation
48
+ @deployer_require_confirmation = deployer_require_confirmation
49
+ @shell_launcher_strategy = shell_launcher_strategy
47
50
  end
48
51
 
49
52
  def service_attributes(service_name)
@@ -36,7 +36,8 @@ class KuberKit::Core::ConfigurationDefinition
36
36
  global_build_vars: @global_build_vars,
37
37
  deployer_strategy: @deployer_strategy,
38
38
  deployer_namespace: @deployer_namespace,
39
- deployer_require_confirmation: @deployer_require_confirmation || false,
39
+ deployer_require_confirmation: @deployer_require_confirmation || false,
40
+ shell_launcher_strategy: @shell_launcher_strategy,
40
41
  )
41
42
  end
42
43
 
@@ -102,8 +103,8 @@ class KuberKit::Core::ConfigurationDefinition
102
103
  self
103
104
  end
104
105
 
105
- def deployer_strategy(path)
106
- @deployer_strategy = path
106
+ def deployer_strategy(strategy)
107
+ @deployer_strategy = strategy
107
108
 
108
109
  self
109
110
  end
@@ -115,6 +116,12 @@ class KuberKit::Core::ConfigurationDefinition
115
116
  end
116
117
  alias_method :deployer_require_confirimation, :deployer_require_confirmation
117
118
 
119
+ def shell_launcher_strategy(strategy)
120
+ @shell_launcher_strategy = path
121
+
122
+ self
123
+ end
124
+
118
125
  def enabled_services(services)
119
126
  if services.is_a?(Hash)
120
127
  @enabled_services += services.keys.map(&:to_sym)
@@ -36,7 +36,8 @@ class KuberKit::Core::ConfigurationFactory
36
36
  global_build_vars: configuration_attrs.global_build_vars || {},
37
37
  deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
38
38
  deployer_namespace: configuration_attrs.deployer_namespace,
39
- deployer_require_confirmation: configuration_attrs.deployer_require_confirmation,
39
+ deployer_require_confirmation: configuration_attrs.deployer_require_confirmation,
40
+ shell_launcher_strategy: configuration_attrs.shell_launcher_strategy || configs.shell_launcher_strategy,
40
41
  )
41
42
  end
42
43
 
@@ -1,5 +1,5 @@
1
1
  class KuberKit::Core::Service
2
- AttributeNotSet = Class.new(Indocker::Error)
2
+ AttributeNotSet = Class.new(KuberKit::Error)
3
3
 
4
4
  attr_reader :name, :dependencies, :template_name, :tags, :images, :attributes, :deployer_strategy
5
5
 
@@ -7,26 +7,48 @@ class KuberKit::Defaults
7
7
  end
8
8
 
9
9
  def init!
10
- KuberKit::Container["artifacts_sync.artifact_updater"].use_resolver(
11
- KuberKit::Container["artifacts_sync.git_artifact_resolver"],
10
+ container["artifacts_sync.artifact_updater"].use_resolver(
11
+ container["artifacts_sync.git_artifact_resolver"],
12
12
  artifact_class: KuberKit::Core::Artifacts::Git
13
13
  )
14
- KuberKit::Container["artifacts_sync.artifact_updater"].use_resolver(
15
- KuberKit::Container["artifacts_sync.null_artifact_resolver"],
14
+ container["artifacts_sync.artifact_updater"].use_resolver(
15
+ container["artifacts_sync.null_artifact_resolver"],
16
16
  artifact_class: KuberKit::Core::Artifacts::Local
17
17
  )
18
- KuberKit::Container["env_file_reader.reader"].use_reader(
19
- KuberKit::Container["env_file_reader.strategies.artifact_file"],
18
+ container["env_file_reader.reader"].use_reader(
19
+ container["env_file_reader.strategies.artifact_file"],
20
20
  env_file_class: KuberKit::Core::EnvFiles::ArtifactFile
21
21
  )
22
- KuberKit::Container["env_file_reader.reader"].use_reader(
23
- KuberKit::Container["env_file_reader.strategies.env_group"],
22
+ container["env_file_reader.reader"].use_reader(
23
+ container["env_file_reader.strategies.env_group"],
24
24
  env_file_class: KuberKit::Core::EnvFiles::EnvGroup
25
25
  )
26
- KuberKit::Container["template_reader.reader"].use_reader(
27
- KuberKit::Container["template_reader.strategies.artifact_file"],
26
+ container["template_reader.reader"].use_reader(
27
+ container["template_reader.strategies.artifact_file"],
28
28
  template_class: KuberKit::Core::Templates::ArtifactFile
29
29
  )
30
+ container["service_deployer.deployer"].register_strategy(
31
+ :kubernetes,
32
+ KuberKit::ServiceDeployer::Strategies::Kubernetes.new
33
+ )
34
+ container["service_deployer.deployer"].register_strategy(
35
+ :docker,
36
+ KuberKit::ServiceDeployer::Strategies::Docker.new
37
+ )
38
+ container["service_deployer.deployer"].register_strategy(
39
+ :docker_compose,
40
+ KuberKit::ServiceDeployer::Strategies::DockerCompose.new
41
+ )
42
+
43
+ container["shell_launcher.launcher"].register_strategy(
44
+ :kubernetes,
45
+ KuberKit::ShellLauncher::Strategies::Kubernetes.new
46
+ )
30
47
  end
48
+
49
+ private
50
+ def container
51
+ KuberKit::Container
52
+ end
31
53
  end
32
54
  end
@@ -3,16 +3,8 @@ class KuberKit::ServiceDeployer::Deployer
3
3
 
4
4
  include KuberKit::Import[
5
5
  "core.service_store",
6
- "service_deployer.strategies.kubernetes",
7
- "service_deployer.strategies.docker",
8
- "service_deployer.strategies.docker_compose"
9
6
  ]
10
7
 
11
- def initialize(**injected_deps, &block)
12
- super(**injected_deps)
13
- add_default_strategies
14
- end
15
-
16
8
  def register_strategy(strategy_name, strategy)
17
9
  @@strategies ||= {}
18
10
 
@@ -31,15 +23,4 @@ class KuberKit::ServiceDeployer::Deployer
31
23
 
32
24
  deployer.deploy(shell, service)
33
25
  end
34
-
35
- def reset!
36
- @@strategies = {}
37
- end
38
-
39
- private
40
- def add_default_strategies
41
- register_strategy(:kubernetes, kubernetes)
42
- register_strategy(:docker, docker)
43
- register_strategy(:docker_compose, docker_compose)
44
- end
45
26
  end
@@ -10,6 +10,10 @@ class KuberKit::Shell::AbstractShell
10
10
  raise KuberKit::NotImplementedError, "must be implemented"
11
11
  end
12
12
 
13
+ def replace!(shell_name: nil, env: [])
14
+ raise KuberKit::NotImplementedError, "must be implemented"
15
+ end
16
+
13
17
  def read(file_path)
14
18
  raise KuberKit::NotImplementedError, "must be implemented"
15
19
  end
@@ -130,4 +130,10 @@ class KuberKit::Shell::Commands::KubectlCommands
130
130
 
131
131
  kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
132
132
  end
133
+
134
+ def set_namespace(shell, namespace, kubeconfig_path: nil)
135
+ command = %Q{config set-context --current --namespace=#{namespace}}
136
+
137
+ kubectl_run(shell, command, kubeconfig_path: kubeconfig_path)
138
+ end
133
139
  end
@@ -58,6 +58,17 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
58
58
  end
59
59
  end
60
60
 
61
+ def replace!(shell_name: nil, env: [], log_command: true)
62
+ shell_name ||= "$SHELL"
63
+ command = (env + [shell_name]).join(" ")
64
+
65
+ if log_command
66
+ ui.print_debug("LocalShell", "Replace Shell: #{command.to_s.cyan}")
67
+ end
68
+
69
+ system_exec(command)
70
+ end
71
+
61
72
  def sync(local_path, remote_path, exclude: nil, delete: true)
62
73
  rsync_commands.rsync(self, local_path, remote_path, exclude: exclude, delete: delete)
63
74
  end
@@ -117,6 +128,10 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
117
128
  end
118
129
 
119
130
  private
131
+ def system_exec(command)
132
+ exec(command)
133
+ end
134
+
120
135
  def ensure_directory_exists(file_path)
121
136
  dir_path = File.dirname(file_path)
122
137
 
@@ -42,6 +42,10 @@ class KuberKit::Shell::SshShell < KuberKit::Shell::LocalShell
42
42
  raise "Currently interactive run is not supported for ssh shell."
43
43
  end
44
44
 
45
+ def replace!(shell_name: nil, env: [])
46
+ raise "Currently repliace run is not supported for ssh shell."
47
+ end
48
+
45
49
  def sync(local_path, remote_path, exclude: nil, delete: true)
46
50
  rsync_commands.rsync(
47
51
  local_shell, local_path, remote_path,
@@ -0,0 +1,12 @@
1
+ class KuberKit::ShellLauncher::ActionHandler
2
+ include KuberKit::Import[
3
+ "shell_launcher.launcher",
4
+ ]
5
+
6
+ Contract KuberKit::Shell::AbstractShell => Any
7
+ def call(shell)
8
+ strategy_name = KuberKit.current_configuration.shell_launcher_strategy
9
+
10
+ launcher.call(shell, strategy_name)
11
+ end
12
+ end
@@ -0,0 +1,31 @@
1
+ class KuberKit::ShellLauncher::Launcher
2
+ StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
+
4
+ include KuberKit::Import[
5
+ "core.service_store",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
9
+ def call(shell, strategy_name)
10
+ launcher = get_strategy(strategy_name)
11
+
12
+ raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if launcher.nil?
13
+
14
+ launcher.call(shell)
15
+ end
16
+
17
+ def register_strategy(strategy_name, strategy)
18
+ @@strategies ||= {}
19
+
20
+ if !strategy.is_a?(KuberKit::ShellLauncher::Strategies::Abstract)
21
+ raise ArgumentError.new("should be an instance of KuberKit::ShellLauncher::Strategies::Abstract, got: #{strategy.inspect}")
22
+ end
23
+
24
+ @@strategies[strategy_name] = strategy
25
+ end
26
+
27
+ def get_strategy(strategy_name)
28
+ @@strategies ||= {}
29
+ @@strategies[strategy_name]
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ class KuberKit::ShellLauncher::Strategies::Abstract
2
+ def call(shell, service)
3
+ raise KuberKit::NotImplementedError, "must be implemented"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class KuberKit::ShellLauncher::Strategies::Kubernetes < KuberKit::ShellLauncher::Strategies::Abstract
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "shell.kubectl_commands",
5
+ "configs",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell => Any
9
+ def call(shell)
10
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
+ if kubeconfig_path.is_a?(KuberKit::Core::ArtifactPath)
12
+ kubeconfig_path = artifact_path_resolver.call(kubeconfig_path)
13
+ end
14
+
15
+ deployer_namespace = KuberKit.current_configuration.deployer_namespace
16
+ if deployer_namespace
17
+ kubectl_commands.set_namespace(shell, deployer_namespace, kubeconfig_path: kubeconfig_path)
18
+ end
19
+
20
+ shell.replace!(env: ["KUBECONFIG=#{kubeconfig_path}"])
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.8.8"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/kuber_kit.rb CHANGED
@@ -174,6 +174,16 @@ module KuberKit
174
174
  autoload :Reader, 'service_reader/reader'
175
175
  end
176
176
 
177
+ module ShellLauncher
178
+ autoload :ActionHandler, 'shell_launcher/action_handler'
179
+ autoload :Launcher, 'shell_launcher/launcher'
180
+
181
+ module Strategies
182
+ autoload :Abstract, 'shell_launcher/strategies/abstract'
183
+ autoload :Kubernetes, 'shell_launcher/strategies/kubernetes'
184
+ end
185
+ end
186
+
177
187
  module Actions
178
188
  autoload :ActionResult, 'actions/action_result'
179
189
  autoload :ImageCompiler, 'actions/image_compiler'
@@ -190,6 +200,7 @@ module KuberKit
190
200
  autoload :KubectlGet, 'actions/kubectl_get'
191
201
  autoload :KubectlLogs, 'actions/kubectl_logs'
192
202
  autoload :KubectlEnv, 'actions/kubectl_env'
203
+ autoload :ShellLauncher, 'actions/shell_launcher'
193
204
  end
194
205
 
195
206
  module Extensions