kuber_kit 0.4.8 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +2 -2
- data/TODO.md +5 -5
- data/example/configurations/review.rb +1 -1
- data/example/services/ruby_app.rb +1 -0
- data/lib/kuber_kit.rb +9 -0
- data/lib/kuber_kit/actions/kubectl_attacher.rb +2 -2
- data/lib/kuber_kit/actions/kubectl_console.rb +2 -2
- data/lib/kuber_kit/actions/kubectl_describe.rb +2 -2
- data/lib/kuber_kit/actions/kubectl_env.rb +19 -0
- data/lib/kuber_kit/actions/kubectl_get.rb +30 -0
- data/lib/kuber_kit/actions/kubectl_logs.rb +2 -2
- data/lib/kuber_kit/actions/service_checker.rb +32 -0
- data/lib/kuber_kit/actions/service_deployer.rb +75 -59
- data/lib/kuber_kit/cli.rb +28 -1
- data/lib/kuber_kit/configs.rb +2 -1
- data/lib/kuber_kit/container.rb +20 -0
- data/lib/kuber_kit/core/dependencies/abstract_dependency_resolver.rb +75 -0
- data/lib/kuber_kit/core/image.rb +2 -1
- data/lib/kuber_kit/core/service.rb +4 -2
- data/lib/kuber_kit/core/service_definition.rb +13 -6
- data/lib/kuber_kit/core/service_factory.rb +1 -0
- data/lib/kuber_kit/image_compiler/image_dependency_resolver.rb +5 -53
- data/lib/kuber_kit/kubernetes/resource_selector.rb +33 -0
- data/lib/kuber_kit/kubernetes/resources_fetcher.rb +7 -30
- data/lib/kuber_kit/service_deployer/service_dependency_resolver.rb +14 -0
- data/lib/kuber_kit/service_deployer/service_list_resolver.rb +2 -2
- data/lib/kuber_kit/service_deployer/strategies/docker.rb +18 -1
- data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +9 -2
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +12 -4
- data/lib/kuber_kit/shell/local_shell.rb +15 -1
- data/lib/kuber_kit/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9573dca431e801716912c8dd4a51ea9d5e948d99e91c53e64385b317bc22dbe9
|
4
|
+
data.tar.gz: 7d162cc2036567c55ec9258d86dacb90354bc55c0914ed2c782d5aa0304ec50f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76846e6ac4744e9267c1a6f34571edd43c63fb17398014c2916f9bba558f4e026e6663e515f3dfaef758acc0ed3b7915662920a696fa03b2f962f217befdf37d
|
7
|
+
data.tar.gz: b348f513b6dc6448966b67c89babfb625387c0f1b272338cf0064db5c76ea6d8e036430a556cd2cace548198495f026ca13b6c29d7f1d20462ab0fd8b0f5cfbb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
**0.5.3**
|
2
|
+
- Change the symbol to exclude service from "-" to "!", you can pass "-s !auth_app" to exclude "auth_app"
|
3
|
+
- Added kit get command to find pods
|
4
|
+
|
5
|
+
**0.5.2**
|
6
|
+
- Added dependencies support to services
|
7
|
+
- Added an option to deploy all services in `kit deloy`
|
8
|
+
- Wait for rollout to finish during service deploy
|
9
|
+
- Deploy services in batches, not all of the simultaneously
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kuber_kit (0.
|
4
|
+
kuber_kit (0.5.3)
|
5
5
|
cli-ui
|
6
6
|
contracts-lite
|
7
7
|
dry-auto_inject
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
docile (1.3.2)
|
21
21
|
dry-auto_inject (0.7.0)
|
22
22
|
dry-container (>= 0.3.4)
|
23
|
-
dry-configurable (0.12.
|
23
|
+
dry-configurable (0.12.1)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
dry-core (~> 0.5, >= 0.5.0)
|
26
26
|
dry-container (0.7.2)
|
data/TODO.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
-
|
2
|
-
-
|
3
|
-
-
|
4
|
-
- find a way to always deploy some service, e.g. for migrations and env_files
|
1
|
+
- add kit get method for more interactive kubernetes
|
2
|
+
- env files should use a separate deployment method (with change detection)
|
3
|
+
- add automatical confirmation support for service deployer
|
5
4
|
- template should be able to set default attributes
|
6
5
|
- template should be able to depend on image?
|
7
6
|
- cleanup image builds older than some date
|
8
|
-
- add some rotation for deploy log
|
7
|
+
- add some rotation for deploy log
|
8
|
+
- kit status should show the list of services and their status, with ability to select & view logs
|
data/lib/kuber_kit.rb
CHANGED
@@ -46,6 +46,10 @@ module KuberKit
|
|
46
46
|
autoload :BuildServer, 'core/build_servers/build_server'
|
47
47
|
end
|
48
48
|
|
49
|
+
module Dependencies
|
50
|
+
autoload :AbstractDependencyResolver, 'core/dependencies/abstract_dependency_resolver'
|
51
|
+
end
|
52
|
+
|
49
53
|
module EnvFiles
|
50
54
|
autoload :EnvFileStore, 'core/env_files/env_file_store'
|
51
55
|
autoload :AbstractEnvFile, 'core/env_files/abstract_env_file'
|
@@ -145,6 +149,7 @@ module KuberKit
|
|
145
149
|
autoload :StrategyDetector, 'service_deployer/strategy_detector'
|
146
150
|
autoload :Deployer, 'service_deployer/deployer'
|
147
151
|
autoload :ServiceListResolver, 'service_deployer/service_list_resolver'
|
152
|
+
autoload :ServiceDependencyResolver, 'service_deployer/service_dependency_resolver'
|
148
153
|
|
149
154
|
module Strategies
|
150
155
|
autoload :Abstract, 'service_deployer/strategies/abstract'
|
@@ -165,12 +170,15 @@ module KuberKit
|
|
165
170
|
autoload :TemplateReader, 'actions/template_reader'
|
166
171
|
autoload :ServiceReader, 'actions/service_reader'
|
167
172
|
autoload :ServiceDeployer, 'actions/service_deployer'
|
173
|
+
autoload :ServiceChecker, 'actions/service_checker'
|
168
174
|
autoload :ConfigurationLoader, 'actions/configuration_loader'
|
169
175
|
autoload :KubectlApplier, 'actions/kubectl_applier'
|
170
176
|
autoload :KubectlAttacher, 'actions/kubectl_attacher'
|
171
177
|
autoload :KubectlConsole, 'actions/kubectl_console'
|
172
178
|
autoload :KubectlDescribe, 'actions/kubectl_describe'
|
179
|
+
autoload :KubectlGet, 'actions/kubectl_get'
|
173
180
|
autoload :KubectlLogs, 'actions/kubectl_logs'
|
181
|
+
autoload :KubectlEnv, 'actions/kubectl_env'
|
174
182
|
end
|
175
183
|
|
176
184
|
module Extensions
|
@@ -178,6 +186,7 @@ module KuberKit
|
|
178
186
|
end
|
179
187
|
|
180
188
|
module Kubernetes
|
189
|
+
autoload :ResourceSelector, 'kubernetes/resource_selector'
|
181
190
|
autoload :ResourcesFetcher, 'kubernetes/resources_fetcher'
|
182
191
|
end
|
183
192
|
|
@@ -2,7 +2,7 @@ class KuberKit::Actions::KubectlAttacher
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"kubernetes.
|
5
|
+
"kubernetes.resource_selector",
|
6
6
|
"ui"
|
7
7
|
]
|
8
8
|
|
@@ -12,7 +12,7 @@ class KuberKit::Actions::KubectlAttacher
|
|
12
12
|
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
13
|
|
14
14
|
if !pod_name
|
15
|
-
pod_name =
|
15
|
+
pod_name = resource_selector.call("attach")
|
16
16
|
end
|
17
17
|
|
18
18
|
kubectl_commands.exec(
|
@@ -2,7 +2,7 @@ class KuberKit::Actions::KubectlConsole
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"kubernetes.
|
5
|
+
"kubernetes.resource_selector",
|
6
6
|
"ui"
|
7
7
|
]
|
8
8
|
|
@@ -12,7 +12,7 @@ class KuberKit::Actions::KubectlConsole
|
|
12
12
|
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
13
|
|
14
14
|
if !pod_name
|
15
|
-
pod_name =
|
15
|
+
pod_name = resource_selector.call("attach")
|
16
16
|
end
|
17
17
|
|
18
18
|
kubectl_commands.exec(
|
@@ -2,7 +2,7 @@ class KuberKit::Actions::KubectlDescribe
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"kubernetes.
|
5
|
+
"kubernetes.resource_selector",
|
6
6
|
"ui"
|
7
7
|
]
|
8
8
|
|
@@ -12,7 +12,7 @@ class KuberKit::Actions::KubectlDescribe
|
|
12
12
|
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
13
|
|
14
14
|
if !resource_name
|
15
|
-
resource_name =
|
15
|
+
resource_name = resource_selector.call("describe", include_ingresses: true, include_pods: true)
|
16
16
|
end
|
17
17
|
|
18
18
|
args = nil
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class KuberKit::Actions::KubectlEnv
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.local_shell",
|
4
|
+
"ui"
|
5
|
+
]
|
6
|
+
|
7
|
+
Contract Hash => Any
|
8
|
+
def call(options)
|
9
|
+
configuration = KuberKit.current_configuration
|
10
|
+
kubeconfig_path = configuration.kubeconfig_path
|
11
|
+
ui.print_info("ENV", "export KUBECONFIG=#{kubeconfig_path}")
|
12
|
+
|
13
|
+
true
|
14
|
+
rescue KuberKit::Error => e
|
15
|
+
ui.print_error("Error", e.message)
|
16
|
+
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class KuberKit::Actions::KubectlGet
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.kubectl_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
"kubernetes.resource_selector",
|
6
|
+
"ui"
|
7
|
+
]
|
8
|
+
|
9
|
+
Contract Maybe[String], Hash => Any
|
10
|
+
def call(resource_name, options)
|
11
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
12
|
+
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
|
+
|
14
|
+
resources = kubectl_commands.get_resources(
|
15
|
+
local_shell, "pod",
|
16
|
+
kubeconfig_path: kubeconfig_path,
|
17
|
+
namespace: deployer_namespace
|
18
|
+
)
|
19
|
+
|
20
|
+
matching_resources = resources.select{|r| r.include?(resource_name) }
|
21
|
+
|
22
|
+
ui.print_info("Pods", matching_resources.join("\n"))
|
23
|
+
|
24
|
+
true
|
25
|
+
rescue KuberKit::Error => e
|
26
|
+
ui.print_error("Error", e.message)
|
27
|
+
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
@@ -2,7 +2,7 @@ class KuberKit::Actions::KubectlLogs
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"kubernetes.
|
5
|
+
"kubernetes.resource_selector",
|
6
6
|
"ui"
|
7
7
|
]
|
8
8
|
|
@@ -12,7 +12,7 @@ class KuberKit::Actions::KubectlLogs
|
|
12
12
|
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
13
|
|
14
14
|
if !pod_name
|
15
|
-
pod_name =
|
15
|
+
pod_name = resource_selector.call("attach")
|
16
16
|
end
|
17
17
|
|
18
18
|
args = nil
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Actions::ServiceChecker
|
2
|
+
include KuberKit::Import[
|
3
|
+
"kubernetes.resources_fetcher",
|
4
|
+
"shell.local_shell",
|
5
|
+
"core.service_store",
|
6
|
+
"ui",
|
7
|
+
]
|
8
|
+
|
9
|
+
Contract Hash => Any
|
10
|
+
def call(options)
|
11
|
+
services = service_store.all_definitions.values.map(&:service_name).map(&:to_s)
|
12
|
+
|
13
|
+
enabled_services = KuberKit.current_configuration.enabled_services.map(&:to_s)
|
14
|
+
if enabled_services.any?
|
15
|
+
services = services.select{ |s| enabled_services.include?(s) }
|
16
|
+
end
|
17
|
+
|
18
|
+
resources = resources_fetcher.call("deployments") + resources_fetcher.call("cronjobs")
|
19
|
+
|
20
|
+
missing_services = services.select{ |s| !resources.include?(s.gsub("_", "-")) }
|
21
|
+
|
22
|
+
ui.print_warning("Warning", "This command will only check services deployed using k8s")
|
23
|
+
|
24
|
+
ui.print_info("Missing", missing_services.inspect)
|
25
|
+
|
26
|
+
{}
|
27
|
+
rescue KuberKit::Error => e
|
28
|
+
ui.print_error("Error", e.message)
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
@@ -2,9 +2,11 @@ class KuberKit::Actions::ServiceDeployer
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"actions.image_compiler",
|
4
4
|
"service_deployer.service_list_resolver",
|
5
|
+
"service_deployer.service_dependency_resolver",
|
5
6
|
"core.service_store",
|
6
7
|
"shell.local_shell",
|
7
8
|
"tools.process_cleaner",
|
9
|
+
"configs",
|
8
10
|
"ui",
|
9
11
|
service_deployer: "service_deployer.action_handler",
|
10
12
|
]
|
@@ -24,14 +26,17 @@ class KuberKit::Actions::ServiceDeployer
|
|
24
26
|
services: services || [],
|
25
27
|
tags: tags || [],
|
26
28
|
enabled_services: KuberKit.current_configuration.enabled_services.map(&:to_s)
|
27
|
-
)
|
29
|
+
).map(&:to_sym)
|
28
30
|
|
29
|
-
|
31
|
+
# Return the list of services with all dependencies.
|
32
|
+
all_service_names = service_dependency_resolver.get_all(service_names)
|
33
|
+
|
34
|
+
unless all_service_names.any?
|
30
35
|
ui.print_warning "ServiceDeployer", "No service found with given options, nothing will be deployed."
|
31
36
|
return false
|
32
37
|
end
|
33
38
|
|
34
|
-
services_list =
|
39
|
+
services_list = all_service_names.map(&:to_s).map(&:yellow).join(", ")
|
35
40
|
ui.print_info "ServiceDeployer", "The following services will be deployed: #{services_list}"
|
36
41
|
|
37
42
|
if require_confirmation
|
@@ -39,7 +44,7 @@ class KuberKit::Actions::ServiceDeployer
|
|
39
44
|
return false unless ["confirm".green, "confirm", "yes"].include?(result)
|
40
45
|
end
|
41
46
|
|
42
|
-
services =
|
47
|
+
services = all_service_names.map do |service_name|
|
43
48
|
service_store.get_service(service_name.to_sym)
|
44
49
|
end
|
45
50
|
|
@@ -50,9 +55,16 @@ class KuberKit::Actions::ServiceDeployer
|
|
50
55
|
return false unless compile_result
|
51
56
|
end
|
52
57
|
|
53
|
-
|
58
|
+
deployed_services = []
|
59
|
+
deployment_result = {}
|
60
|
+
service_dependency_resolver.each_with_deps(service_names) do |dep_service_names|
|
61
|
+
ui.print_debug("ServiceDeployer", "Scheduling to compile: #{dep_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
|
62
|
+
result = deploy_simultaneously(dep_service_names)
|
63
|
+
deployed_services += dep_service_names
|
64
|
+
deployment_result = deployment_result.merge(result)
|
65
|
+
end
|
54
66
|
|
55
|
-
{ services:
|
67
|
+
{ services: all_service_names, deployment: deployment_result }
|
56
68
|
rescue KuberKit::Error => e
|
57
69
|
ui.print_error("Error", e.message)
|
58
70
|
|
@@ -61,69 +73,73 @@ class KuberKit::Actions::ServiceDeployer
|
|
61
73
|
process_cleaner.clean
|
62
74
|
end
|
63
75
|
|
64
|
-
|
65
|
-
|
76
|
+
private
|
77
|
+
def deploy_simultaneously(service_names)
|
78
|
+
task_group = ui.create_task_group
|
66
79
|
|
67
|
-
|
80
|
+
deployer_result = {}
|
68
81
|
|
69
|
-
|
82
|
+
service_names.each do |service_name|
|
70
83
|
|
71
|
-
|
72
|
-
|
73
|
-
|
84
|
+
ui.print_debug("ServiceDeployer", "Started deploying: #{service_name.to_s.green}")
|
85
|
+
task_group.add("Deploying #{service_name.to_s.yellow}") do |task|
|
86
|
+
deployer_result[service_name] = service_deployer.call(local_shell, service_name.to_sym)
|
74
87
|
|
75
|
-
|
76
|
-
|
88
|
+
task.update_title("Deployed #{service_name.to_s.green}")
|
89
|
+
ui.print_debug("ServiceDeployer", "Finished deploying: #{service_name.to_s.green}")
|
90
|
+
end
|
77
91
|
end
|
78
|
-
end
|
79
92
|
|
80
|
-
|
93
|
+
task_group.wait
|
81
94
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def compile_images(images_names)
|
86
|
-
return true if images_names.empty?
|
87
|
-
image_compiler.call(images_names, {})
|
88
|
-
end
|
95
|
+
deployer_result
|
96
|
+
end
|
89
97
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
tags = [specific_service_option]
|
94
|
-
tags += service_store
|
95
|
-
.all_definitions
|
96
|
-
.values
|
97
|
-
.map(&:to_service_attrs)
|
98
|
-
.map(&:tags)
|
99
|
-
.flatten
|
100
|
-
.uniq
|
101
|
-
.sort
|
102
|
-
.map(&:to_s)
|
103
|
-
|
104
|
-
selected_tag = ui.prompt("Please select which tag to deploy", tags)
|
105
|
-
|
106
|
-
if selected_tag == specific_service_option
|
107
|
-
show_service_selection
|
108
|
-
else
|
109
|
-
[[], [selected_tag]]
|
98
|
+
def compile_images(images_names)
|
99
|
+
return true if images_names.empty?
|
100
|
+
image_compiler.call(images_names, {})
|
110
101
|
end
|
111
|
-
end
|
112
102
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
103
|
+
def show_tags_selection()
|
104
|
+
specific_service_option = "deploy specific service"
|
105
|
+
all_services_option = "deploy all services"
|
106
|
+
|
107
|
+
tags = [specific_service_option, all_services_option]
|
108
|
+
tags += service_store
|
109
|
+
.all_definitions
|
110
|
+
.values
|
111
|
+
.map(&:to_service_attrs)
|
112
|
+
.map(&:tags)
|
113
|
+
.flatten
|
114
|
+
.uniq
|
115
|
+
.sort
|
116
|
+
.map(&:to_s)
|
117
|
+
|
118
|
+
selected_tag = ui.prompt("Please select which tag to deploy", tags)
|
119
|
+
|
120
|
+
if selected_tag == specific_service_option
|
121
|
+
show_service_selection
|
122
|
+
elsif selected_tag == all_services_option
|
123
|
+
[["*"], []]
|
124
|
+
else
|
125
|
+
[[], [selected_tag]]
|
126
|
+
end
|
124
127
|
end
|
125
128
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
+
def show_service_selection()
|
130
|
+
services = service_store
|
131
|
+
.all_definitions
|
132
|
+
.values
|
133
|
+
.map(&:service_name)
|
134
|
+
.uniq
|
135
|
+
.sort
|
136
|
+
.map(&:to_s)
|
137
|
+
|
138
|
+
if services.empty?
|
139
|
+
return [[], []]
|
140
|
+
end
|
141
|
+
|
142
|
+
selected_service = ui.prompt("Please select which service to deploy", services)
|
143
|
+
[[selected_service], []]
|
144
|
+
end
|
129
145
|
end
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -30,7 +30,7 @@ class KuberKit::CLI < Thor
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
desc "deploy -t
|
33
|
+
desc "deploy -t TAG_NAME", "Deploy CONTEXT_NAME with kubectl"
|
34
34
|
method_option :services, :type => :array, aliases: ["-s"], repeatable: true
|
35
35
|
method_option :tags, :type => :array, aliases: ["-t"], repeatable: true
|
36
36
|
method_option :skip_compile, :type => :boolean, aliases: ["-B"]
|
@@ -86,6 +86,15 @@ class KuberKit::CLI < Thor
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
desc "check", "Check to make sure that all services are deployed"
|
90
|
+
def check()
|
91
|
+
setup(options)
|
92
|
+
|
93
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
94
|
+
KuberKit::Container['actions.service_checker'].call(options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
89
98
|
desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
|
90
99
|
def apply(file_path)
|
91
100
|
setup(options)
|
@@ -132,6 +141,24 @@ class KuberKit::CLI < Thor
|
|
132
141
|
end
|
133
142
|
end
|
134
143
|
|
144
|
+
desc "env", "Show environment variables for given configuration"
|
145
|
+
def env()
|
146
|
+
setup(options)
|
147
|
+
|
148
|
+
if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
|
149
|
+
KuberKit::Container['actions.kubectl_env'].call(options)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "get RESOURCE_NAME", "List pods matching RESOURCE_NAME using kubectl"
|
154
|
+
def get(pod_name = nil)
|
155
|
+
setup(options)
|
156
|
+
|
157
|
+
if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
|
158
|
+
KuberKit::Container['actions.kubectl_get'].call(pod_name, options)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
135
162
|
desc "version", "Print current version"
|
136
163
|
def version
|
137
164
|
puts KuberKit::VERSION
|
data/lib/kuber_kit/configs.rb
CHANGED
@@ -4,7 +4,7 @@ class KuberKit::Configs
|
|
4
4
|
AVAILABLE_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
|
-
:artifact_clone_dir, :service_config_dir, :deployer_strategy, :compile_simultaneous_limit,
|
7
|
+
:artifact_clone_dir, :service_config_dir, :deployer_strategy, :compile_simultaneous_limit, :deploy_simultaneous_limit,
|
8
8
|
:additional_images_paths, :deprecation_warnings_disabled, :log_file_path
|
9
9
|
]
|
10
10
|
DOCKER_IGNORE_LIST = [
|
@@ -49,6 +49,7 @@ class KuberKit::Configs
|
|
49
49
|
set :service_config_dir, "/tmp/kuber_kit/services"
|
50
50
|
set :deployer_strategy, :kubernetes
|
51
51
|
set :compile_simultaneous_limit, 5
|
52
|
+
set :deploy_simultaneous_limit, 5
|
52
53
|
set :additional_images_paths, []
|
53
54
|
set :deprecation_warnings_disabled, false
|
54
55
|
set :log_file_path, "/tmp/kuber_kit.log"
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -21,6 +21,10 @@ class KuberKit::Container
|
|
21
21
|
KuberKit::Actions::ServiceDeployer.new
|
22
22
|
end
|
23
23
|
|
24
|
+
register "actions.service_checker" do
|
25
|
+
KuberKit::Actions::ServiceChecker.new
|
26
|
+
end
|
27
|
+
|
24
28
|
register "actions.configuration_loader" do
|
25
29
|
KuberKit::Actions::ConfigurationLoader.new
|
26
30
|
end
|
@@ -41,10 +45,18 @@ class KuberKit::Container
|
|
41
45
|
KuberKit::Actions::KubectlDescribe.new
|
42
46
|
end
|
43
47
|
|
48
|
+
register "actions.kubectl_get" do
|
49
|
+
KuberKit::Actions::KubectlGet.new
|
50
|
+
end
|
51
|
+
|
44
52
|
register "actions.kubectl_logs" do
|
45
53
|
KuberKit::Actions::KubectlLogs.new
|
46
54
|
end
|
47
55
|
|
56
|
+
register "actions.kubectl_env" do
|
57
|
+
KuberKit::Actions::KubectlEnv.new
|
58
|
+
end
|
59
|
+
|
48
60
|
register "configs" do
|
49
61
|
KuberKit::Configs.new
|
50
62
|
end
|
@@ -249,6 +261,10 @@ class KuberKit::Container
|
|
249
261
|
KuberKit::ServiceDeployer::ServiceListResolver.new
|
250
262
|
end
|
251
263
|
|
264
|
+
register "service_deployer.service_dependency_resolver" do
|
265
|
+
KuberKit::ServiceDeployer::ServiceDependencyResolver.new
|
266
|
+
end
|
267
|
+
|
252
268
|
register "service_deployer.strategies.kubernetes" do
|
253
269
|
KuberKit::ServiceDeployer::Strategies::Kubernetes.new
|
254
270
|
end
|
@@ -269,6 +285,10 @@ class KuberKit::Container
|
|
269
285
|
KuberKit::ServiceReader::Reader.new
|
270
286
|
end
|
271
287
|
|
288
|
+
register "kubernetes.resource_selector" do
|
289
|
+
KuberKit::Kubernetes::ResourceSelector.new
|
290
|
+
end
|
291
|
+
|
272
292
|
register "kubernetes.resources_fetcher" do
|
273
293
|
KuberKit::Kubernetes::ResourcesFetcher.new
|
274
294
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class KuberKit::Core::Dependencies::AbstractDependencyResolver
|
2
|
+
CircularDependencyError = Class.new(KuberKit::Error)
|
3
|
+
DependencyNotFoundError = Class.new(KuberKit::NotFoundError)
|
4
|
+
|
5
|
+
# Iterate over list of dependencies for items (including the items themself).
|
6
|
+
# Iteration will send the list to the callback block function
|
7
|
+
Contract Or[Symbol, ArrayOf[Symbol]], Proc => Any
|
8
|
+
def each_with_deps(item_names, &block)
|
9
|
+
resolved_dependencies = []
|
10
|
+
# Get first list of dependencies ready to resolve
|
11
|
+
next_dependencies = get_next(item_names, limit: dependency_batch_size)
|
12
|
+
|
13
|
+
# Call the block for each list of dependencies ready to resolve, then calculate the next list
|
14
|
+
while (next_dependencies - resolved_dependencies).any?
|
15
|
+
block.call(next_dependencies)
|
16
|
+
resolved_dependencies += next_dependencies
|
17
|
+
next_dependencies = get_next(item_names, resolved: resolved_dependencies, limit: dependency_batch_size)
|
18
|
+
end
|
19
|
+
|
20
|
+
(item_names - resolved_dependencies).each_slice(dependency_batch_size) do |group|
|
21
|
+
block.call(group)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns next list of dependencies ready to resolve.
|
26
|
+
# Item is not ready to resolve if it has personal dependency.
|
27
|
+
# E.g. if "A" depends on "B" and "C", "C" depends on "D", then only "B" and "D" will be returned.
|
28
|
+
Contract Or[Symbol, ArrayOf[Symbol]], KeywordArgs[
|
29
|
+
resolved: Optional[ArrayOf[Symbol]],
|
30
|
+
limit: Optional[Maybe[Num]]
|
31
|
+
] => Any
|
32
|
+
def get_next(item_names, resolved: [], limit: nil)
|
33
|
+
deps = Array(item_names).map { |i| get_recursive_deps(i) }.flatten.uniq
|
34
|
+
|
35
|
+
# Find out which dependencies are ready to resolve,
|
36
|
+
# they should not have unresolved personal dependencies
|
37
|
+
ready_to_resolve = deps.select do |dep_name|
|
38
|
+
unresolved_deps = get_deps(dep_name) - resolved
|
39
|
+
unresolved_deps.empty?
|
40
|
+
end
|
41
|
+
unresolved_deps = ready_to_resolve - resolved
|
42
|
+
unresolved_deps = unresolved_deps.take(limit) if limit
|
43
|
+
unresolved_deps
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get all dependencies for items (including the items themself), without any limitations
|
47
|
+
Contract Or[Symbol, ArrayOf[Symbol]] => Any
|
48
|
+
def get_all(item_names)
|
49
|
+
deps = Array(item_names).map { |i| get_recursive_deps(i) }.flatten
|
50
|
+
(deps + item_names).uniq
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_recursive_deps(item_name, dependency_tree: [])
|
54
|
+
deps = get_deps(item_name)
|
55
|
+
|
56
|
+
if dependency_tree.include?(item_name)
|
57
|
+
raise CircularDependencyError, "Circular dependency found for #{item_name}. Dependency tree: #{dependency_tree.inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
child_deps = []
|
61
|
+
deps.each do |i|
|
62
|
+
child_deps += get_recursive_deps(i, dependency_tree: dependency_tree + [item_name])
|
63
|
+
end
|
64
|
+
|
65
|
+
(deps + child_deps).uniq
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_deps(item_name)
|
69
|
+
raise "This method should be overriden"
|
70
|
+
end
|
71
|
+
|
72
|
+
def dependency_batch_size
|
73
|
+
raise "This method should be overriden"
|
74
|
+
end
|
75
|
+
end
|
data/lib/kuber_kit/core/image.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class KuberKit::Core::Image
|
2
|
-
attr_reader :name, :dependencies, :registry, :dockerfile_path, :build_vars, :build_context_dir, :tag,
|
2
|
+
attr_reader :name, :dependencies, :registry, :dockerfile_path, :build_vars, :build_context_dir, :tag,
|
3
|
+
:before_build_callback, :after_build_callback
|
3
4
|
|
4
5
|
Contract KeywordArgs[
|
5
6
|
name: Symbol,
|
@@ -1,18 +1,20 @@
|
|
1
1
|
class KuberKit::Core::Service
|
2
2
|
AttributeNotSet = Class.new(Indocker::Error)
|
3
3
|
|
4
|
-
attr_reader :name, :template_name, :tags, :images, :attributes, :deployer_strategy
|
4
|
+
attr_reader :name, :dependencies, :template_name, :tags, :images, :attributes, :deployer_strategy
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
7
7
|
name: Symbol,
|
8
|
+
dependencies: ArrayOf[Symbol],
|
8
9
|
template_name: Maybe[Symbol],
|
9
10
|
tags: ArrayOf[Symbol],
|
10
11
|
images: ArrayOf[Symbol],
|
11
12
|
attributes: HashOf[Symbol => Any],
|
12
13
|
deployer_strategy: Maybe[Symbol]
|
13
14
|
] => Any
|
14
|
-
def initialize(name:, template_name:, tags:, images:, attributes:, deployer_strategy:)
|
15
|
+
def initialize(name:, dependencies:, template_name:, tags:, images:, attributes:, deployer_strategy:)
|
15
16
|
@name = name
|
17
|
+
@dependencies = dependencies
|
16
18
|
@template_name = template_name
|
17
19
|
@tags = tags
|
18
20
|
@images = images
|
@@ -1,22 +1,29 @@
|
|
1
1
|
class KuberKit::Core::ServiceDefinition
|
2
|
-
attr_reader :service_name, :template_name
|
2
|
+
attr_reader :service_name, :template_name, :dependencies
|
3
3
|
|
4
4
|
Contract Or[Symbol, String] => Any
|
5
5
|
def initialize(service_name)
|
6
6
|
@service_name = service_name.to_sym
|
7
|
+
@dependencies = []
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_service_attrs
|
10
11
|
OpenStruct.new(
|
11
|
-
name:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
name: @service_name,
|
13
|
+
dependencies: @dependencies,
|
14
|
+
template_name: get_value(@template_name),
|
15
|
+
tags: Array(get_value(@tags)).map(&:to_sym),
|
16
|
+
images: Array(get_value(@images)).map(&:to_sym),
|
17
|
+
attributes: get_value(@attributes),
|
16
18
|
deployer_strategy: get_value(@deployer_strategy),
|
17
19
|
)
|
18
20
|
end
|
19
21
|
|
22
|
+
def depends_on(*value, &block)
|
23
|
+
@dependencies = Array(value).flatten
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
20
27
|
def template(value = nil, &block)
|
21
28
|
@template_name = block_given? ? block : value
|
22
29
|
|
@@ -1,62 +1,14 @@
|
|
1
|
-
class KuberKit::ImageCompiler::ImageDependencyResolver
|
2
|
-
CircularDependencyError = Class.new(KuberKit::Error)
|
3
|
-
DependencyNotFoundError = Class.new(KuberKit::NotFoundError)
|
4
|
-
|
1
|
+
class KuberKit::ImageCompiler::ImageDependencyResolver < KuberKit::Core::Dependencies::AbstractDependencyResolver
|
5
2
|
include KuberKit::Import[
|
6
3
|
"core.image_store",
|
7
4
|
"configs"
|
8
5
|
]
|
9
|
-
|
10
|
-
Contract Or[Symbol, ArrayOf[Symbol]], Proc => Any
|
11
|
-
def each_with_deps(image_names, &block)
|
12
|
-
compile_limit = configs.compile_simultaneous_limit
|
13
|
-
|
14
|
-
resolved_dependencies = []
|
15
|
-
next_dependencies = get_next(image_names, limit: compile_limit)
|
16
|
-
|
17
|
-
while (next_dependencies - resolved_dependencies).any?
|
18
|
-
block.call(next_dependencies)
|
19
|
-
resolved_dependencies += next_dependencies
|
20
|
-
next_dependencies = get_next(image_names, resolved: resolved_dependencies, limit: compile_limit)
|
21
|
-
end
|
22
|
-
|
23
|
-
(image_names - resolved_dependencies).each_slice(compile_limit) do |group|
|
24
|
-
block.call(group)
|
25
|
-
end
|
26
|
-
end
|
27
6
|
|
28
|
-
Contract Or[Symbol, ArrayOf[Symbol]], KeywordArgs[
|
29
|
-
resolved: Optional[ArrayOf[Symbol]],
|
30
|
-
limit: Optional[Maybe[Num]]
|
31
|
-
] => Any
|
32
|
-
def get_next(image_names, resolved: [], limit: nil)
|
33
|
-
deps = Array(image_names).map { |i| get_recursive_deps(i) }.flatten.uniq
|
34
|
-
|
35
|
-
ready_to_resolve = deps.select do |dep_name|
|
36
|
-
unresolved_deps = get_deps(dep_name) - resolved
|
37
|
-
unresolved_deps.empty?
|
38
|
-
end
|
39
|
-
unresolved_deps = ready_to_resolve - resolved
|
40
|
-
unresolved_deps = unresolved_deps.take(limit) if limit
|
41
|
-
unresolved_deps
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_recursive_deps(image_name, dependency_tree: [])
|
45
|
-
deps = get_deps(image_name)
|
46
|
-
|
47
|
-
if dependency_tree.include?(image_name)
|
48
|
-
raise CircularDependencyError, "Circular dependency found for #{image_name}. Dependency tree: #{dependency_tree.inspect}"
|
49
|
-
end
|
50
|
-
|
51
|
-
child_deps = []
|
52
|
-
deps.each do |i|
|
53
|
-
child_deps += get_recursive_deps(i, dependency_tree: dependency_tree + [image_name])
|
54
|
-
end
|
55
|
-
|
56
|
-
(deps + child_deps).uniq
|
57
|
-
end
|
58
|
-
|
59
7
|
def get_deps(image_name)
|
60
8
|
image_store.get_definition(image_name).dependencies
|
61
9
|
end
|
10
|
+
|
11
|
+
def dependency_batch_size
|
12
|
+
configs.compile_simultaneous_limit
|
13
|
+
end
|
62
14
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class KuberKit::Kubernetes::ResourceSelector
|
2
|
+
include KuberKit::Import[
|
3
|
+
"kubernetes.resources_fetcher",
|
4
|
+
"shell.local_shell",
|
5
|
+
"ui"
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract String, KeywordArgs[
|
9
|
+
include_ingresses: Optional[Bool],
|
10
|
+
include_pods: Optional[Bool]
|
11
|
+
] => Any
|
12
|
+
def call(action_name, include_ingresses: false, include_pods: false)
|
13
|
+
deployments = resources_fetcher.call("deployments")
|
14
|
+
options = deployments.map{|d| "deploy/#{d}" }
|
15
|
+
options << "ingresses" if include_ingresses
|
16
|
+
options << "pods" if include_pods
|
17
|
+
option = ui.prompt("Please select resource to #{action_name}", options)
|
18
|
+
|
19
|
+
if option == "ingresses" && include_ingresses
|
20
|
+
ingresses = resources_fetcher.call("ingresses")
|
21
|
+
options = ingresses.map{|d| "ingresses/#{d}" }
|
22
|
+
return ui.prompt("Please select ingress to #{action_name}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
if option == "pods" && include_pods
|
26
|
+
ingresses = resources_fetcher.call("pods")
|
27
|
+
options = ingresses.map{|d| "pods/#{d}" }
|
28
|
+
return ui.prompt("Please select pod to #{action_name}", options)
|
29
|
+
end
|
30
|
+
|
31
|
+
option
|
32
|
+
end
|
33
|
+
end
|
@@ -2,40 +2,17 @@ class KuberKit::Kubernetes::ResourcesFetcher
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"shell.kubectl_commands",
|
4
4
|
"shell.local_shell",
|
5
|
-
"ui"
|
6
5
|
]
|
7
6
|
|
8
|
-
Contract String
|
9
|
-
|
10
|
-
|
11
|
-
] => Any
|
12
|
-
def call(action_name, include_ingresses: false, include_pods: false)
|
13
|
-
deployments = get_resources("deployments")
|
14
|
-
options = deployments.split(" ").map{|d| "deploy/#{d}" }
|
15
|
-
options << "ingresses" if include_ingresses
|
16
|
-
options << "pods" if include_pods
|
17
|
-
option = ui.prompt("Please select resource to #{action_name}", options)
|
18
|
-
|
19
|
-
if option == "ingresses" && include_ingresses
|
20
|
-
ingresses = get_resources("ingresses")
|
21
|
-
options = ingresses.split(" ").map{|d| "ingresses/#{d}" }
|
22
|
-
return ui.prompt("Please select ingress to #{action_name}", options)
|
23
|
-
end
|
24
|
-
|
25
|
-
if option == "pods" && include_pods
|
26
|
-
ingresses = get_resources("pods")
|
27
|
-
options = ingresses.split(" ").map{|d| "pods/#{d}" }
|
28
|
-
return ui.prompt("Please select pod to #{action_name}", options)
|
29
|
-
end
|
7
|
+
Contract String => ArrayOf[String]
|
8
|
+
def call(resource_type)
|
9
|
+
current_configuration = KuberKit.current_configuration
|
30
10
|
|
31
|
-
option
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_resources(type)
|
35
11
|
kubectl_commands.get_resources(
|
36
|
-
local_shell,
|
37
|
-
jsonpath:
|
38
|
-
|
12
|
+
local_shell, resource_type,
|
13
|
+
jsonpath: ".items[*].metadata.name",
|
14
|
+
kubeconfig_path: current_configuration.kubeconfig_path,
|
15
|
+
namespace: current_configuration.deployer_namespace
|
39
16
|
)
|
40
17
|
end
|
41
18
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class KuberKit::ServiceDeployer::ServiceDependencyResolver < KuberKit::Core::Dependencies::AbstractDependencyResolver
|
2
|
+
include KuberKit::Import[
|
3
|
+
"core.service_store",
|
4
|
+
"configs"
|
5
|
+
]
|
6
|
+
|
7
|
+
def get_deps(service_name)
|
8
|
+
service_store.get_definition(service_name).dependencies
|
9
|
+
end
|
10
|
+
|
11
|
+
def dependency_batch_size
|
12
|
+
configs.deploy_simultaneous_limit
|
13
|
+
end
|
14
|
+
end
|
@@ -41,9 +41,9 @@ class KuberKit::ServiceDeployer::ServiceListResolver
|
|
41
41
|
|
42
42
|
Contract Array => Array
|
43
43
|
def split_by_inclusion(array)
|
44
|
-
excluded, included = array.partition{|e| e.start_with?('
|
44
|
+
excluded, included = array.partition{|e| e.start_with?('!') }
|
45
45
|
|
46
|
-
excluded.map!{ |item| item.gsub(
|
46
|
+
excluded.map!{ |item| item.gsub(/^\!/, "") }
|
47
47
|
|
48
48
|
[included, excluded]
|
49
49
|
end
|
@@ -6,7 +6,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
6
6
|
]
|
7
7
|
|
8
8
|
STRATEGY_OPTIONS = [
|
9
|
+
:namespace,
|
9
10
|
:container_name,
|
11
|
+
:env_file,
|
10
12
|
:image_name,
|
11
13
|
:detached,
|
12
14
|
:command_name,
|
@@ -14,6 +16,8 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
14
16
|
:delete_if_exists,
|
15
17
|
:volumes,
|
16
18
|
:networks,
|
19
|
+
:expose,
|
20
|
+
:publish,
|
17
21
|
]
|
18
22
|
|
19
23
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
@@ -24,11 +28,15 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
24
28
|
raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
|
25
29
|
end
|
26
30
|
|
27
|
-
|
31
|
+
namespace = strategy_options.fetch(:namespace, nil)
|
32
|
+
container_name = strategy_options.fetch(:container_name, [namespace, service.name].compact.join("_"))
|
28
33
|
command_name = strategy_options.fetch(:command_name, nil)
|
34
|
+
env_file = strategy_options.fetch(:env_file, nil)
|
29
35
|
custom_args = strategy_options.fetch(:custom_args, nil)
|
30
36
|
networks = strategy_options.fetch(:networks, [])
|
31
37
|
volumes = strategy_options.fetch(:volumes, [])
|
38
|
+
expose_ports = strategy_options.fetch(:expose, [])
|
39
|
+
publish_ports = strategy_options.fetch(:publish, [])
|
32
40
|
hostname = strategy_options.fetch(:hostname, container_name)
|
33
41
|
|
34
42
|
image_name = strategy_options.fetch(:image_name, nil)
|
@@ -46,6 +54,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
46
54
|
if container_name
|
47
55
|
custom_args << "--name #{container_name}"
|
48
56
|
end
|
57
|
+
if env_file
|
58
|
+
custom_args << "--env-file #{env_file}"
|
59
|
+
end
|
49
60
|
if hostname
|
50
61
|
custom_args << "--hostname #{hostname}"
|
51
62
|
end
|
@@ -58,6 +69,12 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
58
69
|
docker_commands.create_volume(shell, volume_name) unless volume_name.start_with?("/")
|
59
70
|
custom_args << "--volume #{volume}"
|
60
71
|
end
|
72
|
+
Array(expose_ports).each do |expose_port|
|
73
|
+
custom_args << "--expose #{expose_port}"
|
74
|
+
end
|
75
|
+
Array(publish_ports).each do |publish_port|
|
76
|
+
custom_args << "--publish #{publish_port}"
|
77
|
+
end
|
61
78
|
|
62
79
|
docker_commands.run(
|
63
80
|
shell, image.remote_registry_url,
|
@@ -9,7 +9,8 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
|
|
9
9
|
:resource_type,
|
10
10
|
:resource_name,
|
11
11
|
:delete_if_exists,
|
12
|
-
:restart_if_exists
|
12
|
+
:restart_if_exists,
|
13
|
+
:wait_for_rollout
|
13
14
|
]
|
14
15
|
|
15
16
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
@@ -41,12 +42,18 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
|
|
41
42
|
|
42
43
|
apply_result = kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
43
44
|
|
44
|
-
restart_enabled
|
45
|
+
restart_enabled = strategy_options.fetch(:restart_if_exists, true)
|
46
|
+
wait_for_rollout = strategy_options.fetch(:wait_for_rollout, true)
|
45
47
|
if restart_enabled && resource_exists
|
46
48
|
kubectl_commands.rolling_restart(
|
47
49
|
shell, resource_type, resource_name,
|
48
50
|
kubeconfig_path: kubeconfig_path, namespace: namespace
|
49
51
|
)
|
52
|
+
|
53
|
+
kubectl_commands.rollout_status(
|
54
|
+
shell, resource_type, resource_name, wait: true,
|
55
|
+
kubeconfig_path: kubeconfig_path, namespace: namespace
|
56
|
+
) if wait_for_rollout
|
50
57
|
end
|
51
58
|
|
52
59
|
apply_result
|
@@ -60,19 +60,19 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
60
60
|
command_parts << "-o jsonpath='{#{jsonpath}}'"
|
61
61
|
end
|
62
62
|
|
63
|
-
result = kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
63
|
+
result = kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace).to_s
|
64
64
|
|
65
65
|
# Hide warnings manually, until appropriate kubectl option will be available
|
66
|
-
result = result.split("\n").reject{|n| n.start_with?("Warning:") }.join("\n")
|
66
|
+
result = result.split("\n").reject{|n| n.start_with?("Warning:") }.join("\n")
|
67
67
|
|
68
|
-
result
|
68
|
+
Array(result.split(" ")).reject(&:empty?)
|
69
69
|
end
|
70
70
|
|
71
71
|
def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
72
72
|
result = get_resources(shell, resource_type,
|
73
73
|
field_selector: "metadata.name=#{resource_name}", kubeconfig_path: kubeconfig_path, namespace: namespace
|
74
74
|
)
|
75
|
-
result
|
75
|
+
result.any?
|
76
76
|
end
|
77
77
|
|
78
78
|
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
@@ -102,4 +102,12 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
102
102
|
}
|
103
103
|
}, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
104
104
|
end
|
105
|
+
|
106
|
+
def rollout_status(shell, resource_type, resource_name, wait: true, kubeconfig_path: nil, namespace: nil)
|
107
|
+
command_parts = []
|
108
|
+
command_parts << %Q{rollout status #{resource_type} #{resource_name}}
|
109
|
+
command_parts << "-w" if wait
|
110
|
+
|
111
|
+
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
112
|
+
end
|
105
113
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
4
|
+
MAX_LINES_TO_PRINT = 50
|
5
|
+
|
4
6
|
include KuberKit::Import[
|
5
7
|
"shell.command_counter",
|
6
8
|
"shell.rsync_commands",
|
@@ -20,7 +22,19 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
20
22
|
end
|
21
23
|
|
22
24
|
if result && result != "" && log_command
|
23
|
-
|
25
|
+
print_result = result
|
26
|
+
print_result_lines = print_result.split("\n")
|
27
|
+
|
28
|
+
if print_result_lines.count >= MAX_LINES_TO_PRINT
|
29
|
+
print_result = [
|
30
|
+
"[Result is too long, showing only first and last items]".yellow,
|
31
|
+
print_result_lines.first,
|
32
|
+
"[#{print_result_lines.count - 2} lines not showing]".yellow,
|
33
|
+
print_result_lines.last
|
34
|
+
].join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
ui.print_debug("LocalShell", "Finished [#{command_number}] with result: \n ----\n#{print_result.grey}\n ----")
|
24
38
|
end
|
25
39
|
|
26
40
|
if $?.exitstatus != 0
|
data/lib/kuber_kit/version.rb
CHANGED
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.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- ".ruby-gemset"
|
166
166
|
- ".ruby-version"
|
167
167
|
- ".travis.yml"
|
168
|
+
- CHANGELOG.md
|
168
169
|
- Gemfile
|
169
170
|
- Gemfile.lock
|
170
171
|
- LICENSE.txt
|
@@ -209,7 +210,10 @@ files:
|
|
209
210
|
- lib/kuber_kit/actions/kubectl_attacher.rb
|
210
211
|
- lib/kuber_kit/actions/kubectl_console.rb
|
211
212
|
- lib/kuber_kit/actions/kubectl_describe.rb
|
213
|
+
- lib/kuber_kit/actions/kubectl_env.rb
|
214
|
+
- lib/kuber_kit/actions/kubectl_get.rb
|
212
215
|
- lib/kuber_kit/actions/kubectl_logs.rb
|
216
|
+
- lib/kuber_kit/actions/service_checker.rb
|
213
217
|
- lib/kuber_kit/actions/service_deployer.rb
|
214
218
|
- lib/kuber_kit/actions/service_reader.rb
|
215
219
|
- lib/kuber_kit/actions/template_reader.rb
|
@@ -237,6 +241,7 @@ files:
|
|
237
241
|
- lib/kuber_kit/core/context_helper/context_vars.rb
|
238
242
|
- lib/kuber_kit/core/context_helper/image_helper.rb
|
239
243
|
- lib/kuber_kit/core/context_helper/service_helper.rb
|
244
|
+
- lib/kuber_kit/core/dependencies/abstract_dependency_resolver.rb
|
240
245
|
- lib/kuber_kit/core/env_files/abstract_env_file.rb
|
241
246
|
- lib/kuber_kit/core/env_files/artifact_file.rb
|
242
247
|
- lib/kuber_kit/core/env_files/env_file_store.rb
|
@@ -273,11 +278,13 @@ files:
|
|
273
278
|
- lib/kuber_kit/image_compiler/image_builder.rb
|
274
279
|
- lib/kuber_kit/image_compiler/image_dependency_resolver.rb
|
275
280
|
- lib/kuber_kit/image_compiler/version_tag_builder.rb
|
281
|
+
- lib/kuber_kit/kubernetes/resource_selector.rb
|
276
282
|
- lib/kuber_kit/kubernetes/resources_fetcher.rb
|
277
283
|
- lib/kuber_kit/preprocessing/file_preprocessor.rb
|
278
284
|
- lib/kuber_kit/preprocessing/text_preprocessor.rb
|
279
285
|
- lib/kuber_kit/service_deployer/action_handler.rb
|
280
286
|
- lib/kuber_kit/service_deployer/deployer.rb
|
287
|
+
- lib/kuber_kit/service_deployer/service_dependency_resolver.rb
|
281
288
|
- lib/kuber_kit/service_deployer/service_list_resolver.rb
|
282
289
|
- lib/kuber_kit/service_deployer/strategies/abstract.rb
|
283
290
|
- lib/kuber_kit/service_deployer/strategies/docker.rb
|