pfab 0.51.0 → 0.53.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: 06aa820e3141930ca45a670075b6824a23010f5f3568aa3c81edd1825ea452c2
4
+ data.tar.gz: 9d43a1c6d16ac3e44f057817fa50f0143d7e3ce6d9b9ca0446735ae060144dfe
5
5
  SHA512:
6
- metadata.gz: 24b51d55f108f38c95b6ae05a46104353033240a10a18481dafc56185377e9ae66735dc99f3c29276067bb361e16efa376dda5b05e7e33ff1e1abdbad0bf6429
7
- data.tar.gz: 361531b33dfec0ce581c53d7049d6142792d4264a76a975f252c590ce0aee973412196edbdd3972c6c800fdd6176c1dc968abd6817524b59a65e38fcb9fdf284
6
+ metadata.gz: 9e42f6a07719549799f99885888d33218dd69b0211e07ea7d927bf22b4d6d39984a4d246aa7f1c99afa8ccdd273eb2d96292363cb167b0a7c1c09e7ecff73464
7
+ data.tar.gz: 655b9ecb7007a4c19e27591a6edbe2acefcbce8a374ade1b1fb2e97985089503ae875d156cf269d969984f02e1dc148ca1e86a7702c444aab8e5b33fd65bc288
data/Gemfile.lock CHANGED
@@ -18,11 +18,12 @@ GIT
18
18
  GEM
19
19
  remote: https://rubygems.org/
20
20
  specs:
21
- activesupport (5.2.4.3)
21
+ activesupport (6.1.7.5)
22
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
- i18n (>= 0.7, < 2)
24
- minitest (~> 5.1)
25
- tzinfo (~> 1.1)
23
+ i18n (>= 1.6, < 2)
24
+ minitest (>= 5.1)
25
+ tzinfo (~> 2.0)
26
+ zeitwerk (~> 2.3)
26
27
  addressable (2.8.0)
27
28
  public_suffix (>= 2.0.2, < 5.0)
28
29
  builder (3.2.4)
@@ -30,7 +31,7 @@ GEM
30
31
  coderay (1.1.3)
31
32
  commander (4.4.6)
32
33
  highline (~> 1.7.2)
33
- concurrent-ruby (1.1.9)
34
+ concurrent-ruby (1.2.3)
34
35
  descendants_tracker (0.0.4)
35
36
  thread_safe (~> 0.3, >= 0.3.1)
36
37
  docile (1.3.1)
@@ -64,27 +65,27 @@ GEM
64
65
  oauth2 (~> 1.0)
65
66
  hashie (3.6.0)
66
67
  highline (1.7.10)
67
- i18n (1.8.11)
68
+ i18n (1.14.5)
68
69
  concurrent-ruby (~> 1.0)
69
70
  json (1.8.6)
70
71
  jwt (2.3.0)
71
72
  kamelcase (0.0.2)
72
73
  semver2 (~> 3)
73
74
  method_source (1.0.0)
74
- mini_portile2 (2.8.0)
75
- minitest (5.15.0)
75
+ mini_portile2 (2.8.6)
76
+ minitest (5.22.3)
76
77
  multi_json (1.15.0)
77
78
  multi_xml (0.6.0)
78
79
  multipart-post (2.1.1)
79
- nokogiri (1.13.6)
80
- mini_portile2 (~> 2.8.0)
80
+ nokogiri (1.16.5)
81
+ mini_portile2 (~> 2.8.2)
81
82
  racc (~> 1.4)
82
- oauth2 (1.4.7)
83
- faraday (>= 0.8, < 2.0)
83
+ oauth2 (1.4.11)
84
+ faraday (>= 0.17.3, < 3.0)
84
85
  jwt (>= 1.0, < 3.0)
85
86
  multi_json (~> 1.3)
86
87
  multi_xml (~> 0.5)
87
- rack (>= 1.2, < 3)
88
+ rack (>= 1.2, < 4)
88
89
  power_assert (1.1.3)
89
90
  pry (0.14.2)
90
91
  coderay (~> 1.1)
@@ -94,8 +95,8 @@ GEM
94
95
  pry (>= 0.13, < 0.15)
95
96
  psych (4.0.2)
96
97
  public_suffix (4.0.6)
97
- racc (1.6.0)
98
- rack (2.2.3)
98
+ racc (1.7.3)
99
+ rack (3.0.11)
99
100
  rake (13.0.6)
100
101
  rchardet (1.8.0)
101
102
  rdoc (3.12.2)
@@ -111,8 +112,9 @@ GEM
111
112
  test-unit (3.2.9)
112
113
  power_assert
113
114
  thread_safe (0.3.6)
114
- tzinfo (1.2.9)
115
- thread_safe (~> 0.1)
115
+ tzinfo (2.0.6)
116
+ concurrent-ruby (~> 1.0)
117
+ zeitwerk (2.6.14)
116
118
 
