kerbi 0.0.2 → 0.0.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/cli/base_handler.rb +18 -4
- data/lib/cli/release_handler.rb +41 -0
- data/lib/cli/release_serializer.rb +46 -0
- data/lib/cli/root_handler.rb +2 -0
- data/lib/cli/state_handler.rb +16 -23
- 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 +70 -27
- data/lib/config/run_opts.rb +13 -1
- data/lib/config/state_consts.rb +1 -0
- data/lib/kerbi.rb +4 -1
- data/lib/main/code_gen.rb +1 -1
- data/lib/main/errors.rb +6 -0
- data/lib/mixins/cli_state_helpers.rb +5 -33
- data/lib/mixins/cm_backend_testing.rb +18 -4
- data/lib/state/base_backend.rb +34 -0
- data/lib/state/config_map_backend.rb +71 -17
- data/lib/state/resources.yaml.erb +3 -3
- data/lib/utils/cli.rb +32 -0
- data/spec/cli/config_handler_spec.rb +32 -32
- data/spec/cli/release_handler_spec.rb +127 -0
- data/spec/cli/root_handler_spec.rb +12 -11
- data/spec/cli/state_handler_spec.rb +21 -52
- data/spec/{expectations → fixtures/expectations}/common/bad-tag.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/config/bad-set.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/config/set.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/config/show-default.yaml +0 -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/{expectations/state → fixtures/expectations/release}/status-all-working.txt +2 -1
- data/spec/fixtures/expectations/release/status-data-unreadable.txt +5 -0
- data/spec/{expectations/state → fixtures/expectations/release}/status-not-provisioned.txt +2 -1
- data/spec/{expectations → fixtures/expectations}/root/template-inlines.yaml +2 -2
- data/spec/{expectations → fixtures/expectations}/root/template-production.yaml +2 -2
- data/spec/{expectations → fixtures/expectations}/root/template-read-inlines.yaml +4 -4
- data/spec/{expectations → fixtures/expectations}/root/template-read.yaml +4 -4
- data/spec/{expectations → fixtures/expectations}/root/template-write.yaml +4 -4
- data/spec/{expectations → fixtures/expectations}/root/template.yaml +2 -2
- data/spec/{expectations → fixtures/expectations}/root/values.json +0 -0
- data/spec/{expectations → fixtures/expectations}/state/delete.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/demote.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/list.json +0 -0
- data/spec/{expectations → fixtures/expectations}/state/list.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/list.yaml +0 -0
- data/spec/{expectations → fixtures/expectations}/state/promote.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/prune-candidates.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/retag.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/set.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/show.json +0 -0
- data/spec/{expectations → fixtures/expectations}/state/show.txt +0 -0
- data/spec/{expectations → fixtures/expectations}/state/show.yaml +0 -0
- data/spec/{expectations → fixtures/expectations}/values/order-of-precedence.yaml +0 -0
- data/spec/main/configmap_backend_spec.rb +14 -13
- data/spec/main/project_code_gen_spec.rb +8 -2
- 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 +67 -11
- data/spec/utils/helm_spec.rb +89 -89
- data/spec/utils/k8s_auth_spec.rb +28 -28
- metadata +87 -61
- data/boilerplate/kerbifile.rb.erb +0 -9
- data/boilerplate/values.yaml.erb +0 -1
- data/spec/expectations/state/init-already-existed.txt +0 -2
- data/spec/expectations/state/init-both-created.txt +0 -2
@@ -20,11 +20,12 @@ module Kerbi
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def read_write_ready?
|
23
|
-
namespace_exists? &&
|
23
|
+
namespace_exists? && \
|
24
|
+
resource_exists? && \
|
25
|
+
data_readable?
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_connection(options={})
|
27
|
-
res_name = Kerbi::State::Consts::RESOURCE_NAME
|
28
29
|
exceptions = []
|
29
30
|
|
30
31
|
schema = [
|
@@ -42,7 +43,11 @@ module Kerbi
|
|
42
43
|
},
|
43
44
|
{
|
44
45
|
method: :load_resource,
|
45
|
-
message: "4. Resource #{namespace}/cm/#{
|
46
|
+
message: "4. Resource #{namespace}/cm/#{cm_name} exists"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
method: :entries,
|
50
|
+
message: "5. Data from resource is readable"
|
46
51
|
}
|
47
52
|
]
|
48
53
|
|
@@ -57,9 +62,12 @@ module Kerbi
|
|
57
62
|
end
|
58
63
|
|
59
64
|
if exceptions.any? && options[:verbose]
|
65
|
+
#noinspection RubyResolve
|
60
66
|
puts "\n---EXCEPTIONS---\n".colorize(:red).bold
|
61
67
|
exceptions.each do |exc|
|
62
|
-
|
68
|
+
base = "[#{exc[:test]}] #{exc[:exception]}"
|
69
|
+
#noinspection RubyResolve
|
70
|
+
puts base.to_s.colorize(:red).bold
|
63
71
|
puts exc[:exception].backtrace
|
64
72
|
puts "\n\n"
|
65
73
|
end
|
@@ -67,6 +75,7 @@ module Kerbi
|
|
67
75
|
end
|
68
76
|
|
69
77
|
def test_list_namespaces
|
78
|
+
#noinspection RubyResolve
|
70
79
|
client("v1").get_namespaces.any?
|
71
80
|
end
|
72
81
|
|
@@ -74,6 +83,10 @@ module Kerbi
|
|
74
83
|
client.get_namespace namespace
|
75
84
|
end
|
76
85
|
|
86
|
+
def data_readable?
|
87
|
+
entries.is_a?(Array)
|
88
|
+
end
|
89
|
+
|
77
90
|
#noinspection RubyResolve
|
78
91
|
def puts_outcome(msg, result)
|
79
92
|
outcome_str = result.present? ? "Success" : "Failure"
|
@@ -87,6 +100,7 @@ module Kerbi
|
|
87
100
|
outcome_str = result.present? ? "Already existed" : "Created"
|
88
101
|
color = result.present? ? :green : :blue
|
89
102
|
outcome_str = outcome_str.colorize(color)
|
103
|
+
#noinspection RubyResolve
|
90
104
|
puts "#{msg}: #{outcome_str}".bold
|
91
105
|
end
|
92
106
|
end
|
data/lib/state/base_backend.rb
CHANGED
@@ -2,6 +2,8 @@ module Kerbi
|
|
2
2
|
module State
|
3
3
|
class BaseBackend
|
4
4
|
|
5
|
+
attr_reader :is_working
|
6
|
+
|
5
7
|
def initialize(options={})
|
6
8
|
end
|
7
9
|
|
@@ -30,6 +32,34 @@ module Kerbi
|
|
30
32
|
@_resource = nil
|
31
33
|
end
|
32
34
|
|
35
|
+
def delete
|
36
|
+
delete_resource
|
37
|
+
end
|
38
|
+
|
39
|
+
def resource_signature
|
40
|
+
raise NotImplementedError
|
41
|
+
end
|
42
|
+
|
43
|
+
def prime
|
44
|
+
begin
|
45
|
+
resource
|
46
|
+
entries
|
47
|
+
@is_working = true
|
48
|
+
rescue
|
49
|
+
@is_working = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [TrueClass|FalseClass]
|
54
|
+
def working?
|
55
|
+
prime if @is_working.nil?
|
56
|
+
@is_working
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.type_signature
|
60
|
+
raise NotImplementedError
|
61
|
+
end
|
62
|
+
|
33
63
|
protected
|
34
64
|
|
35
65
|
def resource
|
@@ -49,6 +79,10 @@ module Kerbi
|
|
49
79
|
raise NotImplementedError
|
50
80
|
end
|
51
81
|
|
82
|
+
def delete_resource
|
83
|
+
raise NotImplementedError
|
84
|
+
end
|
85
|
+
|
52
86
|
private
|
53
87
|
|
54
88
|
def utils
|
@@ -9,13 +9,15 @@ module Kerbi
|
|
9
9
|
include Kerbi::Mixins::CmBackendTesting
|
10
10
|
|
11
11
|
attr_reader :auth_bundle
|
12
|
+
attr_reader :release_name
|
12
13
|
attr_reader :namespace
|
13
14
|
|
14
15
|
# @param [Hash] auth_bundle generated by Kerbi::Utils::K8sAuth
|
15
|
-
# @param [String]
|
16
|
-
def initialize(auth_bundle, namespace)
|
16
|
+
# @param [String] release_name Kubernetes namespace where configmap lives
|
17
|
+
def initialize(auth_bundle, release_name, namespace)
|
17
18
|
@auth_bundle = auth_bundle.freeze
|
18
|
-
@
|
19
|
+
@release_name = release_name.freeze
|
20
|
+
@namespace = (namespace || @release_name).freeze
|
19
21
|
end
|
20
22
|
|
21
23
|
##
|
@@ -41,9 +43,16 @@ module Kerbi
|
|
41
43
|
# of its contents. This method doesn't actually get used outside
|
42
44
|
# of rspec, but it's super useful there so keeping for time being.
|
43
45
|
# @param [Hash] resource_desc
|
44
|
-
def apply_resource(resource_desc)
|
45
|
-
|
46
|
-
|
46
|
+
def apply_resource(resource_desc, mode: 'create')
|
47
|
+
if mode == 'create'
|
48
|
+
#noinspection RubyResolve
|
49
|
+
client("v1").create_config_map(resource_desc)
|
50
|
+
elsif mode == 'update'
|
51
|
+
#noinspection RubyResolve
|
52
|
+
client("v1").update_config_map(resource_desc)
|
53
|
+
else
|
54
|
+
raise "What kind of sick mode is #{mode}?"
|
55
|
+
end
|
47
56
|
end
|
48
57
|
|
49
58
|
##
|
@@ -52,21 +61,32 @@ module Kerbi
|
|
52
61
|
# @param [Array<Kerbi::State::Entry>] entries
|
53
62
|
# @return [Hash]
|
54
63
|
def template_resource(entries)
|
55
|
-
values = {
|
56
|
-
|
57
|
-
|
64
|
+
values = {
|
65
|
+
consts::ENTRIES_ATTR => entries.map(&:to_h),
|
66
|
+
namespace: namespace,
|
67
|
+
cm_name: cm_name
|
68
|
+
}
|
69
|
+
Kerbi::State::ConfigMapMixer.new(values).run.first
|
58
70
|
end
|
59
71
|
|
60
72
|
##
|
61
73
|
# Creates the required namespace resource for this configmap
|
62
74
|
# in the cluster.
|
63
75
|
def create_namespace
|
64
|
-
|
65
|
-
dict = Kerbi::State::NamespaceMixer.new(
|
76
|
+
values = { namespace: namespace }
|
77
|
+
dict = Kerbi::State::NamespaceMixer.new(values).run.first
|
66
78
|
#noinspection RubyResolve
|
67
79
|
client("v1").create_namespace(dict)
|
68
80
|
end
|
69
81
|
|
82
|
+
def resource_name
|
83
|
+
cm_name
|
84
|
+
end
|
85
|
+
|
86
|
+
def resource_signature
|
87
|
+
"configmaps/#{namespace}/#{resource_name}"
|
88
|
+
end
|
89
|
+
|
70
90
|
protected
|
71
91
|
|
72
92
|
##
|
@@ -76,6 +96,13 @@ module Kerbi
|
|
76
96
|
client("v1").get_config_map(cm_name, namespace).to_h
|
77
97
|
end
|
78
98
|
|
99
|
+
##
|
100
|
+
# Reads the configmap from Kubernetes, returns its dict representation.
|
101
|
+
def delete_resource
|
102
|
+
#noinspection RubyResolve
|
103
|
+
client("v1").delete_config_map(cm_name, namespace)
|
104
|
+
end
|
105
|
+
|
79
106
|
##
|
80
107
|
# Templates the updated version of the configmap given the entries
|
81
108
|
# in memory, and uses the new dict to overwrite the last configmap
|
@@ -91,7 +118,7 @@ module Kerbi
|
|
91
118
|
# #resources, which is memoized, so may trigger a cluster read.
|
92
119
|
# @return [Array<Hash>] entries
|
93
120
|
def read_entries
|
94
|
-
str_entries = resource[:data][
|
121
|
+
str_entries = resource[:data][consts::ENTRIES_ATTR]
|
95
122
|
JSON.parse(str_entries)
|
96
123
|
end
|
97
124
|
|
@@ -100,6 +127,36 @@ module Kerbi
|
|
100
127
|
# like appsV1 (defaults to "v1" if not passed).
|
101
128
|
# @return [Kubeclient::Client]
|
102
129
|
def client(api_name="v1")
|
130
|
+
self.class.make_client(auth_bundle, api_name)
|
131
|
+
end
|
132
|
+
|
133
|
+
def consts
|
134
|
+
Kerbi::State::Consts
|
135
|
+
end
|
136
|
+
|
137
|
+
def cm_name
|
138
|
+
self.class.mk_cm_name(release_name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.releases(auth_bundle)
|
142
|
+
client = make_client(auth_bundle, "v1")
|
143
|
+
res_dicts = client.get_config_maps.map(&:to_h).select do |res_dict|
|
144
|
+
name = res_dict.dig(:metadata, :name)
|
145
|
+
name =~ Kerbi::State::Consts::CM_REGEX
|
146
|
+
end
|
147
|
+
|
148
|
+
res_dicts.map do |res_dict|
|
149
|
+
name, namespace = res_dict[:metadata].values_at(:name, :namespace)
|
150
|
+
release = name.match(Kerbi::State::Consts::CM_REGEX)[1]
|
151
|
+
self.new(auth_bundle, release, namespace)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.mk_cm_name(release_name)
|
156
|
+
"kerbi-#{release_name}-state-tracker"
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.make_client(auth_bundle, api_name)
|
103
160
|
Kubeclient::Client.new(
|
104
161
|
auth_bundle[:endpoint],
|
105
162
|
api_name,
|
@@ -107,13 +164,10 @@ module Kerbi
|
|
107
164
|
)
|
108
165
|
end
|
109
166
|
|
110
|
-
def
|
111
|
-
|
167
|
+
def self.type_signature
|
168
|
+
"ConfigMap"
|
112
169
|
end
|
113
170
|
|
114
|
-
def cm_name
|
115
|
-
consts::RESOURCE_NAME
|
116
|
-
end
|
117
171
|
end
|
118
172
|
end
|
119
173
|
end
|
@@ -5,8 +5,8 @@
|
|
5
5
|
apiVersion: v1
|
6
6
|
kind: ConfigMap
|
7
7
|
metadata:
|
8
|
-
name: <%=
|
9
|
-
namespace: <%=
|
8
|
+
name: <%= values[:cm_name] %>
|
9
|
+
namespace: <%= values[:namespace] %>
|
10
10
|
data: <%= embed({consts::ENTRIES_ATTR => entries_json}) %>
|
11
11
|
|
12
12
|
---
|
@@ -14,4 +14,4 @@ data: <%= embed({consts::ENTRIES_ATTR => entries_json}) %>
|
|
14
14
|
apiVersion: v1
|
15
15
|
kind: Namespace
|
16
16
|
metadata:
|
17
|
-
name: <%=
|
17
|
+
name: <%= values[:namespace] %>
|
data/lib/utils/cli.rb
CHANGED
@@ -105,6 +105,38 @@ module Kerbi
|
|
105
105
|
load(abs_path)
|
106
106
|
end
|
107
107
|
|
108
|
+
##
|
109
|
+
# Given the various Kubernetes authentication options and
|
110
|
+
# configs, generates a Hash with the necessary data/schema
|
111
|
+
# to pass onto the internal k8s authentication logic.
|
112
|
+
#
|
113
|
+
# This method only delegates. Actual work done is done here at:
|
114
|
+
# Kerbi::Utils::K8sAuth.
|
115
|
+
# @return [Hash] auth bundle for the k8s authentication logic.
|
116
|
+
# @param [Kerbi::RunOpts] run_opts
|
117
|
+
def self.make_k8s_auth_bundle(run_opts)
|
118
|
+
case run_opts.k8s_auth_type
|
119
|
+
when "kube-config"
|
120
|
+
Kerbi::Utils::K8sAuth.kube_config_bundle(
|
121
|
+
path: run_opts.kube_config_path,
|
122
|
+
name: run_opts.kube_context_name
|
123
|
+
)
|
124
|
+
when "basic"
|
125
|
+
Kerbi::Utils::K8sAuth.basic_auth_bundle(
|
126
|
+
username: run_opts.k8s_auth_username,
|
127
|
+
password: run_opts.k8s_auth_password
|
128
|
+
)
|
129
|
+
when "token"
|
130
|
+
Kerbi::Utils::K8sAuth.token_auth_bundle(
|
131
|
+
bearer_token: run_opts.k8s_auth_token,
|
132
|
+
)
|
133
|
+
when "in-cluster"
|
134
|
+
Kerbi::Utils::K8sAuth.in_cluster_auth_bundle
|
135
|
+
else
|
136
|
+
raise "Bad k8s connect type '#{run_opts.k8s_auth_type}'"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
108
140
|
LIST_TABLE_STYLE = {
|
109
141
|
border_left: false,
|
110
142
|
border_right: false,
|
@@ -2,37 +2,37 @@ require_relative './../spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe "$ kerbi config [COMMAND]" do
|
4
4
|
|
5
|
-
before(:each) { Kerbi::ConfigFile.reset }
|
6
|
-
|
7
|
-
describe "$ kerbi config show" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "$ kerbi config set [ATTR] [VALUE]" do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "$ kerbi config get [ATTR]" do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
5
|
+
# before(:each) { Kerbi::ConfigFile.reset }
|
6
|
+
#
|
7
|
+
# describe "$ kerbi config show" do
|
8
|
+
# it "outputs the expected text" do
|
9
|
+
# exp_cli_eq_file("config show", "config", "show-default", "yaml")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# describe "$ kerbi config set [ATTR] [VALUE]" do
|
14
|
+
# let(:cmd) { "config set namespace kerbi-spec" }
|
15
|
+
# context "for a legal assignment" do
|
16
|
+
# it "outputs the expected text and changes the value" do
|
17
|
+
# exp_cli_eq_file(cmd, "config", "set", "txt")
|
18
|
+
# new_value = Kerbi::ConfigFile.read["namespace"]
|
19
|
+
# expect(new_value).to eq("kerbi-spec")
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# context "for an illegal assignment" do
|
23
|
+
# let(:cmd){ "config set bad-key fail" }
|
24
|
+
# it "outputs the expected error message" do
|
25
|
+
# exp_cli_eq_file(cmd, "config", "bad-set", "txt")
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# describe "$ kerbi config get [ATTR]" do
|
31
|
+
# let(:cmd) { "config get namespace" }
|
32
|
+
# it "outputs the expected text and changes the value" do
|
33
|
+
# cli("config set namespace kerbi-spec")
|
34
|
+
# expect(cli(cmd).gsub(/\s+/, "")).to eq("kerbi-spec")
|
35
|
+
# end
|
36
|
+
# end
|
37
37
|
|
38
38
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require_relative './../spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "$ kerbi release [COMMAND]" do
|
4
|
+
|
5
|
+
let(:namespace) { "kerbi-spec" }
|
6
|
+
let(:release_name) { "kerbi-spec" }
|
7
|
+
let(:cm_name) { Kerbi::State::ConfigMapBackend.mk_cm_name(release_name) }
|
8
|
+
let(:exps_dir) { "release" }
|
9
|
+
|
10
|
+
let(:set) do
|
11
|
+
new_state_set(
|
12
|
+
one: { values: {x: "x"}, created_at: Time.new(2000).to_s },
|
13
|
+
two: { message: "message", created_at: Time.new(2001).to_s },
|
14
|
+
"[cand]-three".to_sym => { created_at: Time.new(2002).to_s },
|
15
|
+
"[cand]-four".to_sym => { created_at: Time.new(2003).to_s }
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
create_ns(release_name)
|
21
|
+
delete_cm(cm_name, namespace)
|
22
|
+
backend = make_backend(release_name, namespace)
|
23
|
+
configmap_dict = backend.template_resource(set.entries)
|
24
|
+
backend.apply_resource(configmap_dict)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "$ kerbi release init [RELEASE_NAME]" do
|
28
|
+
let(:cmd) { "release init #{release_name}" }
|
29
|
+
context "when resources already existed" do
|
30
|
+
it "echoes the correct text" do
|
31
|
+
exp_cli_eq_file(cmd, exps_dir, "init-already-existed")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the resources did not exist" do
|
36
|
+
it "echoes the correct text" do
|
37
|
+
delete_ns(namespace)
|
38
|
+
exp_cli_eq_file(cmd, exps_dir, "init-both-created")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "$ kerbi release delete [RELEASE_NAME]" do
|
44
|
+
before :each do
|
45
|
+
backend = make_backend(release_name, namespace)
|
46
|
+
backend.provision_missing_resources
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:cmd) { "release delete #{release_name} " \
|
50
|
+
"--namespace #{namespace} " \
|
51
|
+
"--confirm"
|
52
|
+
}
|
53
|
+
|
54
|
+
it "deletes the resource" do
|
55
|
+
backend = make_backend(release_name, namespace)
|
56
|
+
expect(backend.read_write_ready?).to eq(true)
|
57
|
+
backend = make_backend(release_name, namespace)
|
58
|
+
exp_cli_eq_file(cmd, exps_dir, "delete")
|
59
|
+
expect(backend.read_write_ready?).to eq(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "$ kerbi release status [RELEASE_NAME]" do
|
64
|
+
let(:cmd) { "release status #{release_name}" }
|
65
|
+
context "when resources are provisioned" do
|
66
|
+
context "when the data is readable" do
|
67
|
+
it "echoes the correct text" do
|
68
|
+
exp_cli_eq_file(cmd, exps_dir, "status-all-working")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "when the data is not readable" do
|
72
|
+
it "echoes the correct text" do
|
73
|
+
backend = make_backend(release_name, namespace)
|
74
|
+
corrupt_cm(backend)
|
75
|
+
exp_cli_eq_file(cmd, exps_dir, "status-data-unreadable")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when connected but resources not provisioned" do
|
81
|
+
it "echoes the correct text" do
|
82
|
+
delete_ns(namespace)
|
83
|
+
exp_cli_eq_file(cmd, exps_dir, "status-not-provisioned")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "$ kerbi release list" do
|
89
|
+
|
90
|
+
before(:each) { delete_ns("kerbi-spec") }
|
91
|
+
|
92
|
+
def provision(release_name, namespace, entry_count)
|
93
|
+
backend = make_backend(release_name, namespace)
|
94
|
+
backend.provision_missing_resources(quiet: true)
|
95
|
+
expect(backend.read_write_ready?).to eq(true)
|
96
|
+
|
97
|
+
if entry_count >= 0
|
98
|
+
entries = []
|
99
|
+
entry_count.times do |i|
|
100
|
+
entries << new_state("#{i + 1}.0.0")
|
101
|
+
end
|
102
|
+
new_dict = backend.template_resource(entries)
|
103
|
+
backend.apply_resource(new_dict, mode: "update")
|
104
|
+
else
|
105
|
+
corrupt_cm(backend)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
before :all do
|
110
|
+
delete_ns("tuna")
|
111
|
+
delete_ns("macron")
|
112
|
+
|
113
|
+
provision("tuna", "tuna", 2)
|
114
|
+
provision("dirt", "tuna", -1)
|
115
|
+
provision("tuna", "macron", 0)
|
116
|
+
end
|
117
|
+
|
118
|
+
after :all do
|
119
|
+
delete_ns("tuna")
|
120
|
+
delete_ns("macron")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "works" do
|
124
|
+
exp_cli_eq_file("release list", exps_dir, "list")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -3,7 +3,7 @@ require 'io/console'
|
|
3
3
|
|
4
4
|
RSpec.describe "$ kerbi [COMMAND]" do
|
5
5
|
let(:namespace) { "kerbi-spec" }
|
6
|
-
let(:
|
6
|
+
let(:release_name) { "kerbi-spec" }
|
7
7
|
let(:exps_dir) { "root" }
|
8
8
|
let(:root_dir) { "#{__dir__}/../../examples/hello-kerbi" }
|
9
9
|
|
@@ -26,14 +26,13 @@ RSpec.describe "$ kerbi [COMMAND]" do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context "with
|
29
|
+
context "with state" do
|
30
30
|
|
31
|
-
let(:backend){ make_backend(namespace) }
|
31
|
+
let(:backend){ make_backend(release_name, namespace) }
|
32
32
|
|
33
33
|
before :each do
|
34
|
-
|
35
|
-
|
36
|
-
backend = make_backend(namespace)
|
34
|
+
create_ns(namespace)
|
35
|
+
delete_cm(backend.resource_name, namespace)
|
37
36
|
backend.provision_missing_resources(quiet: true)
|
38
37
|
end
|
39
38
|
|
@@ -43,8 +42,10 @@ RSpec.describe "$ kerbi [COMMAND]" do
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def template_write_cmd(pod_image)
|
46
|
-
base_cmd = "template
|
47
|
-
|
45
|
+
base_cmd = "template #{release_name} " \
|
46
|
+
"--set pod.image=#{pod_image}" \
|
47
|
+
" --write-state foo"
|
48
|
+
hello_kerbi(base_cmd)
|
48
49
|
end
|
49
50
|
|
50
51
|
context "with writing" do
|
@@ -81,15 +82,15 @@ RSpec.describe "$ kerbi [COMMAND]" do
|
|
81
82
|
|
82
83
|
context "without inline overrides" do
|
83
84
|
it "echos the expected text" do
|
84
|
-
cmd = hello_kerbi("template
|
85
|
+
cmd = hello_kerbi("template #{release_name} --read-state foo")
|
85
86
|
exp_cli_eq_file(cmd, "root", "template-read", "yaml")
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
90
|
context "with inline overrides" do
|
90
91
|
it "echos the expected text, preferring the inline over the state" do
|
91
|
-
base = "template
|
92
|
-
cmd = hello_kerbi(base
|
92
|
+
base = "template #{release_name} --read-state foo --set pod.image=busybox"
|
93
|
+
cmd = hello_kerbi(base)
|
93
94
|
exp_cli_eq_file(cmd, "root", "template-read-inlines", "yaml")
|
94
95
|
end
|
95
96
|
end
|