kuber_kit 0.8.6 → 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: 861dcc68aede1a1383503407122ddcd8ff87a318609499d054da82622a5b04b4
4
- data.tar.gz: a3dac127827d387865a9efa50c0cf622b4c75f2b56d4fa77d8bab22ae32c262c
3
+ metadata.gz: 6eb3dda64697fc3174d3ae031a7eba5be1f57e80d0c8c43829ff3b36edca38b2
4
+ data.tar.gz: 85a77edc9bdc91c09c6ba6f3e677df032168c66a69a563ddd9087734fa9636bc
5
5
  SHA512:
6
- metadata.gz: 2ef883008c62f3eb0f3660a124513f1051e1c0ca555d53bc0d0eae4ac0aadeee6ad07076d96e4c9fd19fac83755d31f11dc67e44b363e2243a67631bc0448f67
7
- data.tar.gz: d41a9dbab50e8fbd59f639c03cdb1e6263cabef6f6503dddb526639499d6b875c226a12eed7e4903fcba91a334c941b35c00427591a27f5adbd1c157df7dce50
6
+ metadata.gz: 1696812c543f40ec81cb7c4c7804f4f02e739cf7ccff6820f37b884f7965a0822ceb1b2dbc42e7ca9d696f7d539d5b0e44ff6142991178bd9316bdd98276ca09
7
+ data.tar.gz: 8887273eba2ca2b3f714249d4da29dfb826477e08da4f09d06ab9974c5a32e8b698bbeb2f9b0bb7a6cbd75884aba3bedca6adc71ee7d7e53a1a8d3637b798d7f
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
- **0.8.5**
2
- - Properly show initial services in deployment confirmation
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
3
5
 
4
- **0.8.4**
6
+ **0.8.4-0.8.8**
5
7
  - Added initial services support, to deploy before all other servies
8
+ - Allow namespace as symbol in kubectl commands
9
+ - Allow setting kubectl entrypoint for configuration
6
10
 
7
11
  **0.8.3**
8
12
  - Always load artifacts, if kubeconfig is an artifact
@@ -8,7 +8,8 @@ class KuberKit::Actions::KubectlAttacher
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
10
  def call(pod_name, options)
11
- kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
+ kubectl_entrypoint = KuberKit.current_configuration.kubectl_entrypoint
12
13
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
13
14
 
14
15
  if !pod_name
@@ -18,8 +19,9 @@ class KuberKit::Actions::KubectlAttacher
18
19
  kubectl_commands.exec(
19
20
  local_shell, pod_name, "bash", args: "-it",
20
21
  kubeconfig_path: kubeconfig_path,
21
- interactive: true,
22
- namespace: deployer_namespace
22
+ interactive: true,
23
+ namespace: deployer_namespace,
24
+ entrypoint: kubectl_entrypoint
23
25
  )
24
26
 
25
27
  true
@@ -8,7 +8,8 @@ class KuberKit::Actions::KubectlConsole
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
10
  def call(pod_name, options)
11
- kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
+ kubectl_entrypoint = KuberKit.current_configuration.kubectl_entrypoint
12
13
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
13
14
 
14
15
  if !pod_name
@@ -18,8 +19,9 @@ class KuberKit::Actions::KubectlConsole
18
19
  kubectl_commands.exec(
19
20
  local_shell, pod_name, "bin/console", args: "-it",
20
21
  kubeconfig_path: kubeconfig_path,
21
- interactive: true,
22
- namespace: deployer_namespace
22
+ interactive: true,
23
+ namespace: deployer_namespace,
24
+ entrypoint: kubectl_entrypoint
23
25
  )
24
26
 
25
27
  true
@@ -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
@@ -1,8 +1,9 @@
1
1
  class KuberKit::Core::Configuration
2
- attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
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,
@@ -11,6 +12,7 @@ class KuberKit::Core::Configuration
11
12
  env_files: Hash,
12
13
  templates: Hash,
13
14
  kubeconfig_path: Maybe[Or[String, KuberKit::Core::ArtifactPath]],
15
+ kubectl_entrypoint: Maybe[String],
14
16
  services_attributes: HashOf[Symbol => Hash],
15
17
  enabled_services: ArrayOf[Symbol],
16
18
  disabled_services: ArrayOf[Symbol],
@@ -20,18 +22,20 @@ class KuberKit::Core::Configuration
20
22
  global_build_vars: HashOf[Symbol => Any],
21
23
  deployer_strategy: Symbol,
22
24
  deployer_namespace: Maybe[Or[Symbol, String]],
23
- deployer_require_confirmation: Bool,
25
+ deployer_require_confirmation: Bool,
26
+ shell_launcher_strategy: Symbol,
24
27
  ] => Any
25
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
28
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, kubectl_entrypoint:,
26
29
  services_attributes:, enabled_services:, disabled_services:, default_services:,
27
30
  initial_services:, build_servers:, global_build_vars:,
28
- deployer_strategy:, deployer_namespace:, deployer_require_confirmation:)
31
+ deployer_strategy:, deployer_namespace:, deployer_require_confirmation:, shell_launcher_strategy:)
29
32
  @name = name
30
33
  @artifacts = artifacts
31
34
  @registries = registries
32
35
  @env_files = env_files
33
36
  @templates = templates
