dapp 0.18.3 → 0.18.4
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 +4 -4
- data/lib/dapp/kube/dapp/command/common.rb +26 -8
- data/lib/dapp/kube/kubernetes/client.rb +47 -22
- data/lib/dapp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c75ea637d359d2090871e5069ecab913d92ac7c1daaf2d683e0c70bc5fd636a
|
4
|
+
data.tar.gz: 6a0881dca7824efef341e27cd47e74e49874df9b6e806fa91d36ac78f234820e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2046f3d7320ac03db82faef2251407a38ae63173b4ff90eff205a2ed04e5cccbfd562ee7c5a52bc9c0b62d01d080155f16b8d0056342ec54133dc842f77418fc
|
7
|
+
data.tar.gz: ed4bff41fc5a25d3e34cb3059dad42c3268dbed19fa90efa7f804798b21c5a0ef64d5906df9bd33826669ce5b9438d428d02f3eecbe5a454fb636a69939a8f52
|
@@ -143,10 +143,6 @@ module Dapp
|
|
143
143
|
"#{name}-#{kube_namespace}".slugify
|
144
144
|
end
|
145
145
|
|
146
|
-
def kube_namespace
|
147
|
-
kubernetes.namespace
|
148
|
-
end
|
149
|
-
|
150
146
|
{ encode: :generate, decode: :extract }.each do |type, secret_method|
|
151
147
|
define_method "kube_helm_#{type}_json" do |secret, json|
|
152
148
|
change_json_value = proc do |value|
|
@@ -225,12 +221,34 @@ module Dapp
|
|
225
221
|
@secret_key_not_found_in ||= []
|
226
222
|
end
|
227
223
|
|
228
|
-
def
|
229
|
-
|
230
|
-
|
231
|
-
|
224
|
+
def namespace_option
|
225
|
+
options[:namespace].nil? ? nil : options[:namespace].tr('_', '-')
|
226
|
+
end
|
227
|
+
|
228
|
+
def kube_namespace
|
229
|
+
namespace_option || begin
|
230
|
+
namespace = "default"
|
231
|
+
|
232
|
+
Kubernetes::Client.tap do |kube|
|
233
|
+
kube_config = kube.kube_config(kube.kube_config_path)
|
234
|
+
if kube_config
|
235
|
+
kube_context_name = kube.kube_context_name(kube_config)
|
236
|
+
kube_context_config = kube.kube_context_config(kube_config, kube_context_name)
|
237
|
+
|
238
|
+
if kube_context_config
|
239
|
+
context_namespace = kube.kube_context_namespace(kube_context_config)
|
240
|
+
namespace = context_namespace if context_namespace
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
namespace
|
232
246
|
end
|
233
247
|
end
|
248
|
+
|
249
|
+
def kubernetes
|
250
|
+
@kubernetes ||= Kubernetes::Client.new(namespace: kube_namespace)
|
251
|
+
end
|
234
252
|
end
|
235
253
|
end
|
236
254
|
end
|
@@ -3,6 +3,7 @@ module Dapp
|
|
3
3
|
module Kubernetes
|
4
4
|
class Client
|
5
5
|
include Helper::YAML
|
6
|
+
extend Helper::YAML
|
6
7
|
|
7
8
|
::Dapp::Dapp::Shellout::Base.default_env_keys << 'KUBECONFIG'
|
8
9
|
|
@@ -12,7 +13,7 @@ module Dapp
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def namespace
|
15
|
-
@namespace || kube_context_config
|
16
|
+
@namespace || self.class.kube_context_namespace(kube_context_config) || "default"
|
16
17
|
end
|
17
18
|
|
18
19
|
# Чтобы не перегружать методы явной передачей namespace.
|
@@ -222,48 +223,72 @@ module Dapp
|
|
222
223
|
|
223
224
|
def kube_user_config
|
224
225
|
@kube_user_config ||= begin
|
225
|
-
|
226
|
-
|
227
|
-
|
226
|
+
kube_user_config = self.class.kube_user_config(kube_config, kube_context_config['context']['user'])
|
227
|
+
raise Error::BadConfig, code: :kube_user_not_found, data: {context: kube_context_config} if kube_user_config.nil?
|
228
|
+
kube_user_config
|
228
229
|
end
|
229
230
|
end
|
230
231
|
|
231
232
|
def kube_cluster_config
|
232
233
|
@kube_cluster_config ||= begin
|
233
|
-
|
234
|
-
|
235
|
-
|
234
|
+
kube_cluster_config = self.class.kube_cluster_config(kube_config, kube_context_config['context']['cluster'])
|
235
|
+
raise Error::BadConfig, code: :kube_cluster_not_found, data: {context: kube_context_config} if kube_cluster_config.nil?
|
236
|
+
kube_cluster_config
|
236
237
|
end
|
237
238
|
end
|
238
239
|
|
239
240
|
def kube_context_config
|
240
241
|
@kube_context_config ||= begin
|
241
|
-
|
242
|
-
|
243
|
-
|
242
|
+
context_name = self.class.kube_context_name(kube_config)
|
243
|
+
kube_context_config = self.class.kube_context_config(kube_config, context_name)
|
244
|
+
raise Error::BadConfig, code: :kube_context_not_found, data: {context_name: context_name} if kube_context_config.nil?
|
245
|
+
kube_context_config
|
244
246
|
end
|
245
247
|
end
|
246
248
|
|
247
|
-
def
|
248
|
-
@
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
end
|
249
|
+
def kube_config
|
250
|
+
@kube_config ||= begin
|
251
|
+
kube_config = self.class.kube_config(self.class.kube_config_path)
|
252
|
+
raise Error::Base, code: :kube_config_not_found, data: { path: self.class.kube_config_path } if kube_config.nil?
|
253
|
+
kube_config
|
253
254
|
end
|
254
255
|
end
|
255
256
|
|
256
|
-
|
257
|
-
|
257
|
+
class << self
|
258
|
+
def kube_config_path
|
258
259
|
kube_config_path = ENV['KUBECONFIG']
|
259
260
|
kube_config_path = File.join(ENV['HOME'], '.kube/config') unless kube_config_path
|
261
|
+
kube_config_path
|
262
|
+
end
|
260
263
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
264
|
+
def kube_config(kube_config_path)
|
265
|
+
yaml_load_file(kube_config_path) if File.exist?(kube_config_path)
|
266
|
+
end
|
267
|
+
|
268
|
+
def kube_context_name(kube_config)
|
269
|
+
kube_config['current-context'] || begin
|
270
|
+
if context = kube_config.fetch('contexts', []).first
|
271
|
+
warn "[WARN] .kube/config current-context is not set, using context '#{context['name']}'"
|
272
|
+
context['name']
|
273
|
+
end
|
265
274
|
end
|
266
275
|
end
|
276
|
+
|
277
|
+
def kube_context_config(kube_config, kube_context_name)
|
278
|
+
kube_config.fetch('contexts', []).find {|context| context['name'] == kube_context_name}
|
279
|
+
end
|
280
|
+
|
281
|
+
def kube_user_config(kube_config, user_name)
|
282
|
+
kube_config.fetch('users', []).find {|user| user['name'] == user_name}
|
283
|
+
end
|
284
|
+
|
285
|
+
def kube_cluster_config(kube_config, cluster_name)
|
286
|
+
kube_config.fetch('clusters', []).find {|cluster| cluster['name'] == cluster_name}
|
287
|
+
end
|
288
|
+
|
289
|
+
def kube_context_namespace(kube_context_config)
|
290
|
+
kube_context_config['context']['namespace']
|
291
|
+
end
|
267
292
|
end
|
268
293
|
end # Client
|
269
294
|
end # Kubernetes
|
data/lib/dapp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Stolyarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|