kubec 0.4.1 → 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 +4 -4
- data/lib/kubec.rb +3 -0
- data/lib/kubec/config.rb +1 -0
- data/lib/kubec/config/downloader.rb +1 -10
- data/lib/kubec/dsl/kubernetes.rb +2 -1
- data/lib/kubec/kubernetes.rb +8 -1
- data/lib/kubec/kubernetes/config_map.rb +4 -11
- data/lib/kubec/kubernetes/secret.rb +40 -0
- data/lib/kubec/secret/base.rb +8 -0
- data/lib/kubec/secret/downloader.rb +44 -0
- data/lib/kubec/tasks/deploy.rake +2 -0
- data/lib/kubec/tasks/secret.rake +15 -0
- data/lib/kubec/utils.rb +1 -0
- data/lib/kubec/utils/path.rb +27 -0
- data/lib/kubec/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6046577f11a9c5ad6a0bc8181f8b79533c0bd40
|
4
|
+
data.tar.gz: 95b6a88c4db58fc52aa9a3a46296f0a802ee2365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16cceaff76119c566ce24f701ff8ceb4aaeeafd8c47e30aa974f2f5430aabb9f0c54a4201d32c1c6a2a3cd702368c710e6b6aafb0b38568cc60e0dab2a9a9465
|
7
|
+
data.tar.gz: 95e3e68f5efdad66f46e223de0e8ed48098173c72208a51aff28e1afc0ed55796850126ba9a090217472a29b31b71a829c86bab654c114e3d9b4d0c0486208e9
|
data/lib/kubec.rb
CHANGED
@@ -7,6 +7,7 @@ require 'pathname'
|
|
7
7
|
require 'singleton'
|
8
8
|
require 'hirb'
|
9
9
|
require 'colorize'
|
10
|
+
require 'base64'
|
10
11
|
require 'English'
|
11
12
|
|
12
13
|
require 'kubec/version'
|
@@ -19,5 +20,7 @@ module Kubec
|
|
19
20
|
autoload :DSL, 'kubec/dsl'
|
20
21
|
autoload :Status, 'kubec/status/base'
|
21
22
|
autoload :Utils, 'kubec/utils'
|
23
|
+
# TODO: Replace with Downloader
|
22
24
|
autoload :Config, 'kubec/config/base'
|
25
|
+
autoload :Secret, 'kubec/secret/base'
|
23
26
|
end
|
data/lib/kubec/config.rb
CHANGED
@@ -35,19 +35,10 @@ module Kubec
|
|
35
35
|
def write(path, body)
|
36
36
|
puts "=> #{path} saved"
|
37
37
|
File.write(
|
38
|
-
|
38
|
+
Utils::Path.with_stage(path),
|
39
39
|
body
|
40
40
|
)
|
41
41
|
end
|
42
|
-
|
43
|
-
# TODO: Refactor
|
44
|
-
def path_with_stage(path)
|
45
|
-
path.split('.').tap do |ary|
|
46
|
-
ext = ary.pop unless ary.first.empty?
|
47
|
-
ary.push(fetch(:stage, :staging))
|
48
|
-
ary.push(ext) if ext
|
49
|
-
end.join('.')
|
50
|
-
end
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
data/lib/kubec/dsl/kubernetes.rb
CHANGED
data/lib/kubec/kubernetes.rb
CHANGED
@@ -4,6 +4,7 @@ module Kubec
|
|
4
4
|
# Kubernetes
|
5
5
|
class Kubernetes
|
6
6
|
autoload :Config, 'kubec/kubernetes/config'
|
7
|
+
autoload :Secret, 'kubec/kubernetes/secret'
|
7
8
|
autoload :ConfigMap, 'kubec/kubernetes/config_map'
|
8
9
|
autoload :CronJob, 'kubec/kubernetes/cron_job'
|
9
10
|
autoload :Template, 'kubec/kubernetes/template'
|
@@ -18,7 +19,7 @@ module Kubec
|
|
18
19
|
|
19
20
|
include Singleton
|
20
21
|
|
21
|
-
APPLYABLE_TYPES = %i[service deployment config cronjob].freeze
|
22
|
+
APPLYABLE_TYPES = %i[service deployment config secret cronjob].freeze
|
22
23
|
|
23
24
|
class << self
|
24
25
|
def apply(type)
|
@@ -69,6 +70,7 @@ module Kubec
|
|
69
70
|
@services = []
|
70
71
|
@deployments = []
|
71
72
|
@configs = []
|
73
|
+
@secrets = []
|
72
74
|
@cronjobs = []
|
73
75
|
end
|
74
76
|
|
@@ -87,6 +89,11 @@ module Kubec
|
|
87
89
|
@configs << Kubernetes::ConfigMap.new(name, &block)
|
88
90
|
end
|
89
91
|
|
92
|
+
def secret(name = nil, &block)
|
93
|
+
return @secrets if name.nil?
|
94
|
+
@secrets << Kubernetes::Secret.new(name, &block)
|
95
|
+
end
|
96
|
+
|
90
97
|
def cronjob(name = nil, &block)
|
91
98
|
return @cronjobs if name.nil?
|
92
99
|
@cronjobs << Kubernetes::CronJob.new(name, &block)
|
@@ -27,8 +27,9 @@ module Kubec
|
|
27
27
|
def file(path)
|
28
28
|
key = path.split('/').last
|
29
29
|
@files[key] = path
|
30
|
-
path =
|
31
|
-
|
30
|
+
path = Utils::Path.with_stage(path) if stage_config_exist?(path)
|
31
|
+
value = File.read(path) if File.exist?(path)
|
32
|
+
set key, value || ''
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
@@ -41,15 +42,7 @@ module Kubec
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def stage_config_exist?(path)
|
44
|
-
File.exist?(
|
45
|
-
end
|
46
|
-
|
47
|
-
def path_with_stage(path)
|
48
|
-
path.split('.').tap do |ary|
|
49
|
-
ext = ary.pop
|
50
|
-
ary.push(fetch(:stage, :staging))
|
51
|
-
ary.push(ext)
|
52
|
-
end.join('.')
|
45
|
+
File.exist?(Utils::Path.with_stage(path))
|
53
46
|
end
|
54
47
|
end
|
55
48
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kubec
|
4
|
+
class Kubernetes
|
5
|
+
# :nodoc:
|
6
|
+
class Secret < ConfigMap
|
7
|
+
# TODO: Refactor this feature
|
8
|
+
def fetch(*args)
|
9
|
+
Environment.instance.fetch(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set(key, value)
|
13
|
+
self[:data][key] = Base64.encode64(value).delete("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: Refactor
|
17
|
+
def file(path)
|
18
|
+
key = path.split('/').last
|
19
|
+
@files[key] = path
|
20
|
+
path = Utils::Path.with_stage(path) if stage_config_exist?(path)
|
21
|
+
value = File.read(path) if File.exist?(path)
|
22
|
+
set key, value || ''
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def prepare
|
28
|
+
self[:apiVersion] = 'v1'
|
29
|
+
self[:metadata] = Metadata.new(@name)
|
30
|
+
self[:type] = 'Opaque'
|
31
|
+
self[:kind] = 'Secret'
|
32
|
+
self[:data] = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def stage_config_exist?(path)
|
36
|
+
File.exist?(Utils::Path.with_stage(path))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kubec
|
4
|
+
module Secret
|
5
|
+
# :nodoc:
|
6
|
+
class Downloader
|
7
|
+
def initialize
|
8
|
+
@result = `kubectl -n #{fetch(:stage, :staging)} get secret -o json`
|
9
|
+
@success = $CHILD_STATUS.success?
|
10
|
+
@items = {}
|
11
|
+
|
12
|
+
prepare
|
13
|
+
end
|
14
|
+
|
15
|
+
def save
|
16
|
+
Kubernetes.secret.each do |secret|
|
17
|
+
downloaded = @items[secret.name]
|
18
|
+
secret.files.each do |(key, path)|
|
19
|
+
write path, Base64.decode64(downloaded.dig('data', key))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def prepare
|
27
|
+
return unless @success
|
28
|
+
items = JSON.parse(@result).dig('items') || []
|
29
|
+
items.each do |item|
|
30
|
+
name = item.dig('metadata', 'name').to_sym
|
31
|
+
@items[name] = item
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def write(path, body)
|
36
|
+
puts "=> #{path} saved"
|
37
|
+
File.write(
|
38
|
+
Utils::Path.with_stage(path),
|
39
|
+
body
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/kubec/tasks/deploy.rake
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :secret do
|
4
|
+
desc 'Upload secret files'
|
5
|
+
task push: ['deploy:namespace'] do
|
6
|
+
Kubec::Utils::Helper.header 'Starting apply secret'
|
7
|
+
Kubec::Kubernetes.apply(:secret)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Download secret files'
|
11
|
+
task pull: ['deploy:namespace'] do
|
12
|
+
Kubec::Utils::Helper.header 'Starting save secret'
|
13
|
+
Kubec::Secret::Downloader.new.save
|
14
|
+
end
|
15
|
+
end
|
data/lib/kubec/utils.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kubec
|
4
|
+
module Utils
|
5
|
+
# :nodoc:
|
6
|
+
module Path
|
7
|
+
class << self
|
8
|
+
def dotfile?(path)
|
9
|
+
path
|
10
|
+
.split('/')
|
11
|
+
.last
|
12
|
+
.split('.')
|
13
|
+
.first
|
14
|
+
.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_stage(path)
|
18
|
+
path.split('.').tap do |ary|
|
19
|
+
ext = ary.pop unless dotfile?(path)
|
20
|
+
ary.push(fetch(:stage, :staging))
|
21
|
+
ary.push(ext) if ext
|
22
|
+
end.join('.')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/kubec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 5xRuby
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-01-
|
12
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -166,9 +166,12 @@ files:
|
|
166
166
|
- lib/kubec/kubernetes/deployment.rb
|
167
167
|
- lib/kubec/kubernetes/has_attribute.rb
|
168
168
|
- lib/kubec/kubernetes/metadata.rb
|
169
|
+
- lib/kubec/kubernetes/secret.rb
|
169
170
|
- lib/kubec/kubernetes/service.rb
|
170
171
|
- lib/kubec/kubernetes/template.rb
|
171
172
|
- lib/kubec/kubernetes/volume.rb
|
173
|
+
- lib/kubec/secret/base.rb
|
174
|
+
- lib/kubec/secret/downloader.rb
|
172
175
|
- lib/kubec/setup.rb
|
173
176
|
- lib/kubec/status.rb
|
174
177
|
- lib/kubec/status/base.rb
|
@@ -179,6 +182,7 @@ files:
|
|
179
182
|
- lib/kubec/tasks/deploy.rake
|
180
183
|
- lib/kubec/tasks/install.rake
|
181
184
|
- lib/kubec/tasks/restart.rake
|
185
|
+
- lib/kubec/tasks/secret.rake
|
182
186
|
- lib/kubec/tasks/status.rake
|
183
187
|
- lib/kubec/templates/Kubeconfig
|
184
188
|
- lib/kubec/templates/config/kubec.rb
|
@@ -187,6 +191,7 @@ files:
|
|
187
191
|
- lib/kubec/utils.rb
|
188
192
|
- lib/kubec/utils/helper.rb
|
189
193
|
- lib/kubec/utils/humanize_time.rb
|
194
|
+
- lib/kubec/utils/path.rb
|
190
195
|
- lib/kubec/version.rb
|
191
196
|
homepage: https://kubec.5xruby.tw
|
192
197
|
licenses: []
|