kube_cluster 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +27 -1
- data/kube_cluster.gemspec +1 -0
- data/lib/kube/cluster/standard/cdi/data_volume.rb +35 -0
- data/lib/kube/cluster/standard/cloud_native_pg/cluster.rb +27 -0
- data/lib/kube/cluster/standard/cloud_native_pg/database_with_external_secret.rb +44 -0
- data/lib/kube/cluster/standard/cloud_native_pg/external_secret.rb +57 -0
- data/lib/kube/cluster/standard/cloud_native_pg/helm.rb +27 -21
- data/lib/kube/cluster/standard/config_map.rb +45 -0
- data/lib/kube/cluster/standard/custom_resource_definition.rb +82 -0
- data/lib/kube/cluster/standard/daemon_set.rb +70 -0
- data/lib/kube/cluster/standard/deployment_with_service.rb +152 -0
- data/lib/kube/cluster/standard/env_processing.rb +42 -0
- data/lib/kube/cluster/standard/eso/external_secret.rb +96 -0
- data/lib/kube/cluster/standard/forgejo/helm.rb +64 -0
- data/lib/kube/cluster/standard/gateway_api/http_route.rb +33 -0
- data/lib/kube/cluster/standard/job.rb +50 -0
- data/lib/kube/cluster/standard/kube_virt/virtual_machine.rb +36 -0
- data/lib/kube/cluster/standard/meta_controller/composite_controller.rb +80 -0
- data/lib/kube/cluster/standard/meta_controller/decorator_controller.rb +79 -0
- data/lib/kube/cluster/standard/persistent_volume_claim.rb +37 -0
- data/lib/kube/cluster/standard/secret.rb +34 -0
- data/lib/kube/cluster/standard/service.rb +41 -0
- data/lib/kube/cluster/standard/volume_processing.rb +88 -0
- data/lib/kube/cluster/version.rb +1 -1
- data/lib/kube/cluster.rb +1 -0
- metadata +35 -2
- data/lib/kube/cluster/standard/cloud_native_pg.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28348c8c7bfb6bb1e1340efeba20451d4b29c11a8e75454e87d805e3b6c4b36f
|
|
4
|
+
data.tar.gz: c1aa1ee8775553e15026dce80414949bd57da1371dac6bda72766aeba117db1f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48d13d3cd9b6578d44d2007392f89d3c1a3ab0838e1fcde8825d86b1e8cfe263f538ff3b5f92bf70155273c4e58bc68d2d7212c75a6c16a3bf1c06c56c0d91d8
|
|
7
|
+
data.tar.gz: 8cba24053f71e5f4d9efd117c7a477b00b5cdba21b57f6a2afa88a53f632e93f26791d532bdde06d8842477d3e40b15a0c9434b4a50245bc94a3db357ffbab72
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
kube_cluster (0.
|
|
4
|
+
kube_cluster (0.8.0)
|
|
5
|
+
activesupport (~> 8.0)
|
|
5
6
|
kube_kubectl (~> 2.0)
|
|
6
7
|
kube_schema (~> 1.5)
|
|
7
8
|
scampi (~> 0.1)
|
|
@@ -9,6 +10,19 @@ PATH
|
|
|
9
10
|
GEM
|
|
10
11
|
remote: https://rubygems.org/
|
|
11
12
|
specs:
|
|
13
|
+
activesupport (8.1.3)
|
|
14
|
+
base64
|
|
15
|
+
bigdecimal
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
17
|
+
connection_pool (>= 2.2.5)
|
|
18
|
+
drb
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
json
|
|
21
|
+
logger (>= 1.4.2)
|
|
22
|
+
minitest (>= 5.1)
|
|
23
|
+
securerandom (>= 0.3)
|
|
24
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
25
|
+
uri (>= 0.13.1)
|
|
12
26
|
ast (2.4.3)
|
|
13
27
|
async (2.39.0)
|
|
14
28
|
console (~> 1.29)
|
|
@@ -60,12 +74,14 @@ GEM
|
|
|
60
74
|
bake-releases (0.5.4)
|
|
61
75
|
bake (~> 0.21)
|
|
62
76
|
markly (~> 0.8)
|
|
77
|
+
base64 (0.3.0)
|
|
63
78
|
bigdecimal (4.1.2)
|
|
64
79
|
build-files (1.10.2)
|
|
65
80
|
colorize (1.1.0)
|
|
66
81
|
colorize-extended (0.1.0)
|
|
67
82
|
colorize (~> 1.1)
|
|
68
83
|
concurrent-ruby (1.3.6)
|
|
84
|
+
connection_pool (3.0.2)
|
|
69
85
|
console (1.34.3)
|
|
70
86
|
fiber-annotation
|
|
71
87
|
fiber-local (~> 1.1)
|
|
@@ -77,6 +93,7 @@ GEM
|
|
|
77
93
|
decode (0.27.0)
|
|
78
94
|
prism
|
|
79
95
|
rbs
|
|
96
|
+
drb (2.2.3)
|
|
80
97
|
erb (6.0.4)
|
|
81
98
|
falcon (0.55.3)
|
|
82
99
|
async
|
|
@@ -97,6 +114,8 @@ GEM
|
|
|
97
114
|
fiber-storage (1.0.1)
|
|
98
115
|
hana (1.3.7)
|
|
99
116
|
http-accept (2.2.1)
|
|
117
|
+
i18n (1.14.8)
|
|
118
|
+
concurrent-ruby (~> 1.0)
|
|
100
119
|
io-console (0.8.2)
|
|
101
120
|
io-endpoint (0.17.2)
|
|
102
121
|
io-event (1.16.0)
|
|
@@ -140,6 +159,9 @@ GEM
|
|
|
140
159
|
mime-types-data (~> 3.2025, >= 3.2025.0507)
|
|
141
160
|
mime-types-data (3.2026.0414)
|
|
142
161
|
mini_mime (1.1.5)
|
|
162
|
+
minitest (6.0.6)
|
|
163
|
+
drb (~> 2.0)
|
|
164
|
+
prism (~> 1.5)
|
|
143
165
|
msgpack (1.8.0)
|
|
144
166
|
net-imap (0.6.4)
|
|
145
167
|
date
|
|
@@ -215,6 +237,7 @@ GEM
|
|
|
215
237
|
mapping (~> 1.0)
|
|
216
238
|
scampi (0.1.7)
|
|
217
239
|
colorize-extended
|
|
240
|
+
securerandom (0.4.1)
|
|
218
241
|
shellwords (0.2.2)
|
|
219
242
|
simpleidn (0.2.3)
|
|
220
243
|
string-format (0.2.0)
|
|
@@ -224,9 +247,12 @@ GEM
|
|
|
224
247
|
timeout (0.6.1)
|
|
225
248
|
traces (0.18.2)
|
|
226
249
|
tsort (0.2.0)
|
|
250
|
+
tzinfo (2.0.6)
|
|
251
|
+
concurrent-ruby (~> 1.0)
|
|
227
252
|
unicode-display_width (3.2.0)
|
|
228
253
|
unicode-emoji (~> 4.1)
|
|
229
254
|
unicode-emoji (4.2.0)
|
|
255
|
+
uri (1.1.1)
|
|
230
256
|
utopia (2.32.1)
|
|
231
257
|
bake (~> 0.20)
|
|
232
258
|
concurrent-ruby (~> 1.2)
|
data/kube_cluster.gemspec
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
module CDI
|
|
10
|
+
#class DataVolume < Kube::Cluster['DataVolume']
|
|
11
|
+
# def initialize(name:, &block)
|
|
12
|
+
# super() {
|
|
13
|
+
# metadata.name = name
|
|
14
|
+
# instance_exec(&block) if block
|
|
15
|
+
# }
|
|
16
|
+
# end
|
|
17
|
+
#end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test do
|
|
24
|
+
#describe "CDI::DataVolume" do
|
|
25
|
+
# it "initializes without error" do
|
|
26
|
+
# Kube::Cluster::Standard::CDI::DataVolume
|
|
27
|
+
# .new(
|
|
28
|
+
# name: "my-example-volume"
|
|
29
|
+
# )
|
|
30
|
+
# .to_yaml
|
|
31
|
+
# .is_a?(String)
|
|
32
|
+
# .should == true
|
|
33
|
+
# end
|
|
34
|
+
#end
|
|
35
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
module CloudNativePg
|
|
10
|
+
#class Cluster < Kube::Cluster["Cluster"]
|
|
11
|
+
#end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test do
|
|
18
|
+
#describe "CloudNativePg::Cluster" do
|
|
19
|
+
# it "initializes without error" do
|
|
20
|
+
# Kube::Cluster::Standard::CloudNativePg::Cluster
|
|
21
|
+
# .new()
|
|
22
|
+
# .to_yaml
|
|
23
|
+
# .is_a?(String)
|
|
24
|
+
# .should == true
|
|
25
|
+
# end
|
|
26
|
+
#end
|
|
27
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
module CloudNativePg
|
|
10
|
+
class DatabaseWithExternalSecret < Kube::Cluster::Manifest
|
|
11
|
+
def initialize(name:, cluster: "postgres", owner: "app", &block)
|
|
12
|
+
database = Kube::Cluster["Database"].new {
|
|
13
|
+
metadata.name = name
|
|
14
|
+
spec.cluster = { name: cluster }
|
|
15
|
+
spec.databaseReclaimPolicy = "retain"
|
|
16
|
+
spec.ensure = "present"
|
|
17
|
+
spec.name = name
|
|
18
|
+
spec.owner = owner
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
external_secret = CloudNativePg::ExternalSecret.new(name: name)
|
|
22
|
+
|
|
23
|
+
super(database, external_secret)
|
|
24
|
+
instance_exec(&block) if block
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test do
|
|
33
|
+
describe "CloudNativePg::DatabaseWithExternalSecret" do
|
|
34
|
+
it "initializes without error" do
|
|
35
|
+
Kube::Cluster::Standard::CloudNativePg::DatabaseWithExternalSecret
|
|
36
|
+
.new(
|
|
37
|
+
name: "my-example-cluster"
|
|
38
|
+
)
|
|
39
|
+
.to_yaml
|
|
40
|
+
.is_a?(String)
|
|
41
|
+
.should == true
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
module CloudNativePg
|
|
10
|
+
class ExternalSecret < Kube::Cluster["ExternalSecret"]
|
|
11
|
+
|
|
12
|
+
DB_HOST = "postgres-rw.cloudnative-pg.svc.cluster.local"
|
|
13
|
+
|
|
14
|
+
def initialize(name:, env_prefix: "DB", db_host: DB_HOST, &block)
|
|
15
|
+
super() {
|
|
16
|
+
metadata.name = "#{name}-db"
|
|
17
|
+
spec.refreshInterval = "1h"
|
|
18
|
+
spec.secretStoreRef = { kind: "ClusterSecretStore", name: "cnpg-credentials" }
|
|
19
|
+
spec.target = {
|
|
20
|
+
name: "#{name}-db",
|
|
21
|
+
creationPolicy: "Owner",
|
|
22
|
+
deletionPolicy: "Retain",
|
|
23
|
+
template: {
|
|
24
|
+
data: {
|
|
25
|
+
"#{env_prefix}_URL" => "jdbc:postgresql://#{db_host}:5432/#{name}",
|
|
26
|
+
"#{env_prefix}_USER" => "{{ .username }}",
|
|
27
|
+
"#{env_prefix}_PASSWORD" => "{{ .password }}",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
spec.data = [
|
|
32
|
+
{ secretKey: "username", remoteRef: { key: "postgres-app", property: "username" } },
|
|
33
|
+
{ secretKey: "password", remoteRef: { key: "postgres-app", property: "password" } },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
instance_exec(&block) if block_given?
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test do
|
|
46
|
+
describe "CloudNativePg::ExternalSecret" do
|
|
47
|
+
it "initializes without error" do
|
|
48
|
+
Kube::Cluster::Standard::CloudNativePg::ExternalSecret
|
|
49
|
+
.new(
|
|
50
|
+
name: "my-external-secret"
|
|
51
|
+
)
|
|
52
|
+
.to_yaml
|
|
53
|
+
.is_a?(String)
|
|
54
|
+
.should == true
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -30,7 +30,7 @@ module Kube
|
|
|
30
30
|
# class Cluster < Kube::Cluster["HelmChart"]
|
|
31
31
|
# def initialize(&block)
|
|
32
32
|
# super {
|
|
33
|
-
# metadata.name = "cloudnative-pg"
|
|
33
|
+
# metadata.name = "cloudnative-pg--cluster"
|
|
34
34
|
# metadata.namespace = "kube-system"
|
|
35
35
|
# spec.chart = "cluster"
|
|
36
36
|
# spec.version = "0.6.1"
|
|
@@ -46,7 +46,7 @@ module Kube
|
|
|
46
46
|
class Barman < Kube::Cluster["HelmChart"]
|
|
47
47
|
def initialize(&block)
|
|
48
48
|
super {
|
|
49
|
-
metadata.name = "
|
|
49
|
+
metadata.name = "plugin-barman-cloud"
|
|
50
50
|
metadata.namespace = "kube-system"
|
|
51
51
|
spec.chart = "plugin-barman-cloud"
|
|
52
52
|
spec.version = "0.6.0"
|
|
@@ -65,27 +65,33 @@ module Kube
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
test do
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
describe "Operator" do
|
|
69
|
+
it "initializes without error" do
|
|
70
|
+
Kube::Cluster::Standard::CloudNativePg::Helm::Operator
|
|
71
|
+
.new()
|
|
72
|
+
.to_yaml
|
|
73
|
+
.is_a?(String)
|
|
74
|
+
.should == true
|
|
75
|
+
end
|
|
74
76
|
end
|
|
75
77
|
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
78
|
+
#describe "Cluster" do
|
|
79
|
+
# it "initializes without error" do
|
|
80
|
+
# Kube::Cluster::Standard::CloudNativePg::Helm::Cluster
|
|
81
|
+
# .new()
|
|
82
|
+
# .to_yaml
|
|
83
|
+
# .is_a?(String)
|
|
84
|
+
# .should == true
|
|
85
|
+
# end
|
|
86
|
+
#end
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
describe "Barman" do
|
|
89
|
+
it "initializes without error" do
|
|
90
|
+
Kube::Cluster::Standard::CloudNativePg::Helm::Barman
|
|
91
|
+
.new()
|
|
92
|
+
.to_yaml
|
|
93
|
+
.is_a?(String)
|
|
94
|
+
.should == true
|
|
95
|
+
end
|
|
90
96
|
end
|
|
91
97
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
class ConfigMap < Kube::Cluster['ConfigMap']
|
|
10
|
+
|
|
11
|
+
# wtf is this????? I hate it... claude made it and it needs to dead...
|
|
12
|
+
KeyRef = Struct.new(:config_map, :key_name)
|
|
13
|
+
|
|
14
|
+
def initialize(name: 'config', **options, &block)
|
|
15
|
+
super(**options) do
|
|
16
|
+
metadata.name = name
|
|
17
|
+
instance_exec(&block) if block
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def config_map_name
|
|
22
|
+
to_h.dig(:metadata, :name)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def key(key_name)
|
|
26
|
+
KeyRef.new(self, key_name)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test do
|
|
34
|
+
describe "ConfigMap" do
|
|
35
|
+
it "initializes without error" do
|
|
36
|
+
Kube::Cluster::Standard::ConfigMap
|
|
37
|
+
.new(
|
|
38
|
+
#name: "example-config"
|
|
39
|
+
)
|
|
40
|
+
.to_yaml
|
|
41
|
+
.is_a?(String)
|
|
42
|
+
.should == true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
class CustomResourceDefinition < Kube::Cluster['CustomResourceDefinition']
|
|
10
|
+
def initialize(
|
|
11
|
+
kind:, group:, version: 'v1', scope: 'Namespaced',
|
|
12
|
+
short_names: [], categories: [], schema: nil, &block
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
plural = kind.downcase.pluralize
|
|
16
|
+
singular = kind.downcase
|
|
17
|
+
|
|
18
|
+
schema ||= {
|
|
19
|
+
type: 'object',
|
|
20
|
+
'x-kubernetes-preserve-unknown-fields': true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
super() {
|
|
24
|
+
metadata.name = "#{plural}.#{group}"
|
|
25
|
+
|
|
26
|
+
spec.group = group
|
|
27
|
+
spec.names.kind = kind
|
|
28
|
+
spec.names.listKind = "#{kind}List"
|
|
29
|
+
spec.names.plural = plural
|
|
30
|
+
spec.names.singular = singular
|
|
31
|
+
spec.names.shortNames = short_names unless short_names.empty?
|
|
32
|
+
spec.names.categories = categories unless categories.empty?
|
|
33
|
+
spec.scope = scope
|
|
34
|
+
spec.versions = [{
|
|
35
|
+
name: version,
|
|
36
|
+
served: true,
|
|
37
|
+
storage: true,
|
|
38
|
+
subresources: { status: {} },
|
|
39
|
+
schema: {
|
|
40
|
+
openAPIV3Schema: schema
|
|
41
|
+
}
|
|
42
|
+
}]
|
|
43
|
+
|
|
44
|
+
instance_exec(&block) if block
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
api_version = "#{group}/#{version}"
|
|
48
|
+
Kube::Schema.register(
|
|
49
|
+
kind,
|
|
50
|
+
schema: {
|
|
51
|
+
'type' => 'object',
|
|
52
|
+
'properties' => {
|
|
53
|
+
'apiVersion' => { 'type' => 'string' },
|
|
54
|
+
'kind' => { 'type' => 'string' },
|
|
55
|
+
'metadata' => { 'type' => 'object' },
|
|
56
|
+
'spec' => { 'type' => 'object', 'x-kubernetes-preserve-unknown-fields' => true },
|
|
57
|
+
'status' => { 'type' => 'object', 'x-kubernetes-preserve-unknown-fields' => true }
|
|
58
|
+
},
|
|
59
|
+
'x-kubernetes-preserve-unknown-fields' => true
|
|
60
|
+
},
|
|
61
|
+
api_version: api_version
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test do
|
|
70
|
+
describe "CustomResourceDefinition" do
|
|
71
|
+
it "initializes without error" do
|
|
72
|
+
Kube::Cluster::Standard::CustomResourceDefinition
|
|
73
|
+
.new(
|
|
74
|
+
kind: "Widget",
|
|
75
|
+
group: "example.com",
|
|
76
|
+
)
|
|
77
|
+
.to_yaml
|
|
78
|
+
.is_a?(String)
|
|
79
|
+
.should == true
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'kube/cluster'
|
|
4
|
+
require 'kube/cluster/standard/env_processing'
|
|
5
|
+
require 'kube/cluster/standard/volume_processing'
|
|
6
|
+
|
|
7
|
+
module Kube
|
|
8
|
+
module Cluster
|
|
9
|
+
module Standard
|
|
10
|
+
class DaemonSet < Kube::Cluster['DaemonSet']
|
|
11
|
+
def initialize(
|
|
12
|
+
name:,
|
|
13
|
+
image:,
|
|
14
|
+
env: {},
|
|
15
|
+
volume_mounts: {},
|
|
16
|
+
command: nil,
|
|
17
|
+
service_account: nil,
|
|
18
|
+
node_selector: nil,
|
|
19
|
+
tolerations: nil,
|
|
20
|
+
host_pid: false,
|
|
21
|
+
&block
|
|
22
|
+
)
|
|
23
|
+
processed_env = EnvProcessing.process(env)
|
|
24
|
+
processed_volumes = VolumeProcessing.process(volume_mounts)
|
|
25
|
+
|
|
26
|
+
super() {
|
|
27
|
+
metadata.name = name
|
|
28
|
+
metadata.labels = { 'app' => name }
|
|
29
|
+
|
|
30
|
+
spec.selector.matchLabels = { 'app' => name }
|
|
31
|
+
|
|
32
|
+
spec.template.metadata.labels = { 'app' => name }
|
|
33
|
+
spec.template.spec.serviceAccountName = service_account || name
|
|
34
|
+
|
|
35
|
+
container = {
|
|
36
|
+
name: name,
|
|
37
|
+
image: image,
|
|
38
|
+
env: processed_env
|
|
39
|
+
}
|
|
40
|
+
container[:command] = command if command
|
|
41
|
+
container[:volumeMounts] = processed_volumes[:volume_mounts] unless processed_volumes[:volume_mounts].empty?
|
|
42
|
+
|
|
43
|
+
spec.template.spec.containers = [container]
|
|
44
|
+
spec.template.spec.volumes = processed_volumes[:volumes] unless processed_volumes[:volumes].empty?
|
|
45
|
+
spec.template.spec.hostPID = true if host_pid
|
|
46
|
+
spec.template.spec.nodeSelector = node_selector if node_selector
|
|
47
|
+
spec.template.spec.tolerations = tolerations if tolerations
|
|
48
|
+
|
|
49
|
+
instance_exec(&block) if block
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test do
|
|
58
|
+
describe "DaemonSet" do
|
|
59
|
+
it "initializes without error" do
|
|
60
|
+
Kube::Cluster::Standard::DaemonSet
|
|
61
|
+
.new(
|
|
62
|
+
name: "my-daemon",
|
|
63
|
+
image: "busybox",
|
|
64
|
+
)
|
|
65
|
+
.to_yaml
|
|
66
|
+
.is_a?(String)
|
|
67
|
+
.should == true
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kube/cluster"
|
|
5
|
+
|
|
6
|
+
module Kube
|
|
7
|
+
module Cluster
|
|
8
|
+
module Standard
|
|
9
|
+
class DeploymentWithService < Kube::Cluster::Manifest
|
|
10
|
+
def initialize(
|
|
11
|
+
name:,
|
|
12
|
+
image:,
|
|
13
|
+
port:,
|
|
14
|
+
namespace: 'default',
|
|
15
|
+
env: {},
|
|
16
|
+
security_context: nil,
|
|
17
|
+
pod_security_context: nil,
|
|
18
|
+
volume_mounts: {},
|
|
19
|
+
service_port: nil,
|
|
20
|
+
&block
|
|
21
|
+
)
|
|
22
|
+
@_limits = {}
|
|
23
|
+
@_probes = {}
|
|
24
|
+
|
|
25
|
+
processed_env = EnvProcessing.process(env)
|
|
26
|
+
processed_volumes = VolumeProcessing.process(volume_mounts)
|
|
27
|
+
|
|
28
|
+
service_ports = Array(service_port || port)
|
|
29
|
+
|
|
30
|
+
service = Kube::Cluster::Standard::Service.new(
|
|
31
|
+
name: name,
|
|
32
|
+
namespace: namespace,
|
|
33
|
+
ports: service_ports
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
deployment = Kube::Cluster['Deployment'].new do
|
|
37
|
+
metadata.name = name
|
|
38
|
+
metadata.namespace = namespace
|
|
39
|
+
metadata.labels = { 'app' => name }
|
|
40
|
+
|
|
41
|
+
spec.replicas = 1
|
|
42
|
+
spec.selector.matchLabels = { 'app' => name }
|
|
43
|
+
|
|
44
|
+
spec.template.metadata.labels = { 'app' => name }
|
|
45
|
+
spec.template.spec.securityContext = pod_security_context if pod_security_context
|
|
46
|
+
|
|
47
|
+
container = {
|
|
48
|
+
name: name,
|
|
49
|
+
image: image,
|
|
50
|
+
ports: [{ name: 'http', containerPort: port, protocol: 'TCP' }],
|
|
51
|
+
env: processed_env
|
|
52
|
+
}
|
|
53
|
+
container[:securityContext] = security_context if security_context
|
|
54
|
+
container[:volumeMounts] = processed_volumes[:volume_mounts] unless processed_volumes[:volume_mounts].empty?
|
|
55
|
+
|
|
56
|
+
spec.template.spec.containers = [container]
|
|
57
|
+
spec.template.spec.volumes = processed_volumes[:volumes] unless processed_volumes[:volumes].empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
super(deployment, service)
|
|
61
|
+
|
|
62
|
+
instance_exec(&block) if block
|
|
63
|
+
|
|
64
|
+
_apply_limits(deployment)
|
|
65
|
+
_apply_probes(deployment)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def limits
|
|
69
|
+
@_limits
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def probes
|
|
73
|
+
@_probes
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def _apply_limits(deployment)
|
|
79
|
+
return if @_limits.empty?
|
|
80
|
+
|
|
81
|
+
container = deployment.to_h[:spec][:template][:spec][:containers][0]
|
|
82
|
+
resources = {}
|
|
83
|
+
|
|
84
|
+
@_limits.each do |resource_type, mapping|
|
|
85
|
+
mapping.each do |request, limit|
|
|
86
|
+
resources[:requests] ||= {}
|
|
87
|
+
resources[:requests][resource_type] = request.to_s
|
|
88
|
+
|
|
89
|
+
if limit != Float::INFINITY
|
|
90
|
+
resources[:limits] ||= {}
|
|
91
|
+
resources[:limits][resource_type] = limit.to_s
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
container[:resources] = resources
|
|
97
|
+
h = deployment.to_h
|
|
98
|
+
h[:spec][:template][:spec][:containers][0] = container
|
|
99
|
+
deployment.rebuild(h)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def _apply_probes(deployment)
|
|
103
|
+
return if @_probes.empty?
|
|
104
|
+
return unless @_probes[:url]
|
|
105
|
+
|
|
106
|
+
container = deployment.to_h[:spec][:template][:spec][:containers][0]
|
|
107
|
+
url = @_probes[:url]
|
|
108
|
+
|
|
109
|
+
if @_probes[:liveness]
|
|
110
|
+
delay, period = @_probes[:liveness].first
|
|
111
|
+
container[:livenessProbe] = {
|
|
112
|
+
httpGet: url,
|
|
113
|
+
initialDelaySeconds: delay,
|
|
114
|
+
periodSeconds: period,
|
|
115
|
+
timeoutSeconds: 5
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
if @_probes[:readiness]
|
|
120
|
+
delay, period = @_probes[:readiness].first
|
|
121
|
+
container[:readinessProbe] = {
|
|
122
|
+
httpGet: url,
|
|
123
|
+
initialDelaySeconds: delay,
|
|
124
|
+
periodSeconds: period,
|
|
125
|
+
timeoutSeconds: 5
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
h = deployment.to_h
|
|
130
|
+
h[:spec][:template][:spec][:containers][0] = container
|
|
131
|
+
deployment.rebuild(h)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
test do
|
|
139
|
+
describe "DeploymentWithService" do
|
|
140
|
+
it "initializes without error" do
|
|
141
|
+
Kube::Cluster::Standard::DeploymentWithService
|
|
142
|
+
.new(
|
|
143
|
+
name: "pointless-ruby-container",
|
|
144
|
+
image: "ruby/ruby",
|
|
145
|
+
port: 3000,
|
|
146
|
+
)
|
|
147
|
+
.to_yaml
|
|
148
|
+
.is_a?(String)
|
|
149
|
+
.should == true
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|