kerbi 0.0.2 → 0.0.6
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 +2 -1
- data/lib/kerbi.rb +4 -1
- data/lib/main/code_gen.rb +1 -1
- data/lib/main/errors.rb +6 -0
- data/lib/main/mixer.rb +8 -2
- 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 +72 -18
- 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 +128 -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
@@ -3,7 +3,8 @@ require_relative './../spec_helper'
|
|
3
3
|
RSpec.describe "$ kerbi state [COMMAND]" do
|
4
4
|
|
5
5
|
let(:namespace) { "kerbi-spec" }
|
6
|
-
let(:
|
6
|
+
let(:release_name) { "kerbi-spec" }
|
7
|
+
let(:cm_name) { Kerbi::State::ConfigMapBackend.mk_cm_name(release_name) }
|
7
8
|
let(:exps_dir) { "state" }
|
8
9
|
|
9
10
|
let(:set) do
|
@@ -16,67 +17,35 @@ RSpec.describe "$ kerbi state [COMMAND]" do
|
|
16
17
|
end
|
17
18
|
|
18
19
|
before :each do
|
19
|
-
|
20
|
-
|
21
|
-
backend = make_backend(namespace)
|
20
|
+
create_ns(release_name)
|
21
|
+
delete_cm(cm_name, namespace)
|
22
|
+
backend = make_backend(release_name, namespace)
|
22
23
|
configmap_dict = backend.template_resource(set.entries)
|
23
24
|
backend.apply_resource(configmap_dict)
|
24
25
|
end
|
25
26
|
|
26
|
-
describe "$ kerbi state
|
27
|
-
|
28
|
-
context "when resources already existed" do
|
29
|
-
it "echoes the correct text" do
|
30
|
-
exp_cli_eq_file(cmd, exps_dir, "init-already-existed")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when the resources did not exist" do
|
35
|
-
it "echoes the correct text" do
|
36
|
-
kmd("delete ns #{namespace}")
|
37
|
-
exp_cli_eq_file(cmd, exps_dir, "init-both-created")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "$ kerbi state status" do
|
43
|
-
let(:cmd) { "state status -n #{namespace}" }
|
44
|
-
context "when everything is ready" do
|
45
|
-
it "echoes the correct text" do
|
46
|
-
exp_cli_eq_file(cmd, exps_dir, "status-all-working")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when connected but resources not provisioned" do
|
51
|
-
it "echoes the correct text" do
|
52
|
-
kmd("delete ns #{namespace}")
|
53
|
-
exp_cli_eq_file(cmd, exps_dir, "status-not-provisioned")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "$ kerbi state list" do
|
59
|
-
cmd_group_spec("state list -n kerbi-spec", "state", "list")
|
27
|
+
describe "$ kerbi state list [RELEASE_NAME]" do
|
28
|
+
cmd_group_spec("state list kerbi-spec", "state", "list")
|
60
29
|
end
|
61
30
|
|
62
31
|
describe "$ kerbi state show [TAG]" do
|
63
32
|
cmd_group_spec(
|
64
|
-
"state show
|
33
|
+
"state show kerbi-spec one",
|
65
34
|
"state",
|
66
35
|
"show"
|
67
36
|
)
|
68
37
|
|
69
38
|
cmd_group_spec(
|
70
|
-
"state show
|
39
|
+
"state show kerbi-spec @oldest",
|
71
40
|
"state",
|
72
41
|
"show",
|
73
42
|
context_append: " using @oldest instead of a literal tag"
|
74
43
|
)
|
75
44
|
end
|
76
45
|
|
77
|
-
describe "$ kerbi state retag [OLD_TAG] [NEW_TAG]" do
|
46
|
+
describe "$ kerbi state retag [RELEASE_NAME] [OLD_TAG] [NEW_TAG]" do
|
78
47
|
def make_cmd(old_tag)
|
79
|
-
"state retag #{old_tag} born-again
|
48
|
+
"state retag #{namespace} #{old_tag} born-again"
|
80
49
|
end
|
81
50
|
|
82
51
|
context "when the old tag exists" do
|
@@ -100,37 +69,37 @@ RSpec.describe "$ kerbi state [COMMAND]" do
|
|
100
69
|
end
|
101
70
|
end
|
102
71
|
|
103
|
-
describe "$ kerbi state promote" do
|
104
|
-
let(:cmd) { "state promote
|
72
|
+
describe "$ kerbi state promote [RELEASE_NAME] [TAG]" do
|
73
|
+
let(:cmd) { "state promote #{release_name} @candidate" }
|
105
74
|
it "echos the expected text" do
|
106
75
|
exp_cli_eq_file(cmd, exps_dir, "promote")
|
107
76
|
end
|
108
77
|
end
|
109
78
|
|
110
|
-
describe "$ kerbi state demote" do
|
111
|
-
let(:cmd) { "state demote
|
79
|
+
describe "$ kerbi state demote [RELEASE_NAME] [TAG]" do
|
80
|
+
let(:cmd) { "state demote #{release_name} @latest" }
|
112
81
|
it "echos the expected text" do
|
113
82
|
exp_cli_eq_file(cmd, exps_dir, "demote")
|
114
83
|
end
|
115
84
|
end
|
116
85
|
|
117
|
-
describe "$ kerbi state set" do
|
118
|
-
let(:easy_part) { "state set @latest message" }
|
86
|
+
describe "$ kerbi state set [RELEASE_NAME] [TAG] [ATTR] [VAL]" do
|
87
|
+
let(:easy_part) { "state set #{release_name} @latest message" }
|
119
88
|
let(:cmd) { easy_part.split(" ") + ["new message", "-n", namespace] }
|
120
89
|
it "echos the expected text" do
|
121
90
|
exp_cli_eq_file(cmd, exps_dir, "set")
|
122
91
|
end
|
123
92
|
end
|
124
93
|
|
125
|
-
describe "$ kerbi state delete" do
|
126
|
-
let(:cmd) { "state delete
|
94
|
+
describe "$ kerbi state delete [RELEASE_NAME] [TAG]" do
|
95
|
+
let(:cmd) { "state delete #{release_name} @latest" }
|
127
96
|
it "echos the expected text" do
|
128
97
|
exp_cli_eq_file(cmd, exps_dir, "delete")
|
129
98
|
end
|
130
99
|
end
|
131
100
|
|
132
|
-
describe "$ kerbi state prune-candidates" do
|
133
|
-
let(:cmd) { "state prune-candidates
|
101
|
+
describe "$ kerbi state prune-candidates [RELEASE_NAME]" do
|
102
|
+
let(:cmd) { "state prune-candidates #{release_name}" }
|
134
103
|
it "echos the expected text" do
|
135
104
|
exp_cli_eq_file(cmd, exps_dir, "prune-candidates")
|
136
105
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Deleted configmaps/kerbi-spec/kerbi-kerbi-spec-db
|
@@ -1,4 +1,5 @@
|
|
1
1
|
\e[1;39;49m1. Create Kubernetes client: \e[0m\e[1;32;49mSuccess\e[0m
|
2
2
|
\e[1;39;49m2. List cluster namespaces: \e[0m\e[1;32;49mSuccess\e[0m
|
3
3
|
\e[1;39;49m3. Target namespace kerbi-spec exists: \e[0m\e[1;32;49mSuccess\e[0m
|
4
|
-
\e[1;39;49m4. Resource kerbi-spec/cm/kerbi-
|
4
|
+
\e[1;39;49m4. Resource kerbi-spec/cm/kerbi-kerbi-spec-db exists: \e[0m\e[1;32;49mSuccess\e[0m
|
5
|
+
\e[1;39;49m5. Data from resource is readable: \e[0m\e[1;32;49mSuccess\e[0m
|
@@ -0,0 +1,5 @@
|
|
1
|
+
\e[1;39;49m1. Create Kubernetes client: \e[0m\e[1;32;49mSuccess\e[0m
|
2
|
+
\e[1;39;49m2. List cluster namespaces: \e[0m\e[1;32;49mSuccess\e[0m
|
3
|
+
\e[1;39;49m3. Target namespace kerbi-spec exists: \e[0m\e[1;32;49mSuccess\e[0m
|
4
|
+
\e[1;39;49m4. Resource kerbi-spec/cm/kerbi-kerbi-spec-db exists: \e[0m\e[1;32;49mSuccess\e[0m
|
5
|
+
\e[1;39;49m5. Data from resource is readable: \e[0m\e[1;31;49mFailure\e[0m
|
@@ -1,4 +1,5 @@
|
|
1
1
|
\e[1;39;49m1. Create Kubernetes client: \e[0m\e[1;32;49mSuccess\e[0m
|
2
2
|
\e[1;39;49m2. List cluster namespaces: \e[0m\e[1;32;49mSuccess\e[0m
|
3
3
|
\e[1;39;49m3. Target namespace kerbi-spec exists: \e[0m\e[1;31;49mFailure\e[0m
|
4
|
-
\e[1;39;49m4. Resource kerbi-spec/cm/kerbi-
|
4
|
+
\e[1;39;49m4. Resource kerbi-spec/cm/kerbi-kerbi-spec-db exists: \e[0m\e[1;31;49mFailure\e[0m
|
5
|
+
\e[1;39;49m5. Data from resource is readable: \e[0m\e[1;31;49mFailure\e[0m
|
@@ -4,7 +4,7 @@ metadata:
|
|
4
4
|
name: hello-kerbi
|
5
5
|
namespace: foo
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -20,7 +20,7 @@ metadata:
|
|
20
20
|
name: hello-kerbi
|
21
21
|
namespace: foo
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
@@ -4,7 +4,7 @@ metadata:
|
|
4
4
|
name: hello-kerbi
|
5
5
|
namespace: foo
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -20,7 +20,7 @@ metadata:
|
|
20
20
|
name: hello-kerbi
|
21
21
|
namespace: foo
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
@@ -2,9 +2,9 @@ apiVersion: v1
|
|
2
2
|
kind: Pod
|
3
3
|
metadata:
|
4
4
|
name: hello-kerbi
|
5
|
-
namespace:
|
5
|
+
namespace: kerbi-spec
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -18,9 +18,9 @@ apiVersion: v1
|
|
18
18
|
kind: Service
|
19
19
|
metadata:
|
20
20
|
name: hello-kerbi
|
21
|
-
namespace:
|
21
|
+
namespace: kerbi-spec
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
@@ -2,9 +2,9 @@ apiVersion: v1
|
|
2
2
|
kind: Pod
|
3
3
|
metadata:
|
4
4
|
name: hello-kerbi
|
5
|
-
namespace:
|
5
|
+
namespace: kerbi-spec
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -18,9 +18,9 @@ apiVersion: v1
|
|
18
18
|
kind: Service
|
19
19
|
metadata:
|
20
20
|
name: hello-kerbi
|
21
|
-
namespace:
|
21
|
+
namespace: kerbi-spec
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
@@ -2,9 +2,9 @@ apiVersion: v1
|
|
2
2
|
kind: Pod
|
3
3
|
metadata:
|
4
4
|
name: hello-kerbi
|
5
|
-
namespace:
|
5
|
+
namespace: kerbi-spec
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -18,9 +18,9 @@ apiVersion: v1
|
|
18
18
|
kind: Service
|
19
19
|
metadata:
|
20
20
|
name: hello-kerbi
|
21
|
-
namespace:
|
21
|
+
namespace: kerbi-spec
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
@@ -4,7 +4,7 @@ metadata:
|
|
4
4
|
name: hello-kerbi
|
5
5
|
namespace: foo
|
6
6
|
annotations:
|
7
|
-
author:
|
7
|
+
author: person
|
8
8
|
labels:
|
9
9
|
app: hello-kerbi
|
10
10
|
spec:
|
@@ -20,7 +20,7 @@ metadata:
|
|
20
20
|
name: hello-kerbi
|
21
21
|
namespace: foo
|
22
22
|
annotations:
|
23
|
-
author:
|
23
|
+
author: person
|
24
24
|
labels:
|
25
25
|
app: hello-kerbi
|
26
26
|
spec:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -3,20 +3,20 @@ require_relative './../spec_helper'
|
|
3
3
|
RSpec.describe Kerbi::State::ConfigMapBackend do
|
4
4
|
|
5
5
|
let(:namespace) { "kerbi-spec" }
|
6
|
-
let(:cm_name) { Kerbi::State::
|
6
|
+
let(:cm_name) { Kerbi::State::ConfigMapBackend.mk_cm_name(namespace) }
|
7
7
|
|
8
8
|
before :each do
|
9
|
-
|
10
|
-
|
9
|
+
create_ns(namespace)
|
10
|
+
delete_cm(cm_name, namespace)
|
11
11
|
# sleep(2) #ADD ME BACK IF WEIRD ERRORS... :/
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#provision_missing_resources" do
|
15
|
-
let(:backend) { make_backend(namespace) }
|
15
|
+
let(:backend) { make_backend(namespace, namespace) }
|
16
16
|
|
17
17
|
context "when the namespace does not exist" do
|
18
18
|
it "provisions accordingly" do
|
19
|
-
|
19
|
+
delete_ns(namespace)
|
20
20
|
expect(backend.read_write_ready?).to be_falsey
|
21
21
|
backend.provision_missing_resources
|
22
22
|
end
|
@@ -24,14 +24,14 @@ RSpec.describe Kerbi::State::ConfigMapBackend do
|
|
24
24
|
|
25
25
|
context "when the namespace does exist" do
|
26
26
|
before :each do
|
27
|
-
|
27
|
+
create_ns(namespace)
|
28
28
|
expect(backend.read_write_ready?).to be_falsey
|
29
29
|
end
|
30
30
|
|
31
31
|
context "when the configmap does not exist" do
|
32
32
|
it "provisions accordingly" do
|
33
33
|
backend.provision_missing_resources
|
34
|
-
|
34
|
+
delete_cm(cm_name, namespace)
|
35
35
|
backend.provision_missing_resources
|
36
36
|
end
|
37
37
|
end
|
@@ -45,8 +45,8 @@ RSpec.describe Kerbi::State::ConfigMapBackend do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
after :each do
|
48
|
-
expect(backend.read_write_ready?).to eq(true)
|
49
48
|
expect(backend.namespace_exists?).to eq(true)
|
49
|
+
expect(backend.read_write_ready?).to eq(true)
|
50
50
|
expect(backend.resource_exists?).to eq(true)
|
51
51
|
end
|
52
52
|
end
|
@@ -55,9 +55,10 @@ RSpec.describe Kerbi::State::ConfigMapBackend do
|
|
55
55
|
context "with 0 entries" do
|
56
56
|
it "outputs a descriptor with the right basic properties" do
|
57
57
|
result = make_backend("xyz").template_resource([])
|
58
|
+
metadata = (result || {})[:metadata] || {}
|
58
59
|
expect(result[:kind]).to eq('ConfigMap')
|
59
|
-
expect(
|
60
|
-
expect(
|
60
|
+
expect(metadata[:name]).to eq('kerbi-xyz-db')
|
61
|
+
expect(metadata[:namespace]).to eq('xyz')
|
61
62
|
expect(result[:data][:entries]).to eq("[]")
|
62
63
|
end
|
63
64
|
end
|
@@ -75,12 +76,12 @@ RSpec.describe Kerbi::State::ConfigMapBackend do
|
|
75
76
|
describe "#namespace_exists?" do
|
76
77
|
context "when the namespace exists" do
|
77
78
|
it "returns true" do
|
78
|
-
expect(make_backend("default").namespace_exists?).to be_truthy
|
79
|
+
expect(make_backend('', "default").namespace_exists?).to be_truthy
|
79
80
|
end
|
80
81
|
end
|
81
82
|
context "when the namespace does not exist" do
|
82
83
|
it "returns false" do
|
83
|
-
expect(make_backend("nope").namespace_exists?).to be_falsey
|
84
|
+
expect(make_backend('', "nope").namespace_exists?).to be_falsey
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
@@ -94,7 +95,7 @@ RSpec.describe Kerbi::State::ConfigMapBackend do
|
|
94
95
|
end
|
95
96
|
|
96
97
|
it "creates a configmap with the right contents" do
|
97
|
-
subject = make_backend(namespace)
|
98
|
+
subject = make_backend(namespace, namespace)
|
98
99
|
descriptor = subject.template_resource(entries)
|
99
100
|
subject.apply_resource(descriptor)
|
100
101
|
sleep(1)
|
@@ -7,6 +7,13 @@ RSpec.describe Kerbi::CodeGen::ProjectGenerator do
|
|
7
7
|
let(:project_name) { "test-project" }
|
8
8
|
let(:dir_path) { "#{root}/#{project_name}" }
|
9
9
|
|
10
|
+
subject do
|
11
|
+
Kerbi::CodeGen::ProjectGenerator.new(
|
12
|
+
project_name: project_name,
|
13
|
+
root_dir: root
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
10
17
|
before :each do
|
11
18
|
Kerbi::Testing.reset_test_yamls_dir
|
12
19
|
end
|
@@ -15,8 +22,7 @@ RSpec.describe Kerbi::CodeGen::ProjectGenerator do
|
|
15
22
|
let(:expected_files) { %w[Gemfile kerbifile.rb values.yaml] }
|
16
23
|
it "creates a new dir and writes the files" do
|
17
24
|
expect(File.exists?(dir_path)).to be_falsey
|
18
|
-
|
19
|
-
generator.run
|
25
|
+
subject.run
|
20
26
|
expect(File.exists?(dir_path)).to be_truthy
|
21
27
|
actual = Dir.entries(dir_path)
|
22
28
|
expect((expected_files - actual)).to be_empty
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'consts'
|
2
|
+
require_relative 'helpers'
|
3
|
+
|
4
|
+
module HelloKerbi
|
5
|
+
class Mixer < Kerbi::Mixer
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
locate_self __dir__
|
9
|
+
|
10
|
+
def mix
|
11
|
+
patched_with file("common/metadata") do
|
12
|
+
push file("pod-and-service")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Kerbi::Globals.mixers << HelloKerbi::Mixer
|
@@ -0,0 +1,23 @@
|
|
1
|
+
apiVersion: v1
|
2
|
+
kind: Pod
|
3
|
+
metadata:
|
4
|
+
name: <%= HelloKerbi::Consts::APP_NAME %>
|
5
|
+
namespace: <%= release_name %>
|
6
|
+
spec:
|
7
|
+
containers:
|
8
|
+
- name: main
|
9
|
+
image: <%= img2alpine(values[:pod][:image]) %>
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
apiVersion: v1
|
14
|
+
kind: Service
|
15
|
+
metadata:
|
16
|
+
name: <%= HelloKerbi::Consts::APP_NAME %>
|
17
|
+
namespace: <%= release_name %>
|
18
|
+
spec:
|
19
|
+
type: <%= values[:service][:type] %>
|
20
|
+
selector:
|
21
|
+
app: <%= HelloKerbi::Consts::APP_NAME %>
|
22
|
+
ports:
|
23
|
+
- port: 80
|
data/spec/spec_helper.rb
CHANGED
@@ -5,19 +5,70 @@ SimpleCov.start
|
|
5
5
|
|
6
6
|
require_relative './../lib/kerbi'
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
system("kubectl #{command} --context kind-kind", **opts)
|
8
|
+
def run_opts
|
9
|
+
Kerbi::RunOpts.new({}, Kerbi::Consts::OptionDefaults::BASE)
|
11
10
|
end
|
12
11
|
|
12
|
+
# @param [String] namespace
|
13
13
|
# @return [Kerbi::State::ConfigMapBackend]
|
14
|
-
def make_backend(namespace)
|
15
|
-
Kerbi::
|
16
|
-
|
17
|
-
|
14
|
+
def make_backend(release_name, namespace=nil)
|
15
|
+
auth_bundle = Kerbi::Utils::Cli.make_k8s_auth_bundle(run_opts)
|
16
|
+
Kerbi::State::ConfigMapBackend.new(auth_bundle, release_name, namespace)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Kubeclient::Client]
|
20
|
+
def make_kube_client(api_name)
|
21
|
+
auth_bundle = Kerbi::Utils::Cli.make_k8s_auth_bundle(run_opts)
|
22
|
+
Kubeclient::Client.new(
|
23
|
+
auth_bundle[:endpoint],
|
24
|
+
api_name,
|
25
|
+
**auth_bundle[:options]
|
18
26
|
)
|
19
27
|
end
|
20
28
|
|
29
|
+
def create_ns(name)
|
30
|
+
dict = { metadata: { name: name } }
|
31
|
+
begin
|
32
|
+
#noinspection RubyResolve
|
33
|
+
make_kube_client("v1").create_namespace(dict)
|
34
|
+
rescue Kubeclient::HttpError
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_cm(name, namespace)
|
40
|
+
begin
|
41
|
+
#noinspection RubyResolve
|
42
|
+
make_kube_client("v1").delete_config_map(name, namespace)
|
43
|
+
begin
|
44
|
+
sleep(1)
|
45
|
+
#noinspection RubyResolve
|
46
|
+
exists = client.get_config_map(name, namespace) rescue nil
|
47
|
+
end while exists
|
48
|
+
rescue Kubeclient::ResourceNotFoundError
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_ns(name)
|
54
|
+
begin
|
55
|
+
#noinspection RubyResolve
|
56
|
+
(client = make_kube_client("v1")).delete_namespace(name)
|
57
|
+
begin
|
58
|
+
sleep(1)
|
59
|
+
exists = client.get_namespace(name) rescue nil
|
60
|
+
end while exists
|
61
|
+
rescue Kubeclient::ResourceNotFoundError
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def corrupt_cm(backend)
|
67
|
+
cm_body = backend.template_resource([])
|
68
|
+
cm_body[:data][:entries] = "not json"
|
69
|
+
backend.send(:client).update_config_map(cm_body)
|
70
|
+
end
|
71
|
+
|
21
72
|
def new_state(tag, dict={})
|
22
73
|
set = dict.delete(:state)
|
23
74
|
dict[:tag] = tag
|
@@ -43,7 +94,7 @@ def cli(command, escaped: false)
|
|
43
94
|
end
|
44
95
|
|
45
96
|
def load_exp_file(dir, file, ext)
|
46
|
-
path = "#{__dir__}/expectations/#{dir}/#{file}.#{ext}"
|
97
|
+
path = "#{__dir__}/fixtures/expectations/#{dir}/#{file}.#{ext}"
|
47
98
|
File.read(path)
|
48
99
|
end
|
49
100
|
|
@@ -65,8 +116,13 @@ def exp_cli_eq_file(cmd, dir, file, ext='txt')
|
|
65
116
|
if ext == 'json'
|
66
117
|
expect(JSON.parse(actual_str)).to eq(expected)
|
67
118
|
elsif ext == 'yaml'
|
68
|
-
actual = YAML.load_stream(actual_str)
|
69
|
-
|
119
|
+
actual = YAML.load_stream(actual_str) rescue 0
|
120
|
+
if actual != 0
|
121
|
+
expect(actual).to eq(expected)
|
122
|
+
else
|
123
|
+
puts actual_str
|
124
|
+
raise "CMD #{cmd} echoed non-YAML (above)"
|
125
|
+
end
|
70
126
|
else
|
71
127
|
actual = actual_str.gsub(/\s+/, "").gsub("\e", "\\e")
|
72
128
|
expect(actual).to eq(expected)
|
@@ -74,7 +130,7 @@ def exp_cli_eq_file(cmd, dir, file, ext='txt')
|
|
74
130
|
end
|
75
131
|
|
76
132
|
def hello_kerbi(cmd, namespace=nil)
|
77
|
-
target = "#{__dir__}
|
133
|
+
target = "#{__dir__}/mini-projects/hello-kerbi"
|
78
134
|
cmd = "#{cmd} --project-root #{target}"
|
79
135
|
cmd = "#{cmd} --namespace #{namespace}" if namespace
|
80
136
|
cmd
|