kube_cluster 0.17.0 → 0.17.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7b1fa07c1c7e080961d17a281c4b2c8a6e84abc6cc9d4ae6c568415b2e989ae
4
- data.tar.gz: 80994ba308efe68700f925dff182abf89908a55b1d35224c75eb577d7a42485c
3
+ metadata.gz: 928086733f7475611aa69193643f88719d926b70bb4aa3ed9d8a1c8f27efdec7
4
+ data.tar.gz: 3cc456aa515c6ca51fd87f26d35b2fcc740d984f8d907385a9f4b46bfc273a1c
5
5
  SHA512:
6
- metadata.gz: ac7da1390a3fedf1973a709b0ce5547ee99590d68dfdf46686d4fcf64e237b3a37e86f27b3dfc1350ef22bd264828d4c13705b79e05e6abc1f5ac20ae2cd8364
7
- data.tar.gz: 96154be98c24b04e56a49c2c6a4df93b94fe67bfa8b79c754c62e543187a7083418815049e05a47db516b16d58db91e2e9dc649a46f9d04243219c28af87df27
6
+ metadata.gz: 9fb588b0b214cad46930473827384993fb0577d9997ae1a60a2a5e808eb23a792697d95e877d31e959661322b7adf1c2c31ecaf41cc7a910e132ad728f31bab4
7
+ data.tar.gz: 240eb7a87911cb284cd6fc2526608f843dadfee100f25b7b9611e6a27531d440604ae9c7b1d8586b26b5b926292c01f98ffd97e64c51659c0bad983629322e41
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kube_cluster (0.17.0)
4
+ kube_cluster (0.17.1)
5
5
  activesupport (~> 8.0)
6
6
  kube_kubectl (~> 2.0)
7
7
  kube_schema (~> 1.7)
@@ -73,7 +73,7 @@ module Kube
73
73
 
74
74
  instance_exec(&block) if block
75
75
 
76
- _apply_limits(deployment)
76
+ deployment = _apply_limits(deployment)
77
77
  _apply_probes(deployment)
78
78
  end
79
79
 
@@ -88,7 +88,7 @@ module Kube
88
88
  private
89
89
 
90
90
  def _apply_limits(deployment)
91
- return if @_limits.empty?
91
+ return deployment if @_limits.empty?
92
92
 
93
93
  container = deployment.to_h[:spec][:template][:spec][:containers][0]
94
94
  resources = {}
@@ -108,12 +108,12 @@ module Kube
108
108
  container[:resources] = resources
109
109
  h = deployment.to_h
110
110
  h[:spec][:template][:spec][:containers][0] = container
111
- deployment.rebuild(h)
111
+ _replace(deployment, deployment.rebuild(h))
112
112
  end
113
113
 
114
114
  def _apply_probes(deployment)
115
- return if @_probes.empty?
116
- return unless @_probes[:url]
115
+ return deployment if @_probes.empty?
116
+ return deployment unless @_probes[:url]
117
117
 
118
118
  container = deployment.to_h[:spec][:template][:spec][:containers][0]
119
119
  url = @_probes[:url]
@@ -140,7 +140,14 @@ module Kube
140
140
 
141
141
  h = deployment.to_h
142
142
  h[:spec][:template][:spec][:containers][0] = container
143
- deployment.rebuild(h)
143
+ _replace(deployment, deployment.rebuild(h))
144
+ end
145
+
146
+ # rebuild returns a new resource; swap it into this manifest so the
147
+ # change actually lands in the rendered output.
148
+ def _replace(old, rebuilt)
149
+ @resources[@resources.index(old)] = rebuilt
150
+ rebuilt
144
151
  end
145
152
  end
146
153
  end
@@ -175,5 +182,63 @@ test do
175
182
  yaml.include?("stdin: true").should == true
176
183
  yaml.include?("tty: true").should == true
177
184
  end
185
+
186
+ it "renders limits from the block DSL" do
187
+ yaml = Kube::Cluster::Standard::DeploymentWithService
188
+ .new(
189
+ name: "limited",
190
+ image: "ruby/ruby",
191
+ port: 3000,
192
+ ) {
193
+ limits.cpu = { "500m" => Float::INFINITY }
194
+ limits.memory = { "1Gi" => "2Gi" }
195
+ }
196
+ .to_yaml
197
+
198
+ yaml.include?("cpu: 500m").should == true
199
+ yaml.include?("memory: 1Gi").should == true
200
+ yaml.include?("memory: 2Gi").should == true
201
+ # Infinity means request-only — no cpu limit is emitted.
202
+ yaml.scan(/cpu:/).length.should == 1
203
+ end
204
+
205
+ it "renders probes from the block DSL" do
206
+ yaml = Kube::Cluster::Standard::DeploymentWithService
207
+ .new(
208
+ name: "probed",
209
+ image: "ruby/ruby",
210
+ port: 3000,
211
+ ) {
212
+ probes.url = { path: "/healthz", port: "http" }
213
+ probes.liveness = { 120 => 30 }
214
+ probes.readiness = { 60 => 10 }
215
+ }
216
+ .to_yaml
217
+
218
+ yaml.include?("livenessProbe").should == true
219
+ yaml.include?("readinessProbe").should == true
220
+ yaml.include?("path: \"/healthz\"").should == true
221
+ yaml.include?("initialDelaySeconds: 120").should == true
222
+ yaml.include?("initialDelaySeconds: 60").should == true
223
+ end
224
+
225
+ it "renders limits and probes together" do
226
+ yaml = Kube::Cluster::Standard::DeploymentWithService
227
+ .new(
228
+ name: "both",
229
+ image: "ruby/ruby",
230
+ port: 3000,
231
+ ) {
232
+ limits.memory = { "1Gi" => "2Gi" }
233
+ probes.url = { path: "/healthz", port: "http" }
234
+ probes.readiness = { 5 => 5 }
235
+ }
236
+ .to_yaml
237
+
238
+ # The probe pass must not clobber the limits pass (each rebuilds the
239
+ # deployment; the second must start from the first's result).
240
+ yaml.include?("memory: 2Gi").should == true
241
+ yaml.include?("readinessProbe").should == true
242
+ end
178
243
  end
179
244
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kube
4
4
  module Cluster
5
- VERSION = "0.17.0"
5
+ VERSION = "0.17.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K