34
37
  @kubeconfig_path = kubeconfig_path
38
+ @kubectl_entrypoint = kubectl_entrypoint
35
39
  @build_servers = build_servers
36
40
  @services_attributes = services_attributes
37
41
  @enabled_services = enabled_services
@@ -41,7 +45,8 @@ class KuberKit::Core::Configuration
41
45
  @global_build_vars = global_build_vars
42
46
  @deployer_strategy = deployer_strategy
43
47
  @deployer_namespace = deployer_namespace
44
- @deployer_require_confirmation = deployer_require_confirmation
48
+ @deployer_require_confirmation = deployer_require_confirmation
49
+ @shell_launcher_strategy = shell_launcher_strategy
45
50
  end
46
51
 
47
52
  def service_attributes(service_name)
@@ -26,6 +26,7 @@ class KuberKit::Core::ConfigurationDefinition
26
26
  env_files: @env_files,
27
27
  templates: @templates,
28
28
  kubeconfig_path: @kubeconfig_path,
29
+ kubectl_entrypoint: @kubectl_entrypoint,
29
30
  enabled_services: @enabled_services,
30
31
  disabled_services: @disabled_services,
31
32
  default_services: @default_services,
@@ -35,7 +36,8 @@ class KuberKit::Core::ConfigurationDefinition
35
36
  global_build_vars: @global_build_vars,
36
37
  deployer_strategy: @deployer_strategy,
37
38
  deployer_namespace: @deployer_namespace,
38
- deployer_require_confirmation: @deployer_require_confirmation || false,
39
+ deployer_require_confirmation: @deployer_require_confirmation || false,
40
+ shell_launcher_strategy: @shell_launcher_strategy,
39
41
  )
40
42
  end
41
43
 
@@ -89,14 +91,20 @@ class KuberKit::Core::ConfigurationDefinition
89
91
  self
90
92
  end
91
93
 
94
+ def kubectl_entrypoint(path)
95
+ @kubectl_entrypoint = path
96
+
97
+ self
98
+ end
99
+
92
100
  def deployer_namespace(namespace)
93
101
  @deployer_namespace = namespace
94
102
 
95
103
  self
96
104
  end
97
105
 
98
- def deployer_strategy(path)
99
- @deployer_strategy = path
106
+ def deployer_strategy(strategy)
107
+ @deployer_strategy = strategy
100
108
 
101
109
  self
102
110
  end
@@ -108,6 +116,12 @@ class KuberKit::Core::ConfigurationDefinition
108
116
  end
109
117
  alias_method :deployer_require_confirimation, :deployer_require_confirmation
110
118
 
119
+ def shell_launcher_strategy(strategy)
120
+ @shell_launcher_strategy = path
121
+
122
+ self
123
+ end
124
+
111
125
  def enabled_services(services)
112
126
  if services.is_a?(Hash)
113
127
  @enabled_services += services.keys.map(&:to_sym)
@@ -26,6 +26,7 @@ class KuberKit::Core::ConfigurationFactory
26
26
  env_files: env_files,
27
27
  templates: templates,
28
28
  kubeconfig_path: configuration_attrs.kubeconfig_path,
29
+ kubectl_entrypoint: configuration_attrs.kubectl_entrypoint,
29
30
  build_servers: build_servers,
30
31
  services_attributes: configuration_attrs.services_attributes,
31
32
  enabled_services: configuration_attrs.enabled_services,
@@ -35,7 +36,8 @@ class KuberKit::Core::ConfigurationFactory
35
36
  global_build_vars: configuration_attrs.global_build_vars || {},
36
37
  deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
37
38
  deployer_namespace: configuration_attrs.deployer_namespace,
38
- 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,
39
41
  )
40
42
  end
41
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
@@ -10,7 +10,7 @@ class KuberKit::Shell::Commands::KubectlCommands
10
10
  kubeconfig_path: Maybe[Or[
11
11
  String, KuberKit::Core::ArtifactPath
12
12
  ]],
13
- namespace: Maybe[String],
13
+ namespace: Maybe[Or[Symbol, String]],
14
14
  interactive: Optional[Bool],
15
15
  ] => Any
16
16
  def kubectl_run(shell, command_list, kubeconfig_path: nil, namespace: nil, interactive: false)
@@ -43,13 +43,17 @@ class KuberKit::Shell::Commands::KubectlCommands
43
43
  kubectl_run(shell, "apply -f #{file_path}", kubeconfig_path: kubeconfig_path, namespace: namespace)
44
44
  end
45
45
 
46
- def exec(shell, pod_name, command, args: nil, kubeconfig_path: nil, interactive: false, namespace: nil)
46
+ def exec(shell, pod_name, command, args: nil, kubeconfig_path: nil, interactive: false, namespace: nil, entrypoint: nil)
47
47
  command_parts = []
48
48
  command_parts << "exec"
49
49
 
50
50
  if args
51
51
  command_parts << args
52
52
  end
53
+
54
+ if entrypoint
55
+ command = entrypoint.gsub("$@", command)
56
+ end
53
57
 
54
58
  command_parts << pod_name
55
59
  command_parts << "-- #{command}"
@@ -126,4 +130,10 @@ class KuberKit::Shell::Commands::KubectlCommands
126
130
 
127
131
  kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
128
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
129
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.6"
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