kuber_kit 0.4.9 → 0.5.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: 766eae8b402b82c6e307942d24f2ee60d87197ef0b966f8551e17b2926a8210b
4
- data.tar.gz: eae14447e34ab527affdfbbbdd9b34027470b6c2b54b63bb27be8cdf651bbd27
3
+ metadata.gz: da99b8b516e2fa2eb9090dc78084bc4b3d40f6d5856e4d3ecbbb993b1cbdef5d
4
+ data.tar.gz: 73c76c08809d116b0c5f317959b45e5fb513b518592f791d8a0d32a185a5d88c
5
5
  SHA512:
6
- metadata.gz: '086f8e0c1983f00c3b517d4bf8a90c53d4ba58395b429d65a0dd2afeb8e80aae0e5120adf3ea1936b3f7c343de57378ef4e6e5b45c4836eb3de82f73a8198bc7'
7
- data.tar.gz: d236328533a9f15eba54dba8c777e54821ddab141aaf46ada97e88d35a7fc7fe7048bcb49ddb719b081d55a36883a8434c39632343a210b174343851eb43fa93
6
+ metadata.gz: 5953d83da7b07ebe1ee9be3ee803c6662c2a585bbc4b01a66ba9eb3232df86f11c6f9991e3e6ffd992828d25b5b9fc554bdb71ecd396026941b78f23448acb80
7
+ data.tar.gz: a36e8746b7caddea4fe4342df5be1bd7c5304856a613e42b805b119013b9f31cc40c5de9be8587b2f13850f8bc9aa1e1e0179f88904d9ec1b0d3617285261a9b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.4.9)
4
+ kuber_kit (0.5.0)
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.0)
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)
@@ -1,5 +1,5 @@
1
1
  KuberKit
2
- .define_service(:compose_app)
2
+ .define_service(:auth_app)
3
3
  .template(:docker_compose)
4
4
  .images(:ruby_app)
5
5
  .tags(:compose)
data/lib/kuber_kit.rb CHANGED
@@ -165,12 +165,14 @@ module KuberKit
165
165
  autoload :TemplateReader, 'actions/template_reader'
166
166
  autoload :ServiceReader, 'actions/service_reader'
167
167
  autoload :ServiceDeployer, 'actions/service_deployer'
168
+ autoload :ServiceChecker, 'actions/service_checker'
168
169
  autoload :ConfigurationLoader, 'actions/configuration_loader'
169
170
  autoload :KubectlApplier, 'actions/kubectl_applier'
170
171
  autoload :KubectlAttacher, 'actions/kubectl_attacher'
171
172
  autoload :KubectlConsole, 'actions/kubectl_console'
172
173
  autoload :KubectlDescribe, 'actions/kubectl_describe'
173
174
  autoload :KubectlLogs, 'actions/kubectl_logs'
175
+ autoload :KubectlEnv, 'actions/kubectl_env'
174
176
  end
175
177
 
176
178
  module Extensions
@@ -178,6 +180,7 @@ module KuberKit
178
180
  end
179
181
 
180
182
  module Kubernetes
183
+ autoload :ResourceSelector, 'kubernetes/resource_selector'
181
184
  autoload :ResourcesFetcher, 'kubernetes/resources_fetcher'
182
185
  end
183
186
 
@@ -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,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
+ deployments = resources_fetcher.call("deployments")
19
+
20
+ missing_services = services.select{ |s| !deployments.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
data/lib/kuber_kit/cli.rb CHANGED
@@ -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,15 @@ 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
+
135
153
  desc "version", "Print current version"
136
154
  def version
137
155
  puts KuberKit::VERSION
@@ -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
@@ -45,6 +49,10 @@ class KuberKit::Container
45
49
  KuberKit::Actions::KubectlLogs.new
46
50
  end
47
51
 
52
+ register "actions.kubectl_env" do
53
+ KuberKit::Actions::KubectlEnv.new
54
+ end
55
+
48
56
  register "configs" do
49
57
  KuberKit::Configs.new
50
58
  end
@@ -269,6 +277,10 @@ class KuberKit::Container
269
277
  KuberKit::ServiceReader::Reader.new
270
278
  end
271
279
 
280
+ register "kubernetes.resource_selector" do
281
+ KuberKit::Kubernetes::ResourceSelector.new
282
+ end
283
+
272
284
  register "kubernetes.resources_fetcher" do
273
285
  KuberKit::Kubernetes::ResourcesFetcher.new
274
286
  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, 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 = 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, type,
37
- jsonpath: ".items[*].metadata.name",
38
- namespace: KuberKit.current_configuration.deployer_namespace
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
@@ -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") if result.is_a?(String)
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 && result != ""
75
+ result.any?
76
76
  end
77
77
 
78
78
  def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.4.9"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuber_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.5.0
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-02-11 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -209,7 +209,9 @@ files:
209
209
  - lib/kuber_kit/actions/kubectl_attacher.rb
210
210
  - lib/kuber_kit/actions/kubectl_console.rb
211
211
  - lib/kuber_kit/actions/kubectl_describe.rb
212
+ - lib/kuber_kit/actions/kubectl_env.rb
212
213
  - lib/kuber_kit/actions/kubectl_logs.rb
214
+ - lib/kuber_kit/actions/service_checker.rb
213
215
  - lib/kuber_kit/actions/service_deployer.rb
214
216
  - lib/kuber_kit/actions/service_reader.rb
215
217
  - lib/kuber_kit/actions/template_reader.rb
@@ -273,6 +275,7 @@ files:
273
275
  - lib/kuber_kit/image_compiler/image_builder.rb
274
276
  - lib/kuber_kit/image_compiler/image_dependency_resolver.rb
275
277
  - lib/kuber_kit/image_compiler/version_tag_builder.rb
278
+ - lib/kuber_kit/kubernetes/resource_selector.rb
276
279
  - lib/kuber_kit/kubernetes/resources_fetcher.rb
277
280
  - lib/kuber_kit/preprocessing/file_preprocessor.rb
278
281
  - lib/kuber_kit/preprocessing/text_preprocessor.rb