pfab 0.58.6 → 0.58.8

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: e2e4518728aafd25de6e2d32503a6a287007d78deb1a18b657db3af110a6a486
4
- data.tar.gz: a5e3614ff8fef07e2b70bd624eb7b3c845bcb352aebf5f0e29b3979d8137d9c0
3
+ metadata.gz: e7e3d292ab2f6eee610144e871f341ca2bbb128854552b98d2a4e197850d8328
4
+ data.tar.gz: 6f8c89d9512f0956039fe97c860a8a8e4edfcc66e4a22a992a3bf2e9a3f01871
5
5
  SHA512:
6
- metadata.gz: 1fa91a90727c9685754c7239239e6d9035f0c16cce1f28db3a1cb394f66f3cbe0ee342b82203127f66251a1cdea4e1e689b8f51daa82b882e05c2afd14edf2f4
7
- data.tar.gz: b9f124a10d4221c1384925680d21dac2e87cdf11ae9011a525a395cceb49ec720e1ff05099ef27940e82a1905eb673e7c2738287675b3864fbc3e3fe8e610a71
6
+ metadata.gz: b516b4d73d6e281da4e5ce9bc1af4f1e3697f7046af5a24df4df3e154557e08013cf57ff3c7ce731168d3a9e0ee034cb0ec6da4765330aaa9f2527a74c7d0a39
7
+ data.tar.gz: eb666a562d7e5f86f0ddda3edaf9d038d23ab60b29e3dd27ed66ca47f9c62035aa20201e9d56c20d81fd5cb16608278741f991905bf6b98a1a93423f7de48686
data/lib/pfab/cli.rb CHANGED
@@ -5,6 +5,7 @@ require "json"
5
5
  require 'active_support/core_ext/hash/indifferent_access'
6
6
  require 'styled_yaml'
7
7
  require 'digest'
8
+ require 'open3'
8
9
 
9
10
  module Pfab
10
11
  class CLI
@@ -68,15 +69,22 @@ module Pfab
68
69
  c.option "-t", "--timeout TIMEOUT", Integer, "timeout for rollout (default 360s)"
69
70
  c.option "-r", "--retries RETRIES", Integer, "number of retries for rollout (default 3)"
70
71
  c.option "-s", "--sleep SLEEP", Integer, "sleep duration between retries in seconds (default 5)"
72
+ c.option "-g", "--tagged TAGGED", String, "target deployables tagged with TAGGED"
71
73
 
72
74
  c.action do |args, options|
73
75
  options.default timeout: 360, retries: 3, sleep: 5
74
- app_name = get_app_name(all: true)
76
+ app_name = ""
77
+ if options.tagged && options.tagged != ""
78
+ app_name = "Apps tagged with #{options.tagged}"
79
+ else
80
+ app_name = get_app_name(all: true)
81
+ end
82
+
75
83
  puts "Shipping #{app_name}"
76
84
  success = cmd_build
77
85
  if success
78
86
  cmd_generate_yaml
79
- cmd_apply(timeout: options.timeout, retries: options.retries, sleep_duration: options.sleep)
87
+ cmd_apply(timeout: options.timeout, retries: options.retries, sleep_duration: options.sleep, tagged: options.tagged)
80
88
  end
81
89
  end
82
90
  end
@@ -209,11 +217,13 @@ module Pfab
209
217
  run!
210
218
  end
211
219
 
212
- def cmd_apply(timeout: 240, retries: 3, sleep_duration: 5)
220
+ def cmd_apply(timeout: 240, retries: 3, sleep_duration: 5, tagged: nil)
213
221
  set_kube_context
214
222
  success = true
215
223
 
216
- get_apps.each do |app_name|
224
+ apps = tagged ? deployables.select { |k, v| v[:tags]&.include?(tagged) }.keys : get_apps
225
+
226
+ apps.each do |app_name|
217
227
  app = deployables[app_name]
218
228
  if app[:deployable_type] == "cron"
219
229
  deployed_name = deployed_name(app)
@@ -233,28 +243,30 @@ module Pfab
233
243
  selector = "application=#{@application_yaml['name']}"
