kerbi 0.0.4 → 0.0.10
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 +33 -2
- data/lib/cli/entry_serializers.rb +7 -0
- data/lib/cli/release_handler.rb +3 -3
- data/lib/cli/root_handler.rb +4 -5
- data/lib/cli/state_handler.rb +8 -8
- data/lib/cli/values_handler.rb +0 -1
- data/lib/code-gen/new-project/kerbifile.rb.erb +2 -1
- data/lib/config/cli_schema.rb +49 -33
- data/lib/config/config_file.rb +6 -5
- data/lib/config/globals.rb +8 -0
- data/lib/config/run_opts.rb +21 -7
- data/lib/config/state_consts.rb +2 -2
- data/lib/kerbi.rb +2 -0
- data/lib/main/mixer.rb +10 -4
- data/lib/mixins/entry_tag_logic.rb +3 -0
- data/lib/revision/fetcher.rb +15 -0
- data/lib/state/base_backend.rb +12 -1
- data/lib/state/config_map_backend.rb +9 -3
- data/lib/state/entry.rb +55 -2
- data/lib/state/entry_set.rb +22 -5
- data/lib/utils/cli.rb +10 -1
- data/spec/cli/release_handler_spec.rb +2 -1
- data/spec/cli/root_handler_spec.rb +7 -4
- data/spec/cli/state_handler_spec.rb +2 -2
- data/spec/cli/values_handler_spec.rb +0 -1
- data/spec/fixtures/expectations/release/delete.txt +1 -1
- data/spec/fixtures/expectations/release/init-already-existed.txt +1 -1
- data/spec/fixtures/expectations/release/init-both-created.txt +1 -1
- data/spec/fixtures/expectations/release/list.txt +3 -3
- data/spec/fixtures/expectations/release/status-all-working.txt +1 -1
- data/spec/fixtures/expectations/release/status-data-unreadable.txt +1 -1
- data/spec/fixtures/expectations/release/status-not-provisioned.txt +1 -1
- data/spec/fixtures/expectations/state/list.txt +5 -5
- data/spec/fixtures/expectations/state/show.txt +4 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/common/metadata.yaml.erb +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/consts.rb +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/helpers.rb +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/kerbifile.rb +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/pod-and-service.yaml.erb +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/values/production.yaml +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/values/v2.yaml +0 -0
- data/spec/{mini-projects → fixtures/mini-projects}/hello-kerbi/values/values.yaml +0 -0
- data/spec/main/configmap_backend_spec.rb +1 -1
- data/spec/main/state_entry_spec.rb +1 -0
- data/spec/spec_helper.rb +3 -1
- metadata +51 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54c442776af5f74fe8caac8eb74883a3e577f39077ea78972ee0fe0e19b5928
|
4
|
+
data.tar.gz: a7ad9356f2e18bc26d903f2e861a178efc41c6a468616db998dbf7041813eb71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04f5d11c0a023e23d294e41be06ca967ba61f7db97bff724b0c73ff37ec7c6f189988de7e8c57ba6993503403802cd69ee8188bd118ec90c65c1a34bd5f01cac
|
7
|
+
data.tar.gz: 6c5d3b70ccb829331666d581783a61c75b1d65de06cb4bd803ce1e5d60a7e44e4c2d797a9f1a27333e268acad2e0eb5d2b3e5aa4ed0f15dd47f3e19a16a453e4
|
data/lib/cli/base_handler.rb
CHANGED
@@ -15,8 +15,38 @@ module Kerbi
|
|
15
15
|
@_state_backend ||= generate_state_backend(**opts)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
##
|
19
|
+
# Sets two very commonly used variables in the run_opts
|
20
|
+
# object, available to all subclasses.
|
21
|
+
def mem_dna(release_name, project_uri=nil)
|
22
|
+
run_opts.release_name = release_name
|
23
|
+
run_opts.project_uri = project_uri
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform_templating
|
27
|
+
if run_opts.local_engine?
|
28
|
+
perform_local_templating
|
29
|
+
else
|
30
|
+
perform_remote_templating
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def perform_local_templating
|
35
|
+
Kerbi::Utils::Cli.run_mixers(
|
36
|
+
Kerbi::Globals.mixers,
|
37
|
+
compile_values,
|
38
|
+
run_opts.release_name
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform_remote_templating
|
43
|
+
Kerbi::Revision::Fetcher.post_template(
|
44
|
+
remote_engine_root_url,
|
45
|
+
run_opts.revision_tag
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def remote_engine_root_url
|
20
50
|
end
|
21
51
|
|
22
52
|
##
|
@@ -84,6 +114,7 @@ module Kerbi
|
|
84
114
|
|
85
115
|
fname_exprs = run_opts.fname_exprs
|
86
116
|
fname_exprs = ["values", *fname_exprs] if run_opts.load_defaults?
|
117
|
+
fname_exprs = fname_exprs.reject{ |f| f.start_with?("r:") }
|
87
118
|
|
88
119
|
file_values = utils.from_files(
|
89
120
|
fname_exprs,
|
@@ -43,6 +43,8 @@ module Kerbi
|
|
43
43
|
|
44
44
|
has_attributes(
|
45
45
|
:tag,
|
46
|
+
:release,
|
47
|
+
:revision,
|
46
48
|
:message,
|
47
49
|
:created_at,
|
48
50
|
:values,
|
@@ -54,6 +56,10 @@ module Kerbi
|
|
54
56
|
#noinspection RubyResolve
|
55
57
|
colored_tag.bold
|
56
58
|
end
|
59
|
+
|
60
|
+
def release
|
61
|
+
object&.set&.release_name
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
class EntryRowSerializer < Kerbi::Cli::BaseSerializer
|
@@ -61,6 +67,7 @@ module Kerbi
|
|
61
67
|
|
62
68
|
has_attributes(
|
63
69
|
:tag,
|
70
|
+
:revision,
|
64
71
|
:message,
|
65
72
|
:assignments,
|
66
73
|
:overrides,
|
data/lib/cli/release_handler.rb
CHANGED
@@ -5,7 +5,7 @@ module Kerbi
|
|
5
5
|
cmd_meta Kerbi::Consts::CommandSchemas::INIT_RELEASE
|
6
6
|
# @param [String] release_name refers to a Kubernetes namespace
|
7
7
|
def init(release_name)
|
8
|
-
|
8
|
+
mem_dna(release_name)
|
9
9
|
state_backend.provision_missing_resources(verbose: run_opts.verbose?)
|
10
10
|
ns_key = Kerbi::Consts::OptionSchemas::NAMESPACE
|
11
11
|
Kerbi::ConfigFile.patch({ns_key => release_name})
|
@@ -13,7 +13,7 @@ module Kerbi
|
|
13
13
|
|
14
14
|
cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_STATUS
|
15
15
|
def status(release_name)
|
16
|
-
|
16
|
+
mem_dna(release_name)
|
17
17
|
backend = state_backend
|
18
18
|
backend.test_connection(verbose: run_opts.verbose?)
|
19
19
|
end
|
@@ -29,7 +29,7 @@ module Kerbi
|
|
29
29
|
|
30
30
|
cmd_meta Kerbi::Consts::CommandSchemas::RELEASE_DELETE
|
31
31
|
def delete(release_name)
|
32
|
-
|
32
|
+
mem_dna(release_name)
|
33
33
|
backend = state_backend
|
34
34
|
return unless user_confirmed?
|
35
35
|
old_signature = backend.resource_signature
|
data/lib/cli/root_handler.rb
CHANGED
@@ -33,13 +33,12 @@ module Kerbi
|
|
33
33
|
|
34
34
|
cmd_meta Kerbi::Consts::CommandSchemas::TEMPLATE
|
35
35
|
# @param [String] release_name helm-like Kubernetes release name
|
36
|
-
|
37
|
-
|
36
|
+
# @param [String] project_uri local path like '.' or remote URI
|
37
|
+
def template(release_name, project_uri)
|
38
|
+
mem_dna(release_name, project_uri)
|
38
39
|
utils::Cli.load_kerbifile(run_opts.project_root)
|
39
|
-
|
40
|
+
res_dicts = perform_templating
|
40
41
|
persist_compiled_values
|
41
|
-
mixer_classes = Kerbi::Globals.mixers
|
42
|
-
res_dicts = utils::Cli.run_mixers(mixer_classes, values, release_name)
|
43
42
|
echo_data(res_dicts, coerce_type: "Array")
|
44
43
|
end
|
45
44
|
|
data/lib/cli/state_handler.rb
CHANGED
@@ -4,7 +4,7 @@ module Kerbi
|
|
4
4
|
cmd_meta Kerbi::Consts::CommandSchemas::LIST_STATE
|
5
5
|
def list(release_name)
|
6
6
|
prep_opts(Kerbi::Consts::OptionDefaults::LIST_STATE)
|
7
|
-
|
7
|
+
mem_dna(release_name)
|
8
8
|
echo_data(
|
9
9
|
state_backend.entries,
|
10
10
|
table_serializer: Kerbi::Cli::EntryRowSerializer,
|
@@ -16,7 +16,7 @@ module Kerbi
|
|
16
16
|
# @param [String] tag_expr e.g 1.9.1, @latest
|
17
17
|
def show(release_name, tag_expr)
|
18
18
|
prep_opts(Kerbi::Consts::OptionDefaults::LIST_STATE)
|
19
|
-
|
19
|
+
mem_dna(release_name)
|
20
20
|
entry = find_readable_entry(tag_expr)
|
21
21
|
echo_data(
|
22
22
|
entry,
|
@@ -29,7 +29,7 @@ module Kerbi
|
|
29
29
|
# @param [String] old_tag_expr e.g 1.9.1, @latest
|
30
30
|
# @param [String] new_tag_expr e.g 1.9.1, @latest
|
31
31
|
def retag(release_name, old_tag_expr, new_tag_expr)
|
32
|
-
|
32
|
+
mem_dna(release_name)
|
33
33
|
entry = find_readable_entry(old_tag_expr)
|
34
34
|
old_tag = entry.retag(new_tag_expr)
|
35
35
|
touch_and_save_entry(entry, tag: old_tag)
|
@@ -38,7 +38,7 @@ module Kerbi
|
|
38
38
|
cmd_meta Kerbi::Consts::CommandSchemas::PROMOTE_STATE
|
39
39
|
# @param [String] tag_expr e.g 1.9.1, @latest
|
40
40
|
def promote(release_name, tag_expr)
|
41
|
-
|
41
|
+
mem_dna(release_name)
|
42
42
|
entry = find_readable_entry(tag_expr)
|
43
43
|
old_name = entry.promote
|
44
44
|
touch_and_save_entry(entry, tag: old_name)
|
@@ -47,7 +47,7 @@ module Kerbi
|
|
47
47
|
cmd_meta Kerbi::Consts::CommandSchemas::DEMOTE_STATE
|
48
48
|
# @param [String] tag_expr e.g 1.9.1, @latest
|
49
49
|
def demote(release_name, tag_expr)
|
50
|
-
|
50
|
+
mem_dna(release_name)
|
51
51
|
entry = find_readable_entry(tag_expr)
|
52
52
|
old_name = entry.demote
|
53
53
|
touch_and_save_entry(entry, tag: old_name)
|
@@ -58,7 +58,7 @@ module Kerbi
|
|
58
58
|
# @param [String] attr_name e.g message
|
59
59
|
# @param [String] new_value e.g i am a new message
|
60
60
|
def set(release_name, tag_expr, attr_name, new_value)
|
61
|
-
|
61
|
+
mem_dna(release_name)
|
62
62
|
entry = find_readable_entry(tag_expr)
|
63
63
|
old_value = entry.assign_attr(attr_name, new_value)
|
64
64
|
touch_and_save_entry(entry, attr_name => old_value)
|
@@ -67,7 +67,7 @@ module Kerbi
|
|
67
67
|
cmd_meta Kerbi::Consts::CommandSchemas::DELETE_STATE
|
68
68
|
# @param [String] tag_expr e.g 1.9.1, @latest
|
69
69
|
def delete(release_name, tag_expr)
|
70
|
-
|
70
|
+
mem_dna(release_name)
|
71
71
|
entry = find_readable_entry(tag_expr)
|
72
72
|
state_backend.delete_entry(entry)
|
73
73
|
new_count = state_backend.entries.count
|
@@ -76,7 +76,7 @@ module Kerbi
|
|
76
76
|
|
77
77
|
cmd_meta Kerbi::Consts::CommandSchemas::PRUNE_CANDIDATES_STATE
|
78
78
|
def prune_candidates(release_name)
|
79
|
-
|
79
|
+
mem_dna(release_name)
|
80
80
|
old_count = entry_set.entries.count
|
81
81
|
entry_set.prune_candidates
|
82
82
|
state_backend.save
|
data/lib/cli/values_handler.rb
CHANGED
data/lib/config/cli_schema.rb
CHANGED
@@ -3,6 +3,8 @@ module Kerbi
|
|
3
3
|
|
4
4
|
module OptionKeys
|
5
5
|
PROJECT_ROOT = "project-root"
|
6
|
+
REVISION_TAG = "revision"
|
7
|
+
RELEASE_NAME = "release-name"
|
6
8
|
|
7
9
|
OUTPUT_FMT = "output-format"
|
8
10
|
INLINE_ASSIGNMENT = "inline-value"
|
@@ -66,22 +68,30 @@ module Kerbi
|
|
66
68
|
aliases: "-p"
|
67
69
|
}
|
68
70
|
|
71
|
+
REVISION_TAG = {
|
72
|
+
key: OptionKeys::REVISION_TAG,
|
73
|
+
desc: "Use this version of the Kerbi templating "\
|
74
|
+
"engine (given by [PROJECT_URI]).",
|
75
|
+
aliases: "-p"
|
76
|
+
}
|
77
|
+
|
69
78
|
K8S_AUTH_TYPE = {
|
70
79
|
key: OptionKeys::K8S_AUTH_TYPE,
|
71
|
-
desc: "
|
72
|
-
"
|
73
|
-
enum: %w[kube-config in-cluster
|
80
|
+
desc: "Kubernetes cluster authentication type. Uses " \
|
81
|
+
"kube-config if unspecified.",
|
82
|
+
enum: %w[kube-config in-cluster token]
|
74
83
|
}.freeze
|
75
84
|
|
76
85
|
KUBE_CONFIG_PATH = {
|
77
86
|
key: OptionKeys::KUBE_CONFIG_PATH,
|
78
|
-
desc: "
|
87
|
+
desc: "Path to your kube-config file. Uses " \
|
88
|
+
"~/.kube/config if unspecified."
|
79
89
|
}.freeze
|
80
90
|
|
81
91
|
KUBE_CONFIG_CONTEXT = {
|
82
92
|
key: OptionKeys::KUBE_CONFIG_CONTEXT,
|
83
|
-
desc: "
|
84
|
-
|
93
|
+
desc: "Context to use in your kube config. "\
|
94
|
+
"Uses current context if unspecified."
|
85
95
|
}.freeze
|
86
96
|
|
87
97
|
K8S_USERNAME = {
|
@@ -96,7 +106,7 @@ defaults to $(kubectl config current-context)"
|
|
96
106
|
|
97
107
|
LOAD_DEFAULT_VALUES = {
|
98
108
|
key: OptionKeys::LOAD_DEFAULT_VALUES,
|
99
|
-
desc: "
|
109
|
+
desc: "Whether or not to automatically load values.yaml.",
|
100
110
|
type: "boolean",
|
101
111
|
default: true
|
102
112
|
}.freeze
|
@@ -106,31 +116,35 @@ defaults to $(kubectl config current-context)"
|
|
106
116
|
desc: "Kubernetes auth bearer token for token auth"
|
107
117
|
}.freeze
|
108
118
|
|
119
|
+
RELEASE_NAME = {
|
120
|
+
key: OptionKeys::RELEASE_NAME,
|
121
|
+
desc: "Release name for commands where state I/O is optional"
|
122
|
+
}
|
123
|
+
|
109
124
|
STATE_BACKEND_TYPE = {
|
110
125
|
key: OptionKeys::STATE_BACKEND_TYPE,
|
111
|
-
desc: "
|
112
|
-
"values (configmap, secret)",
|
126
|
+
desc: "Type of persistent store to read/write this release's state.",
|
113
127
|
enum: %w[configmap secret]
|
114
128
|
}.freeze
|
115
129
|
|
116
130
|
OUTPUT_FMT = {
|
117
131
|
key: OptionKeys::OUTPUT_FMT,
|
118
132
|
aliases: "-o",
|
119
|
-
desc: "
|
133
|
+
desc: "In what format resulting data should be printed",
|
120
134
|
enum: %w[yaml json table]
|
121
135
|
}.freeze
|
122
136
|
|
123
137
|
INLINE_ASSIGNMENT = {
|
124
138
|
key: OptionKeys::INLINE_ASSIGNMENT,
|
125
139
|
aliases: "--set",
|
126
|
-
desc: "
|
127
|
-
"--set x.
|
140
|
+
desc: "Merge value from this assignment, "\
|
141
|
+
"e.g --set x.y=foo. Multiple --set are allowed.",
|
128
142
|
repeatable: true
|
129
143
|
}.freeze
|
130
144
|
|
131
145
|
READ_STATE = {
|
132
146
|
key: OptionKeys::READ_STATE,
|
133
|
-
desc: "Merge values from
|
147
|
+
desc: "Merge values from state with this tag.",
|
134
148
|
}.freeze
|
135
149
|
|
136
150
|
STRICT_READ_STATE = {
|
@@ -141,38 +155,41 @@ defaults to $(kubectl config current-context)"
|
|
141
155
|
|
142
156
|
WRITE_STATE = {
|
143
157
|
key: OptionKeys::WRITE_STATE,
|
144
|
-
desc: "
|
158
|
+
desc: "Write compiled values into new or existing state record" \
|
159
|
+
"with this tag."
|
145
160
|
}.freeze
|
146
161
|
|
147
162
|
NAMESPACE = {
|
148
163
|
key: OptionKeys::NAMESPACE,
|
149
164
|
aliases: "-n",
|
150
|
-
desc: "
|
151
|
-
|
165
|
+
desc: "Use this Kubernetes namespace instead of [RELEASE_NAME] "\
|
166
|
+
"for state I/O."
|
152
167
|
}.freeze
|
153
168
|
|
154
169
|
VALUE_FNAMES = {
|
155
170
|
key: OptionKeys::VALUE_FNAMES,
|
156
171
|
aliases: "-f",
|
157
|
-
desc: "
|
172
|
+
desc: "Merge all values read from this file. Multiple " \
|
173
|
+
"-f are allowed.",
|
158
174
|
repeatable: true
|
159
175
|
}.freeze
|
160
176
|
|
161
177
|
RUBY_VER = {
|
162
178
|
key: OptionKeys::RUBY_VER,
|
163
|
-
desc: "
|
179
|
+
desc: "Ruby version semver for autogenerated " \
|
180
|
+
"Gemfile."
|
164
181
|
}.freeze
|
165
182
|
|
166
183
|
VERBOSE = {
|
167
184
|
key: OptionKeys::VERBOSE,
|
168
185
|
desc: "Run in verbose mode",
|
169
|
-
|
186
|
+
type: "boolean"
|
170
187
|
}.freeze
|
171
188
|
|
172
189
|
PRE_CONFIRM = {
|
173
190
|
key: OptionKeys::PRE_CONFIRM,
|
174
|
-
desc: "Skip CLI confirmation",
|
175
|
-
|
191
|
+
desc: "Skip any CLI confirmation prompts",
|
192
|
+
type: "boolean"
|
176
193
|
}.freeze
|
177
194
|
|
178
195
|
KUBERNETES_OPTIONS = [
|
@@ -196,32 +213,32 @@ defaults to $(kubectl config current-context)"
|
|
196
213
|
|
197
214
|
VALUES_SUPER = {
|
198
215
|
name: "values",
|
199
|
-
desc: "Command group for values actions
|
216
|
+
desc: "Command group for values actions (see $ kerbi values help)"
|
200
217
|
}.freeze
|
201
218
|
|
202
219
|
PROJECT_SUPER = {
|
203
220
|
name: "project",
|
204
|
-
desc: "Command group for project actions
|
221
|
+
desc: "Command group for project actions (see $ kerbi project help)"
|
205
222
|
}.freeze
|
206
223
|
|
207
224
|
STATE_SUPER = {
|
208
225
|
name: "state",
|
209
|
-
desc: "Command group for state actions"
|
226
|
+
desc: "Command group for state actions (see $ kerbi state help)"
|
210
227
|
}.freeze
|
211
228
|
|
212
229
|
RELEASE_SUPER = {
|
213
230
|
name: "release",
|
214
|
-
desc: "Command group for release actions"
|
231
|
+
desc: "Command group for release actions (see $ kerbi release help)"
|
215
232
|
}.freeze
|
216
233
|
|
217
234
|
CONFIG_SUPER = {
|
218
235
|
name: "config",
|
219
|
-
desc: "Command group for config actions
|
236
|
+
desc: "Command group for config actions (see $ kerbi config help)"
|
220
237
|
}.freeze
|
221
238
|
|
222
239
|
TEMPLATE = {
|
223
|
-
name: "template [
|
224
|
-
desc: "
|
240
|
+
name: "template [RELEASE_NAME] [PROJECT_URI]",
|
241
|
+
desc: "Templates to YAML/JSON, using [RELEASE_NAME] for state I/O",
|
225
242
|
options: [
|
226
243
|
OptionSchemas::PROJECT_ROOT,
|
227
244
|
OptionSchemas::OUTPUT_FMT,
|
@@ -257,8 +274,7 @@ defaults to $(kubectl config current-context)"
|
|
257
274
|
|
258
275
|
RELEASE_STATUS = {
|
259
276
|
name: "status [RELEASE_NAME]",
|
260
|
-
desc: "
|
261
|
-
"state-tracking backend.",
|
277
|
+
desc: "Check readiness of release's ConfigMap/Secret backend.",
|
262
278
|
options: [
|
263
279
|
*OptionSchemas::KUBERNETES_OPTIONS,
|
264
280
|
OptionSchemas::VERBOSE
|
@@ -371,16 +387,16 @@ defaults to $(kubectl config current-context)"
|
|
371
387
|
|
372
388
|
SHOW_VERSION = {
|
373
389
|
name: "version",
|
374
|
-
desc: "Print kerbi version",
|
390
|
+
desc: "Print the kerbi gem's version.",
|
375
391
|
options: []
|
376
392
|
}.freeze
|
377
393
|
|
378
394
|
SHOW_VALUES = {
|
379
395
|
name: "show",
|
380
|
-
desc: "
|
396
|
+
desc: "Prints the final compiled values for the given sources",
|
381
397
|
options: [
|
382
|
-
OptionSchemas::PROJECT_ROOT,
|
383
398
|
OptionSchemas::OUTPUT_FMT,
|
399
|
+
OptionSchemas::PROJECT_ROOT,
|
384
400
|
*OptionSchemas::VALUES_OPTIONS,
|
385
401
|
*OptionSchemas::KUBERNETES_OPTIONS
|
386
402
|
]
|
data/lib/config/config_file.rb
CHANGED
@@ -3,7 +3,7 @@ module Kerbi
|
|
3
3
|
module ConfigFile
|
4
4
|
|
5
5
|
DIR_NAME = ".kerbi"
|
6
|
-
FILE_NAME = "config.
|
6
|
+
FILE_NAME = "config.json"
|
7
7
|
|
8
8
|
def self.file_path
|
9
9
|
"#{Dir.home}/#{DIR_NAME}/#{FILE_NAME}"
|
@@ -26,10 +26,11 @@ module Kerbi
|
|
26
26
|
def self.read
|
27
27
|
begin
|
28
28
|
create_file_if_missing
|
29
|
-
contents =
|
30
|
-
|
29
|
+
contents = File.read(file_path)
|
30
|
+
dict = JSON.parse(contents)
|
31
|
+
dict.slice(*legal_keys)
|
31
32
|
rescue StandardError => e
|
32
|
-
puts "[WARN] failed to read config #{file_path} (#{e})"
|
33
|
+
$stderr.puts "[WARN] failed to read config #{file_path} (#{e})"
|
33
34
|
{}
|
34
35
|
end
|
35
36
|
end
|
@@ -38,7 +39,7 @@ module Kerbi
|
|
38
39
|
def self.write(config, skip_check: false)
|
39
40
|
create_file_if_missing unless skip_check
|
40
41
|
config = config.deep_dup.stringify_keys.slice(*legal_keys)
|
41
|
-
File.write(file_path,
|
42
|
+
File.write(file_path, JSON.dump(config))
|
42
43
|
end
|
43
44
|
|
44
45
|
# @param [Hash] config
|
data/lib/config/globals.rb
CHANGED
data/lib/config/run_opts.rb
CHANGED
@@ -8,6 +8,7 @@ module Kerbi
|
|
8
8
|
|
9
9
|
attr_reader :options
|
10
10
|
attr_accessor :release_name
|
11
|
+
attr_accessor :project_uri
|
11
12
|
|
12
13
|
# @param [Hash{Symbol, Object}] cli_opts CLI args as a hash via Thor
|
13
14
|
# @param [Hash{Symbol, Object}] defaults contextual defaults (per cmd)
|
@@ -90,11 +91,6 @@ module Kerbi
|
|
90
91
|
write_state_to.present?
|
91
92
|
end
|
92
93
|
|
93
|
-
# @return [String]
|
94
|
-
def k8s_auth_type
|
95
|
-
options[consts::K8S_AUTH_TYPE]
|
96
|
-
end
|
97
|
-
|
98
94
|
# @return [String]
|
99
95
|
def kube_config_path
|
100
96
|
options[consts::KUBE_CONFIG_PATH]
|
@@ -138,12 +134,30 @@ module Kerbi
|
|
138
134
|
|
139
135
|
# @return [String]
|
140
136
|
def project_root
|
141
|
-
options[consts::PROJECT_ROOT].presence
|
137
|
+
options[consts::PROJECT_ROOT].presence || project_uri
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [?String]
|
141
|
+
def revision_tag
|
142
|
+
options[consts::REVISION_TAG].presence
|
143
|
+
end
|
144
|
+
|
145
|
+
def remote_engine?
|
146
|
+
revision_tag.present?
|
147
|
+
end
|
148
|
+
|
149
|
+
def local_engine?
|
150
|
+
!remote_engine?
|
151
|
+
end
|
152
|
+
|
153
|
+
# @return [String]
|
154
|
+
def k8s_auth_type
|
155
|
+
options[consts::K8S_AUTH_TYPE]
|
142
156
|
end
|
143
157
|
|
144
158
|
# @return [TrueClass, FalseClass]
|
145
159
|
def in_cluster?
|
146
|
-
|
160
|
+
k8s_auth_type == 'in-cluster'
|
147
161
|
end
|
148
162
|
|
149
163
|
# @return [TrueClass, FalseClass]
|
data/lib/config/state_consts.rb
CHANGED
data/lib/kerbi.rb
CHANGED
@@ -58,6 +58,8 @@ require_relative './state/base_backend'
|
|
58
58
|
require_relative './state/mixers'
|
59
59
|
require_relative './state/config_map_backend'
|
60
60
|
|
61
|
+
require_relative './revision/fetcher'
|
62
|
+
|
61
63
|
require_relative './main/errors'
|
62
64
|
require_relative './cli/base_handler'
|
63
65
|
require_relative './cli/config_handler'
|
data/lib/main/mixer.rb
CHANGED
@@ -12,6 +12,11 @@ module Kerbi
|
|
12
12
|
# @return [String] symbol-keyed hash
|
13
13
|
attr_reader :release_name
|
14
14
|
|
15
|
+
##
|
16
|
+
# Namespace (defaults to release_name) from CLI options
|
17
|
+
# @return [String] symbol-keyed hash
|
18
|
+
attr_reader :namespace
|
19
|
+
|
15
20
|
##
|
16
21
|
# Array of res-hashes being aggregated
|
17
22
|
# @return [Array<Hash>] list of hashes
|
@@ -27,12 +32,13 @@ module Kerbi
|
|
27
32
|
# @param [Hash] values the values tree that will be accessible to the subclass
|
28
33
|
def initialize(values, opts={})
|
29
34
|
@output = []
|
30
|
-
@release_name = opts[:release_name]
|
35
|
+
@release_name = opts[:release_name]
|
36
|
+
@namespace = opts[:namespace] || @release_name
|
31
37
|
@patch_stack = []
|
32
38
|
@values = self.class.compute_own_values_subtree(
|
33
39
|
values,
|
34
40
|
opts[:overwrite_values_root]
|
35
|
-
)
|
41
|
+
).freeze
|
36
42
|
end
|
37
43
|
|
38
44
|
##
|
@@ -107,7 +113,7 @@ module Kerbi
|
|
107
113
|
# @param [String] chart_id using format 'jetstack/cert-manager'
|
108
114
|
# @param [Hash] opts filtering and other options for #dicts
|
109
115
|
# @return [Array<Hash>] processed and filtered dicts
|
110
|
-
def
|
116
|
+
def helm_chart(chart_id, **opts)
|
111
117
|
release = opts[:release] || release_name
|
112
118
|
helm_output = Utils::Helm.template(release, chart_id, **opts)
|
113
119
|
dicts(helm_output)
|
@@ -131,7 +137,7 @@ module Kerbi
|
|
131
137
|
end
|
132
138
|
|
133
139
|
##
|
134
|
-
# Any x-to-dict statements (e.g #dicts, #dir, #
|
140
|
+
# Any x-to-dict statements (e.g #dicts, #dir, #helm_chart) executed
|
135
141
|
# in the &block passed to this method will have their return values
|
136
142
|
# deep merged with the dict(s) passed.
|
137
143
|
# @param [Array<Hash>|Hash] dict
|
@@ -13,16 +13,19 @@ module Kerbi
|
|
13
13
|
CANDIDATE_WORD = "candidate"
|
14
14
|
NEW_CANDIDATE_WORD = "new-candidate"
|
15
15
|
LATEST_WORD = "latest"
|
16
|
+
LATEST_PLUS_WORD = "latest+\\."
|
16
17
|
OLDEST_WORD = "oldest"
|
17
18
|
RANDOM_WORD = "random"
|
18
19
|
|
19
20
|
SPECIAL_READ_WORDS = [
|
20
21
|
CANDIDATE_WORD,
|
22
|
+
LATEST_PLUS_WORD,
|
21
23
|
LATEST_WORD,
|
22
24
|
OLDEST_WORD
|
23
25
|
]
|
24
26
|
|
25
27
|
SPECIAL_WRITE_WORDS = [
|
28
|
+
LATEST_PLUS_WORD,
|
26
29
|
LATEST_WORD,
|
27
30
|
OLDEST_WORD,
|
28
31
|
CANDIDATE_WORD,
|
data/lib/state/base_backend.rb
CHANGED
@@ -2,6 +2,14 @@ module Kerbi
|
|
2
2
|
module State
|
3
3
|
class BaseBackend
|
4
4
|
|
5
|
+
##
|
6
|
+
# Made available to states, as a convenience
|
7
|
+
# @return [String] release name
|
8
|
+
attr_reader :release_name
|
9
|
+
|
10
|
+
##
|
11
|
+
# Whether the last connection attempt succeeded or failed
|
12
|
+
# @return [TrueClass|FalseClass] list of hashes
|
5
13
|
attr_reader :is_working
|
6
14
|
|
7
15
|
def initialize(options={})
|
@@ -9,7 +17,10 @@ module Kerbi
|
|
9
17
|
|
10
18
|
# @return [Kerbi::State::EntrySet]
|
11
19
|
def entry_set
|
12
|
-
@_entry_set ||= EntrySet.new(
|
20
|
+
@_entry_set ||= EntrySet.new(
|
21
|
+
read_entries,
|
22
|
+
release_name: release_name
|
23
|
+
)
|
13
24
|
end
|
14
25
|
|
15
26
|
# @return [Array<Kerbi::State::Entry>]
|