117
119
  PLATFORMS
118
120
  ruby
data/lib/pfab/cli.rb CHANGED
@@ -4,6 +4,7 @@ require "yaml"
4
4
  require "json"
5
5
  require 'active_support/core_ext/hash/indifferent_access'
6
6
  require 'styled_yaml'
7
+ require 'digest'
7
8
 
8
9
  module Pfab
9
10
  class CLI
@@ -16,6 +17,7 @@ module Pfab
16
17
 
17
18
  if File.exist? "application.yaml"
18
19
  @application_yaml = YAML.load(File.read("application.yaml")).with_indifferent_access
20
+ @application_yaml_hash = Digest::SHA256.hexdigest(@application_yaml.to_json)
19
21
  else
20
22
  raise "I need to be run in a directory with a application.yaml"
21
23
  end
@@ -291,6 +293,7 @@ module Pfab
291
293
  def yy
292
294
  Pfab::Yamls.new(apps: all_runnables,
293
295
  application_yaml: @application_yaml,
296
+ application_yaml_hash: @application_yaml_hash,
294
297
  env: $env,
295
298
  sha: get_current_sha,
296
299
  image_name: image_name,
@@ -1,3 +1,5 @@
1
+ require 'securerandom'
2
+
1
3
  module Pfab
2
4
  module Templates
3
5
  class Base
@@ -63,6 +65,10 @@ module Pfab
63
65
  "#{@data['application']}.#{application_type}.#{@data['deployed_name']}"
64
66
  end
65
67
 
68
+ def deploy_unique_id
69
+ @data['sha'] + "-" + @data['application_yaml_hash'][0,8]
70
+ end
71
+
66
72
  def env_from
67
73
  env_from = []
68
74
  env_from << @data.dig("application_yaml", :env_from)
@@ -14,7 +14,9 @@ module Pfab
14
14
  puts "skipping ingress because ingress_disabled = #{@data['generateIngressEnabled']}"
15
15
  end
16
16
  f << StyledYAML.dump(deployment.deep_stringify_keys)
17
- f << StyledYAML.dump(pod_disruption_budget.deep_stringify_keys)
17
+ if get("replicas") || 1 > 1
18
+ f << StyledYAML.dump(pod_disruption_budget.deep_stringify_keys)
19
+ end
18
20
  end
19
21
  end
20
22
 
@@ -180,16 +182,78 @@ module Pfab
180
182
  ANTI_AFFINITY_TYPES = %w[disabled required preferred]
181
183
  ANTI_AFFINITY_MODE = 'antiAffinityMode'
182
184
  ANTI_AFFINITY_PREFERRED_MODE_WEIGHT = 'antiAffinityPreferredModeWeight'
185
+ ZONE_ANTI_AFFINITY_MODE = 'zoneAntiAffinityMode'
186
+ ZONE_ANTI_AFFINITY_PREFERRED_MODE_WEIGHT = 'zoneAntiAffinityPreferredModeWeight'
187
+
183
188
 
184
189
  def anti_affinity
185
- if app_vars.has_key?(ANTI_AFFINITY_MODE)
186
- antiAffinityMode = app_vars[ANTI_AFFINITY_MODE]
190
+ p = host_anti_affinity
191
+ z = zone_anti_affinity
192
+ m = merge_anti_affinity(p, z)
193
+ return m
194
+ end
195
+
196
+
197
+ def host_anti_affinity
198
+ anti_affinity_builder(ANTI_AFFINITY_MODE, ANTI_AFFINITY_PREFERRED_MODE_WEIGHT, "kubernetes.io/hostname")
199
+ end
200
+
201
+ def zone_anti_affinity
202
+ anti_affinity_builder(ZONE_ANTI_AFFINITY_MODE, ZONE_ANTI_AFFINITY_PREFERRED_MODE_WEIGHT, "topology.kubernetes.io/zone")
203
+ end
204
+
205
+ def merge_anti_affinity(pod_anti_affinity, zone_anti_affinity)
206
+ merged = {}
207
+
208
+ if pod_anti_affinity.empty? && zone_anti_affinity.empty?
209
+ merged = {}
210
+ elsif pod_anti_affinity.empty?
211
+ merged = zone_anti_affinity
212
+ elsif zone_anti_affinity.empty?
213
+ merged = pod_anti_affinity
214
+ else
215
+ merged[:podAntiAffinity] = {}
216
+
217
+ required_key = :requiredDuringSchedulingIgnoredDuringExecution
218
+ preferred_key = :preferredDuringSchedulingIgnoredDuringExecution
219
+
220
+ [required_key, preferred_key].each do |key|
221
+ if pod_anti_affinity.dig(:podAntiAffinity, key) && zone_anti_affinity.dig(:podAntiAffinity, key)
222
+ merged[:podAntiAffinity][key] = pod_anti_affinity[:podAntiAffinity][key] + zone_anti_affinity[:podAntiAffinity][key]
223
+ elsif pod_anti_affinity.dig(:podAntiAffinity, key)
224
+ merged[:podAntiAffinity][key] = pod_anti_affinity[:podAntiAffinity][key]
225
+ elsif zone_anti_affinity.dig(:podAntiAffinity, key)
226
+ merged[:podAntiAffinity][key] = zone_anti_affinity[:podAntiAffinity][key]
227
+ end
228
+ end
229
+ end
230
+
231
+ merged
232
+ end
233
+
234
+
235
+ def anti_affinity_builder(key, weight_key, topology_key)
236
+ antiAffinityMode = get(key) || "disabled"
237
+ if antiAffinityMode
187
238
  affinitySelector = {
188
- topologyKey: "kubernetes.io/hostname",
239
+ topologyKey: topology_key,
189
240
  labelSelector: {
190
- matchLabels: {
191
- "deployed-name" => @data['deployed_name'],
192
- },
241
+ matchExpressions: [
242
+ {
243
+ key: "deployed-name",
244
+ operator: "In",
245
+ values: [
246
+ @data['deployed_name']
247
+ ]
248
+ },
249
+ {
250
+ key: "deployment-unique-id",
251
+ operator: "In",
252
+ values: [
253
+ StyledYAML.double_quoted(deploy_unique_id)
254
+ ]
255
+ }
256
+ ]
193
257
  },
194
258
  }
195
259
 
@@ -207,14 +271,14 @@ module Pfab
207
271
  { podAntiAffinity: {
208
272
  preferredDuringSchedulingIgnoredDuringExecution: [
209
273
  {
210
- weight: app_vars[ANTI_AFFINITY_PREFERRED_MODE_WEIGHT] || 100,
274
+ weight: app_vars[weight_key] || 100,
211
275
  podAffinityTerm: affinitySelector
212
276
  }
213
277
  ]
214
278
  }
215
279
  }
216
280
  else
217
- raise "Unexpected value #{antiAffinityMode} specified for `#{ANTI_AFFINITY_MODE}`. Valid selections are #{ANTI_AFFINITY_TYPES}"
281
+ raise "Unexpected value #{antiAffinityMode} specified for `#{key}`. Valid selections are #{ANTI_AFFINITY_TYPES}"
218
282
  end
219
283
  end
220
284
  return {}
@@ -264,6 +328,7 @@ module Pfab
264
328
  "deployed-name" => @data['deployed_name'],
265
329
  "application-type" => application_type,
266
330
  "deploy-id" => deploy_id,
331
+ "deploy-unique-id" => StyledYAML.double_quoted(deploy_unique_id),
267
332
  "tags.datadoghq.com/env": @data['env'],
268
333
  "tags.datadoghq.com/service": @data['deployed_name'],
269
334
  "tags.datadoghq.com/version": StyledYAML.double_quoted(@data['sha'])
@@ -291,6 +356,7 @@ module Pfab
291
356
  application: @data['application'],
292
357
  "deployed-name" => @data['deployed_name'],
293
358
  "application-type" => "web",
359
+ "deploy-unique-id" => StyledYAML.double_quoted(deploy_unique_id),
294
360
  "tags.datadoghq.com/env": @data['env'],
295
361
  "tags.datadoghq.com/service": @data['deployed_name'],
296
362
  "tags.datadoghq.com/version": StyledYAML.double_quoted(@data['sha'])
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 = 53
5
5
  PATCH = 0
6
6
  BUILD = nil
7
7
 
data/lib/pfab/yamls.rb CHANGED
@@ -2,7 +2,7 @@ require 'pry'
2
2
  module Pfab
3
3
  class Yamls
4
4
 
5
- def initialize(apps:, application_yaml:, image_name:, env:, sha:, config:)
5
+ def initialize(apps:, application_yaml:, image_name:, env:, sha:, config:, application_yaml_hash:)
6
6
  @apps = apps
7
7
  namespace = application_yaml.dig(env.to_s, "namespace") || application_yaml["namespace"]
8
8
  raise "No namespace founds" unless namespace
@@ -15,6 +15,7 @@ module Pfab
15
15
  'application' => application_yaml["name"],
16
16
  'application_yaml' => application_yaml,
17
17
  'namespace' => namespace,
18
+ 'application_yaml_hash' => application_yaml_hash
18
19
  }
19
20
  end
20
21
 
data/pfab.gemspec CHANGED
@@ -2,16 +2,16 @@
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.53.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.53.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]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2024-05-13"
14
+ s.date = "2024-05-14"
15
15
  s.description = "k8s helper".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.executables = ["pfab".freeze]
metadata CHANGED
@@ -1,14 +1,14 @@
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.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-13 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander