pfab 0.51.0 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2ffa684bec7e96dac9c896b6f037f02e9c73e2c9c2943c47fc400c59c0d490d
4
- data.tar.gz: a69b88c63cdc12a417c2ed80373c69b31ba5662c412efa6131dfc51168b2b7fa
3
+ metadata.gz: e19f6543864483d014f040e4d0ba5c2e8322bb20ca5604f351c13a36f53b20cd
4
+ data.tar.gz: 1d1afb9c39e0e6d69f5849bd171e2a659174ec747c601239c6e9cc051da92d6f
5
5
  SHA512:
6
- metadata.gz: 24b51d55f108f38c95b6ae05a46104353033240a10a18481dafc56185377e9ae66735dc99f3c29276067bb361e16efa376dda5b05e7e33ff1e1abdbad0bf6429
7
- data.tar.gz: 361531b33dfec0ce581c53d7049d6142792d4264a76a975f252c590ce0aee973412196edbdd3972c6c800fdd6176c1dc968abd6817524b59a65e38fcb9fdf284
6
+ metadata.gz: c402604e6fd169342b2aff975ecb79b15b59cf67399c91a57c15597df3b7629d0a0eb84c5df14e784c09ca4612fafdad60e620bae52a76f1da269030c05d9fa4
7
+ data.tar.gz: 569c405d1a4be90a456ef7dbb8f5e3cadf842b475644dbb79e85fc6d2765dc557e75b147dba2c58ae88c67ef37d0cab5f45bf9c000983ccb69535597c1a42d40
@@ -180,12 +180,64 @@ module Pfab
180
180
  ANTI_AFFINITY_TYPES = %w[disabled required preferred]
181
181
  ANTI_AFFINITY_MODE = 'antiAffinityMode'
182
182
  ANTI_AFFINITY_PREFERRED_MODE_WEIGHT = 'antiAffinityPreferredModeWeight'
183
+ ZONE_ANTI_AFFINITY_MODE = 'zoneAntiAffinityMode'
184
+ ZONE_ANTI_AFFINITY_PREFERRED_MODE_WEIGHT = 'zoneAntiAffinityPreferredModeWeight'
185
+
183
186
 
184
187
  def anti_affinity
185
- if app_vars.has_key?(ANTI_AFFINITY_MODE)
186
- antiAffinityMode = app_vars[ANTI_AFFINITY_MODE]
188
+ p = host_anti_affinity
189
+ z = zone_anti_affinity
190
+ printf("host anti affinity: %s\n", p)
191
+ printf("zone anti affinity: %s\n", z)
192
+ m = merge_anti_affinity(p, z)
193
+ printf("merged anti affinity: %s\n", m)
194
+ return m
195
+ end
196
+
197
+
198
+ def host_anti_affinity
199
+ anti_affinity_builder(ANTI_AFFINITY_MODE, ANTI_AFFINITY_PREFERRED_MODE_WEIGHT, "kubernetes.io/hostname")
200
+ end
201
+
202
+ def zone_anti_affinity
203
+ anti_affinity_builder(ZONE_ANTI_AFFINITY_MODE, ZONE_ANTI_AFFINITY_PREFERRED_MODE_WEIGHT, "topology.kubernetes.io/zone")
204
+ end
205
+
206
+ def merge_anti_affinity(pod_anti_affinity, zone_anti_affinity)
207
+ merged = {}
208
+
209
+ if pod_anti_affinity.empty? && zone_anti_affinity.empty?
210
+ merged = {}
211
+ elsif pod_anti_affinity.empty?
212
+ merged = zone_anti_affinity
213
+ elsif zone_anti_affinity.empty?
214
+ merged = pod_anti_affinity
215
+ else
216
+ merged[:podAntiAffinity] = {}
217
+
218
+ required_key = :requiredDuringSchedulingIgnoredDuringExecution
219
+ preferred_key = :preferredDuringSchedulingIgnoredDuringExecution
220
+
221
+ [required_key, preferred_key].each do |key|
222
+ if pod_anti_affinity.dig(:podAntiAffinity, key) && zone_anti_affinity.dig(:podAntiAffinity, key)
223
+ merged[:podAntiAffinity][key] = pod_anti_affinity[:podAntiAffinity][key] + zone_anti_affinity[:podAntiAffinity][key]
224
+ elsif pod_anti_affinity.dig(:podAntiAffinity, key)
225
+ merged[:podAntiAffinity][key] = pod_anti_affinity[:podAntiAffinity][key]
226
+ elsif zone_anti_affinity.dig(:podAntiAffinity, key)
227
+ merged[:podAntiAffinity][key] = zone_anti_affinity[:podAntiAffinity][key]
228
+ end
229
+ end
230
+ end
231
+
232
+ merged
233
+ end
234
+
235
+
236
+ def anti_affinity_builder(key, weight_key, topology_key)
237
+ antiAffinityMode = get(key) || "disabled"
238
+ if antiAffinityMode
187
239
  affinitySelector = {
188
- topologyKey: "kubernetes.io/hostname",
240
+ topologyKey: topology_key,
189
241
  labelSelector: {
190
242
  matchLabels: {
191
243
  "deployed-name" => @data['deployed_name'],
@@ -207,14 +259,14 @@ module Pfab
207
259
  { podAntiAffinity: {
208
260
  preferredDuringSchedulingIgnoredDuringExecution: [
209
261
  {
210
- weight: app_vars[ANTI_AFFINITY_PREFERRED_MODE_WEIGHT] || 100,
262
+ weight: app_vars[weight_key] || 100,
211
263
  podAffinityTerm: affinitySelector
212
264
  }
213
265
  ]
214
266
  }
215
267
  }
216
268
  else
217
- raise "Unexpected value #{antiAffinityMode} specified for `#{ANTI_AFFINITY_MODE}`. Valid selections are #{ANTI_AFFINITY_TYPES}"
269
+ raise "Unexpected value #{antiAffinityMode} specified for `#{key}`. Valid selections are #{ANTI_AFFINITY_TYPES}"
218
270
  end
219
271
  end
220
272
  return {}
data/lib/pfab/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Pfab
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 51
4
+ MINOR = 52
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
data/pfab.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: pfab 0.51.0 ruby lib
5
+ # stub: pfab 0.52.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pfab".freeze
9
- s.version = "0.51.0"
9
+ s.version = "0.52.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer