kube_cluster 0.20.1 → 0.21.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/.gitignore +1 -0
- data/Gemfile.lock +5 -37
- data/flake.nix +2 -1
- data/kube_cluster.gemspec +1 -3
- data/lib/kube/cluster/container.rb +17 -17
- data/lib/kube/cluster/manifest.rb +158 -158
- data/lib/kube/cluster/middleware/annotations.rb +42 -42
- data/lib/kube/cluster/middleware/hpa_for_deployment.rb +134 -134
- data/lib/kube/cluster/middleware/ingress_for_service.rb +75 -75
- data/lib/kube/cluster/middleware/labels.rb +58 -58
- data/lib/kube/cluster/middleware/pod_anti_affinity.rb +104 -104
- data/lib/kube/cluster/middleware/resource_preset.rb +145 -145
- data/lib/kube/cluster/middleware/security_context.rb +127 -127
- data/lib/kube/cluster/middleware/service_for_deployment.rb +120 -120
- data/lib/kube/cluster/middleware.rb +219 -221
- data/lib/kube/cluster/resource/dirty_tracking.rb +388 -388
- data/lib/kube/cluster/resource.rb +16 -16
- data/lib/kube/cluster/standard/cdi/data_volume.rb +13 -13
- data/lib/kube/cluster/standard/cloud_native_pg/cluster.rb +11 -11
- data/lib/kube/cluster/standard/cloud_native_pg/database_with_external_secret.rb +11 -11
- data/lib/kube/cluster/standard/cloud_native_pg/external_secret.rb +11 -11
- data/lib/kube/cluster/standard/cloud_native_pg/helm.rb +26 -26
- data/lib/kube/cluster/standard/config_map.rb +11 -11
- data/lib/kube/cluster/standard/cron_job.rb +13 -13
- data/lib/kube/cluster/standard/cron_job_with_service_account.rb +12 -12
- data/lib/kube/cluster/standard/custom_resource_definition.rb +12 -12
- data/lib/kube/cluster/standard/daemon_set.rb +12 -12
- data/lib/kube/cluster/standard/deployment_with_service.rb +82 -82
- data/lib/kube/cluster/standard/env_processing.rb +15 -15
- data/lib/kube/cluster/standard/eso/external_secret.rb +13 -13
- data/lib/kube/cluster/standard/forgejo/helm.rb +11 -11
- data/lib/kube/cluster/standard/gateway_api/http_route.rb +302 -19
- data/lib/kube/cluster/standard/job.rb +12 -12
- data/lib/kube/cluster/standard/job_with_service_account.rb +11 -11
- data/lib/kube/cluster/standard/kube_virt/virtual_machine.rb +11 -11
- data/lib/kube/cluster/standard/meta_controller/composite_controller.rb +13 -13
- data/lib/kube/cluster/standard/meta_controller/decorator_controller.rb +13 -13
- data/lib/kube/cluster/standard/perses/perses.rb +9 -9
- data/lib/kube/cluster/standard/perses/perses_datasource.rb +13 -13
- data/lib/kube/cluster/standard/persistent_volume_claim.rb +12 -12
- data/lib/kube/cluster/standard/role.rb +12 -12
- data/lib/kube/cluster/standard/role_binding.rb +10 -10
- data/lib/kube/cluster/standard/secret.rb +11 -11
- data/lib/kube/cluster/standard/service.rb +12 -12
- data/lib/kube/cluster/standard/service_account.rb +9 -9
- data/lib/kube/cluster/standard/service_account_with_role.rb +10 -10
- data/lib/kube/cluster/standard/victoria_metrics/vl_agent.rb +9 -9
- data/lib/kube/cluster/standard/victoria_metrics/vl_single.rb +9 -9
- data/lib/kube/cluster/standard/victoria_metrics/vm_agent.rb +9 -9
- data/lib/kube/cluster/standard/victoria_metrics/vm_node_scrape.rb +9 -9
- data/lib/kube/cluster/standard/victoria_metrics/vm_service_scrape.rb +9 -9
- data/lib/kube/cluster/standard/victoria_metrics/vm_single.rb +9 -9
- data/lib/kube/cluster/standard/volume_processing.rb +3 -3
- data/lib/kube/cluster/version.rb +1 -1
- data/lib/kube/cluster.rb +0 -1
- data/lib/kube/helm/chart.rb +323 -323
- data/lib/kube/helm/endpoint.rb +58 -58
- data/lib/kube/helm/repo.rb +160 -160
- metadata +4 -18
|
@@ -34,60 +34,60 @@ module Kube
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
Middleware = Kube::Cluster::Middleware
|
|
37
|
+
__END__
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
m = manifest(Kube::Cluster["ConfigMap"].new { metadata.name = "test" })
|
|
39
|
+
Middleware = Kube::Cluster::Middleware
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"prometheus.io/port": "9090",
|
|
46
|
-
).call(m)
|
|
41
|
+
it "adds_annotations" do
|
|
42
|
+
m = manifest(Kube::Cluster["ConfigMap"].new { metadata.name = "test" })
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
Middleware::Annotations.new(
|
|
45
|
+
"prometheus.io/scrape": "true",
|
|
46
|
+
"prometheus.io/port": "9090",
|
|
47
|
+
).call(m)
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "resource_annotations_override_middleware_defaults" do
|
|
54
|
-
m = manifest(Kube::Cluster["ConfigMap"].new {
|
|
55
|
-
metadata.name = "test"
|
|
56
|
-
metadata.annotations = { "prometheus.io/port": "8080" }
|
|
57
|
-
})
|
|
49
|
+
annotations = m.resources.first.to_h.dig(:metadata, :annotations)
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
annotations[:"prometheus.io/port"].should == "9090"
|
|
52
|
+
end
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
it "resource_annotations_override_middleware_defaults" do
|
|
55
|
+
m = manifest(Kube::Cluster["ConfigMap"].new {
|
|
56
|
+
metadata.name = "test"
|
|
57
|
+
metadata.annotations = { "prometheus.io/port": "8080" }
|
|
58
|
+
})
|
|
64
59
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
metadata.name = "test"
|
|
68
|
-
metadata.annotations = { "custom/annotation": "keep" }
|
|
69
|
-
})
|
|
60
|
+
Middleware::Annotations.new("prometheus.io/port": "9090").call(m)
|
|
61
|
+
annotations = m.resources.first.to_h.dig(:metadata, :annotations)
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
annotations[:"prometheus.io/port"].should == "8080"
|
|
64
|
+
end
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
it "preserves_existing_annotations" do
|
|
67
|
+
m = manifest(Kube::Cluster["ConfigMap"].new {
|
|
68
|
+
metadata.name = "test"
|
|
69
|
+
metadata.annotations = { "custom/annotation": "keep" }
|
|
70
|
+
})
|
|
76
71
|
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
Middleware::Annotations.new("prometheus.io/scrape": "true").call(m)
|
|
73
|
+
annotations = m.resources.first.to_h.dig(:metadata, :annotations)
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
annotations[:"prometheus.io/scrape"].should == "true"
|
|
76
|
+
end
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
it "converts_values_to_strings" do
|
|
79
|
+
m = manifest(Kube::Cluster["ConfigMap"].new { metadata.name = "test" })
|
|
85
80
|
|
|
86
|
-
|
|
81
|
+
Middleware::Annotations.new("prometheus.io/port": 9090).call(m)
|
|
82
|
+
annotations = m.resources.first.to_h.dig(:metadata, :annotations)
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
m = Kube::Cluster::Manifest.new
|
|
90
|
-
resources.each { |r| m << r }
|
|
91
|
-
m
|
|
92
|
-
end
|
|
84
|
+
annotations[:"prometheus.io/port"].should == "9090"
|
|
93
85
|
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def manifest(*resources)
|
|
90
|
+
m = Kube::Cluster::Manifest.new
|
|
91
|
+
resources.each { |r| m << r }
|
|
92
|
+
m
|
|
93
|
+
end
|
|
@@ -107,159 +107,159 @@ module Kube
|
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
110
|
+
__END__
|
|
111
|
+
|
|
112
|
+
Middleware = Kube::Cluster::Middleware
|
|
113
|
+
|
|
114
|
+
it "generates_hpa_from_deployment" do
|
|
115
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
116
|
+
metadata.name = "web"
|
|
117
|
+
metadata.namespace = "production"
|
|
118
|
+
metadata.labels = {
|
|
119
|
+
"app.kubernetes.io/name": "web",
|
|
120
|
+
"app.kubernetes.io/autoscale": "2-10",
|
|
121
|
+
}
|
|
122
|
+
spec.selector.matchLabels = { app: "web" }
|
|
123
|
+
spec.template.metadata.labels = { app: "web" }
|
|
124
|
+
spec.template.spec.containers = [
|
|
125
|
+
{ name: "web", image: "nginx" },
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
Middleware::HPAForDeployment.new.call(m)
|
|
130
|
+
|
|
131
|
+
deploy, hpa = m.resources
|
|
132
|
+
hh = hpa.to_h
|
|
133
|
+
metrics = hh.dig(:spec, :metrics)
|
|
134
|
+
|
|
135
|
+
metrics[1].dig(:resource, :target, :averageUtilization).should == 80
|
|
136
|
+
end
|
|
127
137
|
|
|
128
|
-
|
|
138
|
+
it "custom_cpu_and_memory_targets" do
|
|
139
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
140
|
+
metadata.name = "web"
|
|
141
|
+
metadata.labels = { "app.kubernetes.io/autoscale": "1-3" }
|
|
142
|
+
spec.selector.matchLabels = { app: "web" }
|
|
143
|
+
spec.template.metadata.labels = { app: "web" }
|
|
144
|
+
spec.template.spec.containers = [
|
|
145
|
+
{ name: "web", image: "nginx" },
|
|
146
|
+
]
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
Middleware::HPAForDeployment.new(cpu: 60, memory: 70).call(m)
|
|
150
|
+
hpa = m.resources.last.to_h
|
|
151
|
+
|
|
152
|
+
hpa.dig(:spec, :metrics, 1, :resource, :target, :averageUtilization).should == 70
|
|
153
|
+
end
|
|
129
154
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
it "strips_autoscale_label_from_hpa" do
|
|
156
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
157
|
+
metadata.name = "web"
|
|
158
|
+
metadata.labels = {
|
|
159
|
+
"app.kubernetes.io/name": "web",
|
|
160
|
+
"app.kubernetes.io/autoscale": "1-5",
|
|
161
|
+
}
|
|
162
|
+
spec.selector.matchLabels = { app: "web" }
|
|
163
|
+
spec.template.metadata.labels = { app: "web" }
|
|
164
|
+
spec.template.spec.containers = [
|
|
165
|
+
{ name: "web", image: "nginx" },
|
|
166
|
+
]
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
Middleware::HPAForDeployment.new.call(m)
|
|
170
|
+
hpa_labels = m.resources.last.to_h.dig(:metadata, :labels)
|
|
171
|
+
|
|
172
|
+
hpa_labels[:"app.kubernetes.io/autoscale"].should.be.nil
|
|
173
|
+
end
|
|
133
174
|
|
|
134
|
-
|
|
135
|
-
|
|
175
|
+
it "skips_deployment_without_autoscale_label" do
|
|
176
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
177
|
+
metadata.name = "web"
|
|
178
|
+
spec.selector.matchLabels = { app: "web" }
|
|
179
|
+
spec.template.metadata.labels = { app: "web" }
|
|
180
|
+
spec.template.spec.containers = [
|
|
181
|
+
{ name: "web", image: "nginx" },
|
|
182
|
+
]
|
|
183
|
+
})
|
|
136
184
|
|
|
137
|
-
|
|
138
|
-
m = manifest(Kube::Cluster["Deployment"].new {
|
|
139
|
-
metadata.name = "web"
|
|
140
|
-
metadata.labels = { "app.kubernetes.io/autoscale": "1-3" }
|
|
141
|
-
spec.selector.matchLabels = { app: "web" }
|
|
142
|
-
spec.template.metadata.labels = { app: "web" }
|
|
143
|
-
spec.template.spec.containers = [
|
|
144
|
-
{ name: "web", image: "nginx" },
|
|
145
|
-
]
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
Middleware::HPAForDeployment.new(cpu: 60, memory: 70).call(m)
|
|
149
|
-
hpa = m.resources.last.to_h
|
|
150
|
-
|
|
151
|
-
hpa.dig(:spec, :metrics, 1, :resource, :target, :averageUtilization).should == 70
|
|
152
|
-
end
|
|
185
|
+
Middleware::HPAForDeployment.new.call(m)
|
|
153
186
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
metadata.name = "web"
|
|
157
|
-
metadata.labels = {
|
|
158
|
-
"app.kubernetes.io/name": "web",
|
|
159
|
-
"app.kubernetes.io/autoscale": "1-5",
|
|
160
|
-
}
|
|
161
|
-
spec.selector.matchLabels = { app: "web" }
|
|
162
|
-
spec.template.metadata.labels = { app: "web" }
|
|
163
|
-
spec.template.spec.containers = [
|
|
164
|
-
{ name: "web", image: "nginx" },
|
|
165
|
-
]
|
|
166
|
-
})
|
|
187
|
+
m.resources.size.should == 1
|
|
188
|
+
end
|
|
167
189
|
|
|
168
|
-
|
|
169
|
-
|
|
190
|
+
it "skips_non_pod_bearing_resources" do
|
|
191
|
+
m = manifest(Kube::Cluster["ConfigMap"].new {
|
|
192
|
+
metadata.name = "config"
|
|
193
|
+
metadata.labels = { "app.kubernetes.io/autoscale": "1-5" }
|
|
194
|
+
})
|
|
170
195
|
|
|
171
|
-
|
|
172
|
-
end
|
|
196
|
+
Middleware::HPAForDeployment.new.call(m)
|
|
173
197
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
metadata.name = "web"
|
|
177
|
-
spec.selector.matchLabels = { app: "web" }
|
|
178
|
-
spec.template.metadata.labels = { app: "web" }
|
|
179
|
-
spec.template.spec.containers = [
|
|
180
|
-
{ name: "web", image: "nginx" },
|
|
181
|
-
]
|
|
182
|
-
})
|
|
198
|
+
m.resources.size.should == 1
|
|
199
|
+
end
|
|
183
200
|
|
|
201
|
+
it "raises_on_invalid_range_format" do
|
|
202
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
203
|
+
metadata.name = "web"
|
|
204
|
+
metadata.labels = { "app.kubernetes.io/autoscale": "bad" }
|
|
205
|
+
spec.selector.matchLabels = { app: "web" }
|
|
206
|
+
spec.template.metadata.labels = { app: "web" }
|
|
207
|
+
spec.template.spec.containers = [
|
|
208
|
+
{ name: "web", image: "nginx" },
|
|
209
|
+
]
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
error = nil
|
|
213
|
+
begin
|
|
184
214
|
Middleware::HPAForDeployment.new.call(m)
|
|
185
|
-
|
|
186
|
-
|
|
215
|
+
rescue ArgumentError => e
|
|
216
|
+
error = e
|
|
187
217
|
end
|
|
188
218
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
metadata.name = "config"
|
|
192
|
-
metadata.labels = { "app.kubernetes.io/autoscale": "1-5" }
|
|
193
|
-
})
|
|
219
|
+
error.message.should.include "Invalid autoscale label"
|
|
220
|
+
end
|
|
194
221
|
|
|
222
|
+
it "raises_on_invalid_range_values" do
|
|
223
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
224
|
+
metadata.name = "web"
|
|
225
|
+
metadata.labels = { "app.kubernetes.io/autoscale": "5-2" }
|
|
226
|
+
spec.selector.matchLabels = { app: "web" }
|
|
227
|
+
spec.template.metadata.labels = { app: "web" }
|
|
228
|
+
spec.template.spec.containers = [
|
|
229
|
+
{ name: "web", image: "nginx" },
|
|
230
|
+
]
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
error = nil
|
|
234
|
+
begin
|
|
195
235
|
Middleware::HPAForDeployment.new.call(m)
|
|
196
|
-
|
|
197
|
-
|
|
236
|
+
rescue ArgumentError => e
|
|
237
|
+
error = e
|
|
198
238
|
end
|
|
199
239
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
metadata.name = "web"
|
|
203
|
-
metadata.labels = { "app.kubernetes.io/autoscale": "bad" }
|
|
204
|
-
spec.selector.matchLabels = { app: "web" }
|
|
205
|
-
spec.template.metadata.labels = { app: "web" }
|
|
206
|
-
spec.template.spec.containers = [
|
|
207
|
-
{ name: "web", image: "nginx" },
|
|
208
|
-
]
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
error = nil
|
|
212
|
-
begin
|
|
213
|
-
Middleware::HPAForDeployment.new.call(m)
|
|
214
|
-
rescue ArgumentError => e
|
|
215
|
-
error = e
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
error.message.should.include "Invalid autoscale label"
|
|
219
|
-
end
|
|
240
|
+
error.message.should.include "Invalid autoscale range"
|
|
241
|
+
end
|
|
220
242
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
error = nil
|
|
233
|
-
begin
|
|
234
|
-
Middleware::HPAForDeployment.new.call(m)
|
|
235
|
-
rescue ArgumentError => e
|
|
236
|
-
error = e
|
|
237
|
-
end
|
|
243
|
+
it "works_with_statefulset" do
|
|
244
|
+
m = manifest(Kube::Cluster["StatefulSet"].new {
|
|
245
|
+
metadata.name = "db"
|
|
246
|
+
metadata.labels = { "app.kubernetes.io/autoscale": "1-3" }
|
|
247
|
+
spec.selector.matchLabels = { app: "db" }
|
|
248
|
+
spec.template.metadata.labels = { app: "db" }
|
|
249
|
+
spec.template.spec.containers = [
|
|
250
|
+
{ name: "postgres", image: "postgres:16" },
|
|
251
|
+
]
|
|
252
|
+
})
|
|
238
253
|
|
|
239
|
-
|
|
240
|
-
end
|
|
254
|
+
Middleware::HPAForDeployment.new.call(m)
|
|
241
255
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
metadata.name = "db"
|
|
245
|
-
metadata.labels = { "app.kubernetes.io/autoscale": "1-3" }
|
|
246
|
-
spec.selector.matchLabels = { app: "db" }
|
|
247
|
-
spec.template.metadata.labels = { app: "db" }
|
|
248
|
-
spec.template.spec.containers = [
|
|
249
|
-
{ name: "postgres", image: "postgres:16" },
|
|
250
|
-
]
|
|
251
|
-
})
|
|
256
|
+
m.resources.last.to_h.dig(:spec, :scaleTargetRef, :kind).should == "StatefulSet"
|
|
257
|
+
end
|
|
252
258
|
|
|
253
|
-
|
|
259
|
+
private
|
|
254
260
|
|
|
255
|
-
|
|
261
|
+
def manifest(*resources)
|
|
262
|
+
m = Kube::Cluster::Manifest.new
|
|
263
|
+
resources.each { |r| m << r }
|
|
264
|
+
m
|
|
256
265
|
end
|
|
257
|
-
|
|
258
|
-
private
|
|
259
|
-
|
|
260
|
-
def manifest(*resources)
|
|
261
|
-
m = Kube::Cluster::Manifest.new
|
|
262
|
-
resources.each { |r| m << r }
|
|
263
|
-
m
|
|
264
|
-
end
|
|
265
|
-
end
|
|
@@ -87,100 +87,100 @@ module Kube
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
Middleware = Kube::Cluster::Middleware
|
|
90
|
+
__END__
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
m = manifest(Kube::Cluster["Service"].new {
|
|
95
|
-
metadata.name = "web"
|
|
96
|
-
metadata.namespace = "production"
|
|
97
|
-
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
98
|
-
spec.selector = { app: "web" }
|
|
99
|
-
spec.ports = [{ name: "http", port: 80, targetPort: "http" }]
|
|
100
|
-
})
|
|
92
|
+
Middleware = Kube::Cluster::Middleware
|
|
101
93
|
|
|
102
|
-
|
|
94
|
+
it "generates_ingress_from_service_with_expose_label" do
|
|
95
|
+
m = manifest(Kube::Cluster["Service"].new {
|
|
96
|
+
metadata.name = "web"
|
|
97
|
+
metadata.namespace = "production"
|
|
98
|
+
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
99
|
+
spec.selector = { app: "web" }
|
|
100
|
+
spec.ports = [{ name: "http", port: 80, targetPort: "http" }]
|
|
101
|
+
})
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
ih = ingress.to_h
|
|
106
|
-
rule = ih.dig(:spec, :rules, 0)
|
|
103
|
+
Middleware::IngressForService.new.call(m)
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
it "custom_issuer_and_ingress_class" do
|
|
112
|
-
m = manifest(Kube::Cluster["Service"].new {
|
|
113
|
-
metadata.name = "web"
|
|
114
|
-
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
115
|
-
spec.ports = [{ name: "http", port: 80 }]
|
|
116
|
-
})
|
|
105
|
+
service, ingress = m.resources
|
|
106
|
+
ih = ingress.to_h
|
|
107
|
+
rule = ih.dig(:spec, :rules, 0)
|
|
117
108
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
ingress_class: "traefik",
|
|
121
|
-
).call(m)
|
|
109
|
+
rule.dig(:http, :paths, 0, :backend, :service, :port, :name).should == "http"
|
|
110
|
+
end
|
|
122
111
|
|
|
123
|
-
|
|
112
|
+
it "custom_issuer_and_ingress_class" do
|
|
113
|
+
m = manifest(Kube::Cluster["Service"].new {
|
|
114
|
+
metadata.name = "web"
|
|
115
|
+
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
116
|
+
spec.ports = [{ name: "http", port: 80 }]
|
|
117
|
+
})
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
Middleware::IngressForService.new(
|
|
120
|
+
issuer: "letsencrypt-staging",
|
|
121
|
+
ingress_class: "traefik",
|
|
122
|
+
).call(m)
|
|
127
123
|
|
|
128
|
-
|
|
129
|
-
m = manifest(Kube::Cluster["Service"].new {
|
|
130
|
-
metadata.name = "api"
|
|
131
|
-
metadata.labels = { "app.kubernetes.io/expose": "true" }
|
|
132
|
-
spec.ports = [{ name: "http", port: 80 }]
|
|
133
|
-
})
|
|
124
|
+
ingress = m.resources.last.to_h
|
|
134
125
|
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
ingress.dig(:metadata, :annotations, :"cert-manager.io/cluster-issuer").should == "letsencrypt-staging"
|
|
127
|
+
end
|
|
137
128
|
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
it "expose_true_uses_name_as_hostname" do
|
|
130
|
+
m = manifest(Kube::Cluster["Service"].new {
|
|
131
|
+
metadata.name = "api"
|
|
132
|
+
metadata.labels = { "app.kubernetes.io/expose": "true" }
|
|
133
|
+
spec.ports = [{ name: "http", port: 80 }]
|
|
134
|
+
})
|
|
140
135
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
metadata.name = "web"
|
|
144
|
-
metadata.labels = {
|
|
145
|
-
"app.kubernetes.io/expose": "app.example.com",
|
|
146
|
-
"app.kubernetes.io/name": "web",
|
|
147
|
-
}
|
|
148
|
-
spec.ports = [{ name: "http", port: 80 }]
|
|
149
|
-
})
|
|
136
|
+
Middleware::IngressForService.new.call(m)
|
|
137
|
+
ingress = m.resources.last.to_h
|
|
150
138
|
|
|
151
|
-
|
|
152
|
-
|
|
139
|
+
ingress.dig(:spec, :tls, 0, :hosts).should == ["api.local"]
|
|
140
|
+
end
|
|
153
141
|
|
|
154
|
-
|
|
155
|
-
|
|
142
|
+
it "strips_expose_label_from_ingress" do
|
|
143
|
+
m = manifest(Kube::Cluster["Service"].new {
|
|
144
|
+
metadata.name = "web"
|
|
145
|
+
metadata.labels = {
|
|
146
|
+
"app.kubernetes.io/expose": "app.example.com",
|
|
147
|
+
"app.kubernetes.io/name": "web",
|
|
148
|
+
}
|
|
149
|
+
spec.ports = [{ name: "http", port: 80 }]
|
|
150
|
+
})
|
|
156
151
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
metadata.name = "web"
|
|
160
|
-
spec.ports = [{ name: "http", port: 80 }]
|
|
161
|
-
})
|
|
152
|
+
Middleware::IngressForService.new.call(m)
|
|
153
|
+
ingress_labels = m.resources.last.to_h.dig(:metadata, :labels)
|
|
162
154
|
|
|
163
|
-
|
|
155
|
+
ingress_labels[:"app.kubernetes.io/expose"].should.be.nil
|
|
156
|
+
end
|
|
164
157
|
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
it "skips_service_without_expose_label" do
|
|
159
|
+
m = manifest(Kube::Cluster["Service"].new {
|
|
160
|
+
metadata.name = "web"
|
|
161
|
+
spec.ports = [{ name: "http", port: 80 }]
|
|
162
|
+
})
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
m = manifest(Kube::Cluster["Deployment"].new {
|
|
170
|
-
metadata.name = "web"
|
|
171
|
-
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
172
|
-
})
|
|
164
|
+
Middleware::IngressForService.new.call(m)
|
|
173
165
|
|
|
174
|
-
|
|
166
|
+
m.resources.size.should == 1
|
|
167
|
+
end
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
it "skips_non_service_resources" do
|
|
170
|
+
m = manifest(Kube::Cluster["Deployment"].new {
|
|
171
|
+
metadata.name = "web"
|
|
172
|
+
metadata.labels = { "app.kubernetes.io/expose": "app.example.com" }
|
|
173
|
+
})
|
|
178
174
|
|
|
179
|
-
|
|
175
|
+
Middleware::IngressForService.new.call(m)
|
|
180
176
|
|
|
181
|
-
|
|
182
|
-
m = Kube::Cluster::Manifest.new
|
|
183
|
-
resources.each { |r| m << r }
|
|
184
|
-
m
|
|
185
|
-
end
|
|
177
|
+
m.resources.size.should == 1
|
|
186
178
|
end
|
|
179
|
+
|
|
180
|
+
private
|
|
181
|
+
|
|
182
|
+
def manifest(*resources)
|
|
183
|
+
m = Kube::Cluster::Manifest.new
|
|
184
|
+
resources.each { |r| m << r }
|
|
185
|
+
m
|
|
186
|
+
end
|