Class: Kdep::RolloutTracker
- Inherits:
-
Object
- Object
- Kdep::RolloutTracker
- Defined in:
- lib/kdep/rollout_tracker.rb
Overview
Declarative rollout-restart triggers. Phases that apply resources register sources; at end of run the tracker looks up matching rollout_on rules and restarts the unique set of targets once.
sources are “kind/name” (configmap, secret). targets are “kind/name” (deployment, statefulset, daemonset).
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #errors? ⇒ Boolean
- #flush! ⇒ Object
-
#initialize(rollout_on:, namespace:, ui:, dry_run: false) ⇒ RolloutTracker
constructor
A new instance of RolloutTracker.
- #record_applied(kind, name) ⇒ Object
Constructor Details
#initialize(rollout_on:, namespace:, ui:, dry_run: false) ⇒ RolloutTracker
Returns a new instance of RolloutTracker.
13 14 15 16 17 18 19 20 |
# File 'lib/kdep/rollout_tracker.rb', line 13 def initialize(rollout_on:, namespace:, ui:, dry_run: false) @rules = rollout_on || [] @namespace = namespace @ui = ui @dry_run = dry_run @applied = Set.new @errors = [] end |
Instance Method Details
#errors? ⇒ Boolean
52 53 54 |
# File 'lib/kdep/rollout_tracker.rb', line 52 def errors? !@errors.empty? end |
#flush! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kdep/rollout_tracker.rb', line 26 def flush! targets = Set.new @rules.each do |rule| src = normalize(rule["source"]) next unless @applied.include?(src) Array(rule["targets"]).each { |t| targets << normalize(t) } end targets.sort.each do |target| kind, name = target.split("/", 2) if @dry_run @ui.info("[dry-run] would rollout-restart #{kind}/#{name}") next end begin Kdep::Kubectl.rollout_restart(kind, name, namespace: @namespace) @ui.info("rollout-restarted #{kind}/#{name}") rescue Kdep::Kubectl::Error => e @errors << "#{kind}/#{name}: #{e.}" @ui.error("rollout-restart failed for #{kind}/#{name}: #{e.}") end end @errors.empty? end |
#record_applied(kind, name) ⇒ Object
22 23 24 |
# File 'lib/kdep/rollout_tracker.rb', line 22 def record_applied(kind, name) @applied << "#{kind.to_s.downcase}/#{name}" end |