234
244
  deployment_json = `kubectl get deployment -l #{selector} -o json --namespace=#{yy.namespace}`
235
245
  deployments = JSON.parse(deployment_json)
236
-
246
+
237
247
  if deployments["items"].any?
238
248
  deployments["items"].each do |deployment|
239
249
  deployment_name = deployment["metadata"]["name"]
240
250
  puts "Waiting for deployment #{deployment_name} to roll out..."
241
251
 
242
252
  rollout_success = false
243
-
253
+
244
254
  retries.times do |attempt|
245
- rollout_success = kubectl("rollout status deployment/#{deployment_name} --timeout=#{timeout}s")
255
+ rollout_result = kubectl_with_output("rollout status deployment/#{deployment_name} --timeout=#{timeout}s")
256
+ rollout_success = rollout_result.success?
246
257
  if rollout_success
247
258
  puts "Deployment #{deployment_name} successfully rolled out. Attempt #{attempt + 1}/#{retries}."
248
259
  break
249
260
  else
250
261
  puts "Attempt #{attempt + 1}/#{retries}: Deployment #{deployment_name} failed to roll out within the specified timeout."
262
+ puts "Output was #{rollout_result}"
251
263
  if attempt < retries - 1
252
264
  puts "Retrying in #{sleep_duration} seconds..."
253
265
  sleep(sleep_duration)
254
266
  end
255
267
  end
256
268
  end
257
-
269
+
258
270
  unless rollout_success
259
271
  puts "Deployment #{deployment_name} failed to roll out after #{retries} attempts."
260
272
  return false
@@ -392,6 +404,10 @@ module Pfab
392
404
  result == true
393
405
  end
394
406
 
407
+ def kubectl_with_output(cmd, post_cmd = "")
408
+ puts_and_system_with_output("kubectl #{cmd} --namespace=#{yy.namespace} #{post_cmd}")
409
+ end
410
+
395
411
  def puts_and_system(cmd)
396
412
  puts cmd
397
413
  if $dryrun
@@ -402,6 +418,18 @@ module Pfab
402
418
  end
403
419
  end
404
420
 
421
+ def puts_and_system_with_output(cmd)
422
+ puts cmd
423
+ if $dryrun
424
+ dryrun_message = "dry run, didn't run that"
425
+ puts dryrun_message
426
+ CommandResult.new(stdout: dryrun_message, stderr: dryrun_message, exit_status_code: 0)
427
+ else
428
+ stdout, stderr, status = Open3.capture3(cmd)
429
+ CommandResult.new(stdout: stdout, stderr: stderr, exit_status_code: status.exitstatus)
430
+ end
431
+ end
432
+
405
433
  def deployables
406
434
  @_deployables ||= calculate_runnables("deployables")
407
435
  end
@@ -424,6 +452,7 @@ module Pfab
424
452
  application: application,
425
453
  deployable: deployable,
426
454
  deployable_type: deployable_type,
455
+ tags: dep["tags"],
427
456
  command: dep["command"],
428
457
  }
429
458
  end
@@ -456,4 +485,14 @@ module Pfab
456
485
  (name == "all") ? deployables.keys : [name]
457
486
  end
458
487
  end
488
+
489
+ CommandResult = Struct.new(:stdout, :stderr, :exit_status_code, keyword_init: true) do
490
+ def success?
491
+ exit_status_code == 0
492
+ end
493
+
494
+ def to_s
495
+ "status: #{status.exitstatus}\n\nstdout: #{stdout}\n\nstderr: #{stderr}\n\n"
496
+ end
497
+ end
459
498
  end
data/lib/pfab/version.rb CHANGED
@@ -2,7 +2,7 @@ module Pfab
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 58
5
- PATCH = 6
5
+ PATCH = 8
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
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.58.6 ruby lib
5
+ # stub: pfab 0.58.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pfab".freeze
9
- s.version = "0.58.6"
9
+ s.version = "0.58.8"
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-10-09"
14
+ s.date = "2024-10-21"
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.58.6
4
+ version: 0.58.8
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-10-09 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander