Module: Kontena::Cli::Helpers::HealthHelper
- Defined in:
- lib/kontena/cli/helpers/health_helper.rb
Instance Method Summary collapse
-
#grid_health(grid, nodes) ⇒ Symbol
Validate grid nodes configuration and status.
- #health_icon(health) ⇒ Object
- #node_etcd_health(node_etcd_health) ⇒ Symbol, String
-
#node_health(node, grid_health) ⇒ Symbol
Validate grid node status based on the grid health.
Instance Method Details
#grid_health(grid, nodes) ⇒ Symbol
Validate grid nodes configuration and status
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kontena/cli/helpers/health_helper.rb', line 25 def grid_health(grid, nodes) initial = grid['initial_size'] minimum = grid['initial_size'] / 2 + 1 # a majority is required for etcd quorum online = nodes.select{|node| node['initial_member'] && node['connected']} if online.length < minimum return :error elsif online.length < initial return :warning else return :ok end end |
#health_icon(health) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kontena/cli/helpers/health_helper.rb', line 3 def health_icon(health) case health when nil " " when :ok pastel.green('⊛') when :warning pastel.yellow('⊙') when :error pastel.red('⊗') when :offline pastel.dark('⊝') else fail "Invalid health=#{health}" end end |
#node_etcd_health(node_etcd_health) ⇒ Symbol, String
55 56 57 58 59 60 61 62 63 |
# File 'lib/kontena/cli/helpers/health_helper.rb', line 55 def node_etcd_health(node_etcd_health) if node_etcd_health['health'] return :ok, "healthy" elsif node_etcd_health['error'] return :error, "unhealthy: #{node_etcd_health['error']}" else return :error, "unhealthy" end end |
#node_health(node, grid_health) ⇒ Symbol
Validate grid node status based on the grid health
45 46 47 48 49 50 51 |
# File 'lib/kontena/cli/helpers/health_helper.rb', line 45 def node_health(node, grid_health) if node['initial_member'] return node['connected'] ? grid_health : :offline else return node['connected'] ? :ok : :offline end end |