kuber_kit 0.8.7 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -3
- data/lib/kuber_kit/actions/kubectl_attacher.rb +5 -3
- data/lib/kuber_kit/actions/kubectl_console.rb +5 -3
- data/lib/kuber_kit/actions/shell_launcher.rb +18 -0
- data/lib/kuber_kit/cli.rb +11 -0
- data/lib/kuber_kit/configs.rb +9 -6
- data/lib/kuber_kit/container.rb +12 -12
- data/lib/kuber_kit/core/configuration.rb +11 -6
- data/lib/kuber_kit/core/configuration_definition.rb +17 -3
- data/lib/kuber_kit/core/configuration_factory.rb +3 -1
- data/lib/kuber_kit/core/service.rb +1 -1
- data/lib/kuber_kit/defaults.rb +32 -10
- data/lib/kuber_kit/service_deployer/deployer.rb +0 -19
- data/lib/kuber_kit/shell/abstract_shell.rb +8 -0
- data/lib/kuber_kit/shell/commands/bash_commands.rb +16 -6
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +11 -1
- data/lib/kuber_kit/shell/local_shell.rb +19 -0
- data/lib/kuber_kit/shell/ssh_shell.rb +8 -0
- data/lib/kuber_kit/shell_launcher/action_handler.rb +12 -0
- data/lib/kuber_kit/shell_launcher/launcher.rb +31 -0
- data/lib/kuber_kit/shell_launcher/strategies/abstract.rb +5 -0
- data/lib/kuber_kit/shell_launcher/strategies/kubernetes.rb +22 -0
- data/lib/kuber_kit/version.rb +1 -1
- data/lib/kuber_kit.rb +11 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74747b7166c91e6a78919e9888e8a643a0b199d4e3457015d902e7d12be0df1f
|
4
|
+
data.tar.gz: e292c750666b58996116cd1eb01a43f9472120346235eeec2cd3d7434770b381
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c06ee817240523fa6faec061d223337ed08d683a0ba15c671f4d65f1cdb1e3e8ce088ffb130f48d2c37a030f9200fde54b69ea6f6a542621266cb59ad6b7aa80
|
7
|
+
data.tar.gz: 989df85f77d4c8676def49566c8277172b8498f19798ce273704e3cd818176bd8fce4efe5bf208db88441d2d1ab38257c7d45ad6cc5895a95b9de10056eb9ff8
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
**0.
|
2
|
-
-
|
1
|
+
**0.9.0-0.9.1**
|
2
|
+
- Allow skipping confirmation during deployment
|
3
|
+
- Added `kit sh` command to create a new shell
|
4
|
+
- Do not expand image compile directory path in default 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
|
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:
|
22
|
-
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
|
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:
|
22
|
-
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)
|
data/lib/kuber_kit/configs.rb
CHANGED
@@ -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,11 +34,13 @@ class KuberKit::Configs
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def add_default_configs
|
37
|
-
home_kuber_kit_path = File.
|
37
|
+
home_kuber_kit_path = File.join("~", ".kuber_kit")
|
38
|
+
absolute_kuber_kit_path = File.expand_path(home_kuber_kit_path)
|
38
39
|
|
39
40
|
set :image_dockerfile_name, "Dockerfile"
|
40
41
|
set :image_build_context_dir, "build_context"
|
41
42
|
set :image_tag, 'latest'
|
43
|
+
# do not use absolute path for compile dir, compilation could be done on remote server
|
42
44
|
set :image_compile_dir, File.join(home_kuber_kit_path, "image_builds")
|
43
45
|
set :docker_ignore_list, DOCKER_IGNORE_LIST
|
44
46
|
set :kuber_kit_dirname, "kuber_kit"
|
@@ -47,15 +49,16 @@ class KuberKit::Configs
|
|
47
49
|
set :services_dirname, "services"
|
48
50
|
set :infra_dirname, "infrastructure"
|
49
51
|
set :configurations_dirname, "configurations"
|
50
|
-
set :artifact_clone_dir, File.join(
|
51
|
-
set :service_config_dir, File.join(
|
52
|
+
set :artifact_clone_dir, File.join(absolute_kuber_kit_path, "artifacts")
|
53
|
+
set :service_config_dir, File.join(absolute_kuber_kit_path, "services")
|
52
54
|
set :deployer_strategy, :kubernetes
|
55
|
+
set :shell_launcher_strategy, :kubernetes
|
53
56
|
set :compile_simultaneous_limit, 5
|
54
57
|
set :deploy_simultaneous_limit, 5
|
55
58
|
set :additional_images_paths, []
|
56
59
|
set :deprecation_warnings_disabled, false
|
57
|
-
set :log_file_path, File.join(
|
58
|
-
set :env_file_compile_dir, File.join(
|
60
|
+
set :log_file_path, File.join(absolute_kuber_kit_path, "deploy.log")
|
61
|
+
set :env_file_compile_dir, File.join(absolute_kuber_kit_path, "env_files")
|
59
62
|
end
|
60
63
|
|
61
64
|
def items
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -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:
|
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
|
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:
|
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(
|
99
|
-
@deployer_strategy =
|
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:
|
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
|
|
data/lib/kuber_kit/defaults.rb
CHANGED
@@ -7,26 +7,48 @@ class KuberKit::Defaults
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def init!
|
10
|
-
|
11
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
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
|
@@ -25,4 +29,8 @@ class KuberKit::Shell::AbstractShell
|
|
25
29
|
def sync(local_path, remote_path, exclude: nil)
|
26
30
|
raise KuberKit::NotImplementedError, "must be implemented"
|
27
31
|
end
|
32
|
+
|
33
|
+
def expand_path(relative_path)
|
34
|
+
raise KuberKit::NotImplementedError, "must be implemented"
|
35
|
+
end
|
28
36
|
end
|
@@ -1,25 +1,35 @@
|
|
1
1
|
class KuberKit::Shell::Commands::BashCommands
|
2
2
|
def rm(shell, path)
|
3
|
-
shell.
|
3
|
+
absolute_path = shell.expand_path(path)
|
4
|
+
shell.exec!(%Q{rm "#{absolute_path}"})
|
4
5
|
end
|
5
6
|
|
6
7
|
def rm_rf(shell, path)
|
7
|
-
shell.
|
8
|
+
absolute_path = shell.expand_path(path)
|
9
|
+
shell.exec!(%Q{rm -rf "#{absolute_path}"})
|
8
10
|
end
|
9
11
|
|
10
12
|
def cp(shell, source_path, dest_path)
|
11
|
-
shell.
|
13
|
+
abs_source_path = shell.expand_path(source_path)
|
14
|
+
abs_dest_path = shell.expand_path(dest_path)
|
15
|
+
|
16
|
+
shell.exec!(%Q{cp "#{abs_source_path}" "#{abs_dest_path}"})
|
12
17
|
end
|
13
18
|
|
14
19
|
def cp_r(shell, source_path, dest_path)
|
15
|
-
shell.
|
20
|
+
abs_source_path = shell.expand_path(source_path)
|
21
|
+
abs_dest_path = shell.expand_path(dest_path)
|
22
|
+
|
23
|
+
shell.exec!(%Q{cp -r "#{abs_source_path}" "#{abs_dest_path}"})
|
16
24
|
end
|
17
25
|
|
18
26
|
def mkdir(shell, path)
|
19
|
-
shell.
|
27
|
+
absolute_path = shell.expand_path(path)
|
28
|
+
shell.exec!(%Q{mkdir "#{absolute_path}"})
|
20
29
|
end
|
21
30
|
|
22
31
|
def mkdir_p(shell, path)
|
23
|
-
shell.
|
32
|
+
absolute_path = shell.expand_path(path)
|
33
|
+
shell.exec!(%Q{mkdir -p "#{absolute_path}"})
|
24
34
|
end
|
25
35
|
end
|
@@ -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
|
@@ -116,7 +127,15 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
116
127
|
"KIT=#{Process.pid} #{command}"
|
117
128
|
end
|
118
129
|
|
130
|
+
def expand_path(relative_path)
|
131
|
+
File.expand_path(relative_path)
|
132
|
+
end
|
133
|
+
|
119
134
|
private
|
135
|
+
def system_exec(command)
|
136
|
+
exec(command)
|
137
|
+
end
|
138
|
+
|
120
139
|
def ensure_directory_exists(file_path)
|
121
140
|
dir_path = File.dirname(file_path)
|
122
141
|
|
@@ -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,
|
@@ -67,6 +71,10 @@ class KuberKit::Shell::SshShell < KuberKit::Shell::LocalShell
|
|
67
71
|
true
|
68
72
|
end
|
69
73
|
|
74
|
+
def expand_path(relative_path)
|
75
|
+
exec!("readlink -f #{relative_path}")
|
76
|
+
end
|
77
|
+
|
70
78
|
private
|
71
79
|
def ssh_session
|
72
80
|
unless connected?
|
@@ -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,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
|
data/lib/kuber_kit/version.rb
CHANGED
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
|
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: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- lib/kuber_kit/actions/service_checker.rb
|
248
248
|
- lib/kuber_kit/actions/service_deployer.rb
|
249
249
|
- lib/kuber_kit/actions/service_reader.rb
|
250
|
+
- lib/kuber_kit/actions/shell_launcher.rb
|
250
251
|
- lib/kuber_kit/actions/template_reader.rb
|
251
252
|
- lib/kuber_kit/artifacts_sync/abstract_artifact_resolver.rb
|
252
253
|
- lib/kuber_kit/artifacts_sync/artifact_updater.rb
|
@@ -344,6 +345,10 @@ files:
|
|
344
345
|
- lib/kuber_kit/shell/local_shell.rb
|
345
346
|
- lib/kuber_kit/shell/ssh_session.rb
|
346
347
|
- lib/kuber_kit/shell/ssh_shell.rb
|
348
|
+
- lib/kuber_kit/shell_launcher/action_handler.rb
|
349
|
+
- lib/kuber_kit/shell_launcher/launcher.rb
|
350
|
+
- lib/kuber_kit/shell_launcher/strategies/abstract.rb
|
351
|
+
- lib/kuber_kit/shell_launcher/strategies/kubernetes.rb
|
347
352
|
- lib/kuber_kit/template_reader/action_handler.rb
|
348
353
|
- lib/kuber_kit/template_reader/reader.rb
|
349
354
|
- lib/kuber_kit/template_reader/strategies/abstract.rb
|