kerbi 0.0.1 → 0.0.5
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/cli/base_handler.rb +194 -0
- data/lib/cli/base_serializer.rb +120 -0
- data/lib/cli/config_handler.rb +51 -0
- data/lib/cli/entry_serializers.rb +99 -0
- data/lib/cli/project_handler.rb +2 -2
- data/lib/cli/release_handler.rb +41 -0
- data/lib/cli/release_serializer.rb +46 -0
- data/lib/cli/root_handler.rb +34 -13
- data/lib/cli/state_handler.rb +88 -0
- data/lib/cli/values_handler.rb +4 -3
- data/{boilerplate → lib/code-gen/new-project}/Gemfile.erb +0 -0
- data/lib/code-gen/new-project/kerbifile.rb.erb +9 -0
- data/lib/code-gen/new-project/values.yaml.erb +1 -0
- data/lib/config/cli_schema.rb +343 -28
- data/lib/config/config_file.rb +60 -0
- data/lib/config/globals.rb +4 -0
- data/lib/config/run_opts.rb +162 -0
- data/lib/config/state_consts.rb +11 -0
- data/lib/kerbi.rb +35 -10
- data/lib/main/code_gen.rb +1 -1
- data/lib/main/errors.rb +115 -0
- data/lib/main/mixer.rb +20 -10
- data/lib/mixins/cli_state_helpers.rb +108 -0
- data/lib/mixins/cm_backend_testing.rb +109 -0
- data/lib/mixins/entry_tag_logic.rb +183 -0
- data/lib/state/base_backend.rb +93 -0
- data/lib/state/config_map_backend.rb +173 -0
- data/lib/state/entry.rb +173 -0
- data/lib/state/entry_set.rb +137 -0
- data/lib/state/metadata.yaml.erb +11 -0
- data/lib/state/mixers.rb +23 -0
- data/lib/state/resources.yaml.erb +17 -0
- data/lib/utils/cli.rb +108 -9
- data/lib/utils/helm.rb +10 -12
- data/lib/utils/k8s_auth.rb +87 -0
- data/lib/utils/misc.rb +36 -1
- data/lib/utils/mixing.rb +1 -1
- data/lib/utils/values.rb +13 -22
- data/spec/cli/config_handler_spec.rb +38 -0
- data/spec/cli/release_handler_spec.rb +127 -0
- data/spec/cli/root_handler_spec.rb +100 -0
- data/spec/cli/state_handler_spec.rb +108 -0
- data/spec/cli/values_handler_spec.rb +17 -0
- data/spec/fixtures/expectations/common/bad-tag.txt +1 -0
- data/spec/fixtures/expectations/config/bad-set.txt +1 -0
- data/spec/fixtures/expectations/config/set.txt +1 -0
- data/spec/fixtures/expectations/config/show-default.yaml +6 -0
- data/spec/fixtures/expectations/release/delete.txt +1 -0
- data/spec/fixtures/expectations/release/init-already-existed.txt +2 -0
- data/spec/fixtures/expectations/release/init-both-created.txt +2 -0
- data/spec/fixtures/expectations/release/list.txt +5 -0
- data/spec/fixtures/expectations/release/status-all-working.txt +5 -0
- data/spec/fixtures/expectations/release/status-data-unreadable.txt +5 -0
- data/spec/fixtures/expectations/release/status-not-provisioned.txt +5 -0
- data/spec/fixtures/expectations/root/template-inlines.yaml +31 -0
- data/spec/fixtures/expectations/root/template-production.yaml +31 -0
- data/spec/fixtures/expectations/root/template-read-inlines.yaml +31 -0
- data/spec/fixtures/expectations/root/template-read.yaml +31 -0
- data/spec/fixtures/expectations/root/template-write.yaml +31 -0
- data/spec/fixtures/expectations/root/template.yaml +31 -0
- data/spec/fixtures/expectations/root/values.json +28 -0
- data/spec/fixtures/expectations/state/delete.txt +1 -0
- data/spec/fixtures/expectations/state/demote.txt +1 -0
- data/spec/fixtures/expectations/state/list.json +51 -0
- data/spec/fixtures/expectations/state/list.txt +6 -0
- data/spec/fixtures/expectations/state/list.yaml +35 -0
- data/spec/fixtures/expectations/state/promote.txt +1 -0
- data/spec/fixtures/expectations/state/prune-candidates.txt +1 -0
- data/spec/fixtures/expectations/state/retag.txt +1 -0
- data/spec/fixtures/expectations/state/set.txt +1 -0
- data/spec/fixtures/expectations/state/show.json +13 -0
- data/spec/fixtures/expectations/state/show.txt +13 -0
- data/spec/fixtures/expectations/state/show.yaml +8 -0
- data/spec/fixtures/expectations/values/order-of-precedence.yaml +4 -0
- data/spec/main/configmap_backend_spec.rb +110 -0
- data/spec/main/project_code_gen_spec.rb +8 -2
- data/spec/main/state_entry_set_spec.rb +112 -0
- data/spec/main/state_entry_spec.rb +109 -0
- data/spec/mini-projects/hello-kerbi/common/metadata.yaml.erb +5 -0
- data/spec/mini-projects/hello-kerbi/consts.rb +5 -0
- data/spec/mini-projects/hello-kerbi/helpers.rb +8 -0
- data/spec/mini-projects/hello-kerbi/kerbifile.rb +18 -0
- data/spec/mini-projects/hello-kerbi/pod-and-service.yaml.erb +23 -0
- data/spec/mini-projects/hello-kerbi/values/production.yaml +2 -0
- data/spec/mini-projects/hello-kerbi/values/v2.yaml +2 -0
- data/spec/mini-projects/hello-kerbi/values/values.yaml +4 -0
- data/spec/spec_helper.rb +143 -1
- data/spec/utils/helm_spec.rb +89 -109
- data/spec/utils/k8s_auth_spec.rb +32 -0
- data/spec/utils/misc_utils_spec.rb +9 -0
- data/spec/utils/values_utils_spec.rb +12 -19
- metadata +143 -16
- data/boilerplate/kerbifile.rb.erb +0 -9
- data/boilerplate/values.yaml.erb +0 -1
- data/lib/cli/base.rb +0 -83
- data/lib/config/cli_opts.rb +0 -50
- data/lib/config/manager.rb +0 -36
- data/lib/main/state_manager.rb +0 -47
- data/lib/utils/kubectl.rb +0 -58
- data/spec/main/examples_spec.rb +0 -12
- data/spec/main/state_manager_spec.rb +0 -84
- data/spec/utils/state_utils.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12c9672d03ca241ca969d74f1ef3297c4571976c9f8c2b16d688d9552b472a2e
|
4
|
+
data.tar.gz: 12bdb95a12e5e8a82fec049cfca51deab3d5ddcf922fe880067a86a5bad20f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d63e202d6c736d15fe3520f50d92f8661790b5718bb690fc6badc7351ea156db4abc55491f2c63293432048e601b3d4e55c689ec8c2fc7a5d5b24f8e936528
|
7
|
+
data.tar.gz: 18ab1a1acae9e29d909e35fef91cb71143d1ba2db38f0db63596944e13dfd1bc3caa8cc868edef1e5da6bdafd34a6092bc03ef976f7fa51324bd120ba5317794
|
@@ -0,0 +1,194 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
|
4
|
+
##
|
5
|
+
# Superclass for all Thor CLI handlers.
|
6
|
+
class BaseHandler < Thor
|
7
|
+
include Kerbi::Mixins::CliStateHelpers
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
##
|
12
|
+
# Convenience method for instantiating (and memoizating) a state
|
13
|
+
# management backend.
|
14
|
+
def state_backend(**opts)
|
15
|
+
@_state_backend ||= generate_state_backend(**opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def mem_release_name(release_name)
|
19
|
+
self.run_opts.release_name = release_name
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Looks at the CLI options to determine which
|
24
|
+
# data serializer should be used.
|
25
|
+
# @param [Hash] options
|
26
|
+
# @return [Class<Kerbi::Cli::BaseSerializer>|null]
|
27
|
+
def resolve_serializer(options={})
|
28
|
+
if run_opts.output_json?
|
29
|
+
winner = options[:json_serializer]
|
30
|
+
elsif run_opts.output_yaml?
|
31
|
+
winner = options[:yaml_serializer]
|
32
|
+
elsif run_opts.output_table?
|
33
|
+
winner = options[:table_serializer]
|
34
|
+
else
|
35
|
+
raise "Unknown output format '#{run_opts.output_format}'"
|
36
|
+
end
|
37
|
+
winner || options[:serializer]
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Pretty prints data to STDOUT selecting the right
|
42
|
+
# serializer, and coercing data if requested by the
|
43
|
+
# caller.
|
44
|
+
# @param [Hash|Array<Object>] dicts
|
45
|
+
def echo_data(items, **opts)
|
46
|
+
utils = Kerbi::Utils::Cli
|
47
|
+
serializer = resolve_serializer(opts)
|
48
|
+
items = utils.coerce_hash_or_array(items, opts)
|
49
|
+
if serializer
|
50
|
+
if items.is_a?(Array)
|
51
|
+
items = items.map{ |e| serializer.new(e).serialize }
|
52
|
+
else
|
53
|
+
items = serializer.new(items).serialize
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if run_opts.output_yaml?
|
58
|
+
printable_str = utils.dicts_to_yaml(items)
|
59
|
+
elsif run_opts.output_json?
|
60
|
+
printable_str = utils.dicts_to_json(items)
|
61
|
+
elsif run_opts.output_table?
|
62
|
+
printable_str = utils.list_to_table(items, serializer)
|
63
|
+
else
|
64
|
+
raise "Unknown output format '#{run_opts.output_format}'"
|
65
|
+
end
|
66
|
+
|
67
|
+
echo(printable_str)
|
68
|
+
end
|
69
|
+
|
70
|
+
def echo(printable_str)
|
71
|
+
$stdout.puts printable_str
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Returns single merged dict containing all values given or
|
76
|
+
# pointed to by the CLI args, plus the default values.yaml file.
|
77
|
+
# This includes values from files, inline expressions, and the
|
78
|
+
# state ConfigMap.
|
79
|
+
# @return [Hash] symbol-keyed dict of all loaded values
|
80
|
+
def compile_values
|
81
|
+
@_compiled_values ||=
|
82
|
+
begin
|
83
|
+
utils = Kerbi::Utils::Values
|
84
|
+
|
85
|
+
fname_exprs = run_opts.fname_exprs
|
86
|
+
fname_exprs = ["values", *fname_exprs] if run_opts.load_defaults?
|
87
|
+
|
88
|
+
file_values = utils.from_files(
|
89
|
+
fname_exprs,
|
90
|
+
root: run_opts.project_root
|
91
|
+
)
|
92
|
+
|
93
|
+
inline_values = utils.from_inlines(run_opts.inline_val_exprs)
|
94
|
+
state_values = read_state_values
|
95
|
+
|
96
|
+
file_values.
|
97
|
+
deep_merge(state_values).
|
98
|
+
deep_merge(inline_values)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Compiles the values from only the default values file,
|
104
|
+
# e.g values.yaml, or values/values.yaml.
|
105
|
+
# @return [Hash]
|
106
|
+
def compile_default_values
|
107
|
+
utils = Kerbi::Utils::Values
|
108
|
+
if run_opts.load_defaults?
|
109
|
+
utils.from_files(['values'], root: run_opts.project_root)
|
110
|
+
else
|
111
|
+
{}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Called by command-methods that need to start with a set
|
117
|
+
# of default options that is not the normal default,
|
118
|
+
# i.e that is not Kerbi::Consts::OptionDefaults::BASE.
|
119
|
+
# @param [Hash] defaults alternative defaults
|
120
|
+
def prep_opts(defaults)
|
121
|
+
@_options_obj = Kerbi::RunOpts.new(options, defaults)
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Returns a re-usable instance of the CLI-args
|
126
|
+
# wrapper Kerbi::RunOpts
|
127
|
+
# @return [Kerbi::RunOpts] re-usable instance
|
128
|
+
def run_opts
|
129
|
+
@_options_obj ||= Kerbi::RunOpts.new(
|
130
|
+
options,
|
131
|
+
Kerbi::Consts::OptionDefaults::BASE
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Convenience class method for declaring a Thor subcommand
|
137
|
+
# metadata bundle, in accordance with the schema in
|
138
|
+
# Kerbi::Consts::OptionSchemas.
|
139
|
+
# @param [Hash] _schema a dict from Kerbi::Consts::OptionSchemas
|
140
|
+
# @param [Class<Thor>] handler_cls the handler
|
141
|
+
def self.sub_cmd_meta(_schema, handler_cls)
|
142
|
+
schema = _schema.deep_dup
|
143
|
+
desc(schema[:name], schema[:desc])
|
144
|
+
subcommand schema[:name], handler_cls
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.option_defaults_hash
|
148
|
+
@_option_defaults_hash ||= {}
|
149
|
+
end
|
150
|
+
|
151
|
+
# def self.set_default_options_for_next(defaults)
|
152
|
+
# defaults ||= Kerbi::Consts::OptionDefaults::BASE
|
153
|
+
# option_defaults_hash[:__next__] = defaults.deep_dup
|
154
|
+
# end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Convenience class method for declaring a Thor command
|
158
|
+
# metadata bundle, in accordance with the schema in
|
159
|
+
# Kerbi::Consts::OptionSchemas.
|
160
|
+
# @param [Hash] _schema a dict from Kerbi::Consts::OptionSchemas
|
161
|
+
def self.cmd_meta(_schema)
|
162
|
+
schema = _schema.deep_dup
|
163
|
+
desc(schema[:name], schema[:desc])
|
164
|
+
# set_default_options_for_next(schema[:defaults])
|
165
|
+
(schema[:options] || []).each do |opt_schema|
|
166
|
+
opt_key = opt_schema.delete(:key)
|
167
|
+
self.option opt_key, opt_schema
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.exit_on_failure?
|
172
|
+
true
|
173
|
+
end
|
174
|
+
|
175
|
+
def user_confirmed?(message='Are you sure?')
|
176
|
+
unless run_opts.confirmed?
|
177
|
+
end_with = "Enter 'yes' to confirm or re-run with --confirm."
|
178
|
+
echo("#{message} #{end_with}")
|
179
|
+
unless STDIN.gets.strip.downcase == "yes"
|
180
|
+
echo("Aborted")
|
181
|
+
return false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
true
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
def utils
|
190
|
+
Kerbi::Utils
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
class BaseSerializer
|
4
|
+
|
5
|
+
attr_reader :object
|
6
|
+
attr_reader :parent_object
|
7
|
+
attr_reader :context
|
8
|
+
|
9
|
+
def initialize(object, context={})
|
10
|
+
@object = object
|
11
|
+
@parent_object = context.delete(:parent_object)
|
12
|
+
@context = context
|
13
|
+
end
|
14
|
+
|
15
|
+
def serialize
|
16
|
+
flat_attrs = serialize_flat_attrs
|
17
|
+
assoc_attrs = serialize_associations
|
18
|
+
poss_attrs = serialize_possessions
|
19
|
+
flat_attrs.merge(assoc_attrs).merge(poss_attrs)
|
20
|
+
end
|
21
|
+
|
22
|
+
def serialize_flat_attrs
|
23
|
+
Hash[self.class.attributes.map do |attribute_name|
|
24
|
+
[attribute_name, attribute_value(attribute_name)]
|
25
|
+
end]
|
26
|
+
end
|
27
|
+
|
28
|
+
def serialize_possessions
|
29
|
+
Hash[self.class.possessions.map do |possession|
|
30
|
+
attr = possession[:attr] || possession[:name]
|
31
|
+
value = attribute_value(attr)
|
32
|
+
serialized_value = value && begin
|
33
|
+
serialized_relation_value(possession, value)
|
34
|
+
end
|
35
|
+
[attr, serialized_value]
|
36
|
+
end]
|
37
|
+
end
|
38
|
+
|
39
|
+
def serialize_associations
|
40
|
+
Hash[self.class.associations.map do |association|
|
41
|
+
attr = association[:attr] || association[:name]
|
42
|
+
values = attribute_value(attr)
|
43
|
+
values = limit_has_many(attr, values)
|
44
|
+
serialized_array = values.map do |value|
|
45
|
+
serialized_relation_value(association, value)
|
46
|
+
end
|
47
|
+
[attr, serialized_array]
|
48
|
+
end]
|
49
|
+
end
|
50
|
+
|
51
|
+
def serialized_relation_value(relation, value)
|
52
|
+
serializer = relation[:serializer]
|
53
|
+
new_context = context.merge(parent_object: object)
|
54
|
+
serializer.serialize(value, new_context)
|
55
|
+
end
|
56
|
+
|
57
|
+
def attribute_value(name)
|
58
|
+
receiver = self.respond_to?(name) ? self : object
|
59
|
+
receiver.send(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def limit_has_many(association_name, query_result)
|
63
|
+
limit_quantity = context["#{association_name}_limit".to_sym]
|
64
|
+
limit_quantity && query_result.limit(limit_quantity) || query_result
|
65
|
+
end
|
66
|
+
|
67
|
+
def key
|
68
|
+
object.id
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.has_many(name, serializer, attr=nil)
|
72
|
+
@associations ||= []
|
73
|
+
@associations << {
|
74
|
+
name: name.to_sym,
|
75
|
+
serializer: serializer,
|
76
|
+
attr: attr
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.has_one(name, serializer, attr=nil)
|
81
|
+
@possessions ||= []
|
82
|
+
@possessions << {
|
83
|
+
name: name.to_sym,
|
84
|
+
serializer: serializer,
|
85
|
+
attr: attr
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.possessions
|
90
|
+
@possessions ||= []
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.associations
|
94
|
+
@associations ||= []
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.attributes
|
98
|
+
@attributes ||= []
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.has_attributes(*attrs)
|
102
|
+
@attributes = attrs.map(&:to_sym)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.header_titles
|
106
|
+
attributes.map(&:to_s).map(&:upcase)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.serialize(object, context={})
|
110
|
+
instance = new(object, context)
|
111
|
+
instance.serialize
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.serialize_many(objects, context={})
|
115
|
+
out = objects.map {|object| serialize(object, context)}
|
116
|
+
{ data: out }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
class ConfigHandler < BaseHandler
|
4
|
+
|
5
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_LOCATION
|
6
|
+
def location
|
7
|
+
echo Kerbi::ConfigFile.file_path
|
8
|
+
end
|
9
|
+
|
10
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_SET
|
11
|
+
def set(key, new_value)
|
12
|
+
raise_if_bad_write(key)
|
13
|
+
old_value = run_opts.options[key]
|
14
|
+
Kerbi::ConfigFile.patch(key => new_value)
|
15
|
+
|
16
|
+
name = "config[#{key}]"
|
17
|
+
change_str = "from #{old_value} => #{new_value}"
|
18
|
+
echo "Updated #{name} #{change_str}".colorize(:green)
|
19
|
+
end
|
20
|
+
|
21
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_GET
|
22
|
+
def get(key)
|
23
|
+
echo run_opts.options[key]
|
24
|
+
end
|
25
|
+
|
26
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_SHOW
|
27
|
+
def show
|
28
|
+
echo_data(run_opts.options)
|
29
|
+
end
|
30
|
+
|
31
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_RESET
|
32
|
+
def reset
|
33
|
+
Kerbi::ConfigFile.reset
|
34
|
+
echo("Config reset".colorize(:green))
|
35
|
+
echo("See #{Kerbi::ConfigFile.file_path}")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def raise_if_bad_write(key)
|
41
|
+
unless legal_keys.include?(key)
|
42
|
+
raise Kerbi::IllegalConfigWrite.new(key)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def legal_keys
|
47
|
+
Kerbi::Consts::OptionKeys::LEGAL_CONFIG_FILE_KEYS
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
module EntrySerializationHelpers
|
4
|
+
def defined_or_na(actual_value)
|
5
|
+
if !(value = actual_value).nil?
|
6
|
+
if block_given?
|
7
|
+
begin
|
8
|
+
yield(value)
|
9
|
+
rescue
|
10
|
+
"ERR"
|
11
|
+
end
|
12
|
+
else
|
13
|
+
value
|
14
|
+
end
|
15
|
+
else
|
16
|
+
"N/A"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def colored_tag
|
21
|
+
#noinspection RubyResolve
|
22
|
+
color = object.committed? ? :blue : :yellow
|
23
|
+
object.tag.colorize(color)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class EntryYamlJsonSerializer < Kerbi::Cli::BaseSerializer
|
29
|
+
include Kerbi::Cli::EntrySerializationHelpers
|
30
|
+
|
31
|
+
has_attributes(
|
32
|
+
:tag,
|
33
|
+
:message,
|
34
|
+
:created_at,
|
35
|
+
:values,
|
36
|
+
:default_values,
|
37
|
+
:overridden_keys
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
class FullEntryRowSerializer < Kerbi::Cli::BaseSerializer
|
42
|
+
include Kerbi::Cli::EntrySerializationHelpers
|
43
|
+
|
44
|
+
has_attributes(
|
45
|
+
:tag,
|
46
|
+
:message,
|
47
|
+
:created_at,
|
48
|
+
:values,
|
49
|
+
:default_values,
|
50
|
+
:overridden_keys
|
51
|
+
)
|
52
|
+
|
53
|
+
def tag
|
54
|
+
#noinspection RubyResolve
|
55
|
+
colored_tag.bold
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class EntryRowSerializer < Kerbi::Cli::BaseSerializer
|
60
|
+
include Kerbi::Cli::EntrySerializationHelpers
|
61
|
+
|
62
|
+
has_attributes(
|
63
|
+
:tag,
|
64
|
+
:message,
|
65
|
+
:assignments,
|
66
|
+
:overrides,
|
67
|
+
:created_at
|
68
|
+
)
|
69
|
+
|
70
|
+
def tag
|
71
|
+
colored_tag
|
72
|
+
end
|
73
|
+
|
74
|
+
def message
|
75
|
+
(object.message || "").truncate(27)
|
76
|
+
end
|
77
|
+
|
78
|
+
def assignments
|
79
|
+
defined_or_na(object.values) do |values|
|
80
|
+
Kerbi::Utils::Misc.flatten_hash(values).count
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def overrides
|
85
|
+
defined_or_na(object.overrides_delta) do |differences|
|
86
|
+
Kerbi::Utils::Misc.flatten_hash(differences).count
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def created_at
|
91
|
+
if object.created_at
|
92
|
+
Kerbi::Utils::Misc.pretty_time_elapsed(object.created_at)
|
93
|
+
else
|
94
|
+
"N/A"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/cli/project_handler.rb
CHANGED
@@ -2,11 +2,11 @@ module Kerbi
|
|
2
2
|
module Cli
|
3
3
|
class ProjectHandler < BaseHandler
|
4
4
|
|
5
|
-
|
5
|
+
cmd_meta Kerbi::Consts::CommandSchemas::NEW_PROJECT
|
6
6
|
def new_project(project_name)
|
7
7
|
generator = Kerbi::CodeGen::ProjectGenerator.new(
|
8
8
|
project_name: project_name,
|
9
|
-
ruby_version:
|
9
|
+
ruby_version: run_opts.ruby_version,
|
10
10
|
verbose: true
|
11
11
|
)
|
12
12
|
success = generator.run
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
class ReleaseHandler < BaseHandler
|
4
|
+
|
5
|
+
cmd_meta Kerbi::Consts::CommandSchemas::INIT_RELEASE
|
6
|
+
# @param [String] release_name refers to a Kubernetes namespace
|
7
|
+
def init(release_name)
|
8
|
+
mem_release_name(release_name)
|
9
|
+
state_backend.provision_missing_resources(verbose: run_opts.verbose?)
|
10
|
+
ns_key = Kerbi::Consts::OptionSchemas::NAMESPACE
|
11
|
+
Kerbi::ConfigFile.patch({ns_key => release_name})
|
12
|
+
end
|
13
|
+
|
14
|
+
cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_STATUS
|
15
|
+
def status(release_name)
|
16
|
+
mem_release_name(release_name)
|
17
|
+
backend = state_backend
|
18
|
+
backend.test_connection(verbose: run_opts.verbose?)
|
19
|
+
end
|
20
|
+
|
21
|
+
cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_LIST
|
22
|
+
def list
|
23
|
+
prep_opts(Kerbi::Consts::OptionDefaults::LIST_STATE)
|
24
|
+
auth_bundle = Kerbi::Utils::Cli.make_k8s_auth_bundle(run_opts)
|
25
|
+
backends = Kerbi::State::ConfigMapBackend.releases(auth_bundle)
|
26
|
+
backends.each(&:prime)
|
27
|
+
echo_data(backends, serializer: Kerbi::Cli::ReleaseSerializer)
|
28
|
+
end
|
29
|
+
|
30
|
+
cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_DELETE
|
31
|
+
def delete(release_name)
|
32
|
+
mem_release_name(release_name)
|
33
|
+
backend = state_backend
|
34
|
+
return unless user_confirmed?
|
35
|
+
old_signature = backend.resource_signature
|
36
|
+
backend.delete
|
37
|
+
echo("Deleted #{old_signature}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Kerbi
|
2
|
+
module Cli
|
3
|
+
class ReleaseSerializer < Kerbi::Cli::BaseSerializer
|
4
|
+
has_attributes(
|
5
|
+
:name,
|
6
|
+
:backend,
|
7
|
+
:namespace,
|
8
|
+
:resource,
|
9
|
+
:states,
|
10
|
+
:latest
|
11
|
+
)
|
12
|
+
|
13
|
+
def name
|
14
|
+
object.release_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def backend
|
18
|
+
object.class.type_signature
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource
|
22
|
+
object.resource_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def states
|
26
|
+
if object.working?
|
27
|
+
object.entries.count
|
28
|
+
else
|
29
|
+
broken_txt
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def latest
|
34
|
+
if object.working?
|
35
|
+
object.entry_set.latest&.tag
|
36
|
+
else
|
37
|
+
broken_txt
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def broken_txt
|
42
|
+
"ERR"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/cli/root_handler.rb
CHANGED
@@ -2,6 +2,7 @@ module Kerbi
|
|
2
2
|
|
3
3
|
class Console
|
4
4
|
attr_reader :values
|
5
|
+
|
5
6
|
def initialize(values)
|
6
7
|
@values = values
|
7
8
|
end
|
@@ -12,36 +13,56 @@ module Kerbi
|
|
12
13
|
end
|
13
14
|
|
14
15
|
module Cli
|
15
|
-
|
16
16
|
##
|
17
17
|
# Top level CLI command handler with Thor.
|
18
18
|
class RootHandler < BaseHandler
|
19
19
|
|
20
|
-
|
20
|
+
##
|
21
|
+
# Two things happen here:
|
22
|
+
# 1. Kerbi::Globals.reset is necessary for testing, because memory
|
23
|
+
# is not flushed.
|
24
|
+
def self.start(*args, **kwargs)
|
25
|
+
begin
|
26
|
+
Kerbi::Globals.reset
|
27
|
+
super
|
28
|
+
rescue Kerbi::Error => e
|
29
|
+
#noinspection RubyResolve
|
30
|
+
puts e.to_s.colorize(:red).bold
|
31
|
+
end
|
32
|
+
end
|
21
33
|
|
22
|
-
|
34
|
+
cmd_meta Kerbi::Consts::CommandSchemas::TEMPLATE
|
23
35
|
# @param [String] release_name helm-like Kubernetes release name
|
24
|
-
|
25
|
-
|
26
|
-
utils::Cli.load_kerbifile(
|
27
|
-
values =
|
36
|
+
def template(release_name)
|
37
|
+
mem_release_name(release_name)
|
38
|
+
utils::Cli.load_kerbifile(run_opts.project_root)
|
39
|
+
values = compile_values
|
40
|
+
persist_compiled_values
|
28
41
|
mixer_classes = Kerbi::Globals.mixers
|
29
42
|
res_dicts = utils::Cli.run_mixers(mixer_classes, values, release_name)
|
30
|
-
|
43
|
+
echo_data(res_dicts, coerce_type: "Array")
|
31
44
|
end
|
32
45
|
|
33
|
-
|
46
|
+
cmd_meta Kerbi::Consts::CommandSchemas::CONSOLE
|
34
47
|
def console
|
35
|
-
utils::Cli.load_kerbifile(
|
36
|
-
values =
|
48
|
+
utils::Cli.load_kerbifile(run_opts.project_root)
|
49
|
+
values = compile_values
|
37
50
|
ARGV.clear
|
38
51
|
IRB.setup(eval("__FILE__"), argv: [])
|
39
52
|
workspace = IRB::WorkSpace.new(Console.new(values))
|
40
53
|
IRB::Irb.new(workspace).run(IRB.conf)
|
41
54
|
end
|
42
55
|
|
43
|
-
|
44
|
-
|
56
|
+
cmd_meta Kerbi::Consts::CommandSchemas::SHOW_VERSION
|
57
|
+
def version
|
58
|
+
puts "1"
|
59
|
+
end
|
60
|
+
|
61
|
+
sub_cmd_meta Kerbi::Consts::CommandSchemas::VALUES_SUPER, ValuesHandler
|
62
|
+
sub_cmd_meta Kerbi::Consts::CommandSchemas::PROJECT_SUPER, ProjectHandler
|
63
|
+
sub_cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_SUPER, ReleaseHandler
|
64
|
+
sub_cmd_meta Kerbi::Consts::CommandSchemas::STATE_SUPER, StateHandler
|
65
|
+
sub_cmd_meta Kerbi::Consts::CommandSchemas::CONFIG_SUPER, ConfigHandler
|
45
66
|
end
|
46
67
|
end
|
47
68
|
end
|