Skip to content
This repository was archived by the owner on Aug 29, 2018. It is now read-only.

Commit cacbbf9

Browse files
author
OpenShift Bot
committed
Merge pull request #6382 from sallyom/bz1122084
Merged by openshift-bot
2 parents 099c974 + bd8961c commit cacbbf9

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

node/lib/openshift-origin-node/model/node.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ def self.node_utilization
347347
res['gears_started_count'] = 0
348348
res['gears_deploying_count'] = 0
349349
res['gears_unknown_count'] = 0
350+
res['node_disk_free'] = 0
351+
res['node_total_size'] = 0
350352
OpenShift::Runtime::ApplicationContainer.all(nil, false).each do |app|
351353
# res['git_repos_count'] += 1 if ApplicationRepository.new(app).exists?
352354
res['gears_total_count'] += 1
@@ -366,6 +368,15 @@ def self.node_utilization
366368
end
367369
end
368370

371+
# fact for available disk space on a node, considered in gear moves to ensure minimum buffer of free space on nodes
372+
mountpoint = self.get_gear_mountpoint
373+
df_cmd = "df -aP #{mountpoint} | awk -F' ' 'NR == 2 {print $2,$4}'"
374+
df_output, stderr, rc = Utils.oo_spawn(df_cmd)
375+
raise NodeCommandException.new "Error: #{stderr} executing command #{df_cmd}" unless rc == 0
376+
df_total_size, df_free = df_output.split
377+
res['node_total_size'] = df_total_size.to_i
378+
res['node_disk_free'] = df_free.to_i
379+
369380
# consider a gear active unless explicitly not
370381
res['gears_active_count'] = res['gears_total_count'] - res['gears_idled_count'] - res['gears_stopped_count']
371382
res['gears_usage_pct'] = begin res['gears_total_count'] * 100.0 / res['max_active_gears'].to_f; rescue; 0.0; end

node/test/unit/node_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
require 'yaml'
1919
require 'pp'
2020

21+
module FakeFS
22+
class File
23+
class Stat
24+
def dev
25+
return 5555
26+
end
27+
end
28+
end
29+
end
30+
2131
class NodeTest < OpenShift::NodeTestCase
2232

2333
def setup

plugins/msg-broker/mcollective/lib/openshift/mcollective_application_container_proxy.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,34 @@ def get_quota_files
788788
rpc_get_fact_direct('quota_files').to_i
789789
end
790790

791+
# <<accessor>>
792+
# Get the available disk space of a Node
793+
#
794+
# RETURNS:
795+
# * Integer: the available disk space of a node in blocks
796+
#
797+
# NOTES:
798+
# * method on Node
799+
# * calls rpc_get_fact_direct
800+
#
801+
def get_node_disk_free
802+
rpc_get_fact_direct('node_disk_free').to_i
803+
end
804+
805+
# <<accessor>>
806+
# Get the total disk space of a Node
807+
#
808+
# RETURNS:
809+
# * Integer: the total disk space of a node in blocks
810+
#
811+
# NOTES:
812+
# * method on Node
813+
# * calls rpc_get_fact_direct
814+
#
815+
def get_node_total_size
816+
rpc_get_fact_direct('node_total_size').to_i
817+
end
818+
791819
#
792820
# Add a component to an existing gear on the node
793821
#
@@ -2375,7 +2403,18 @@ def rsync_destination_container(gear, destination_container, destination_distric
23752403
reply = ResultIO.new
23762404
source_container = gear.get_proxy
23772405
platform = gear.group_instance.platform
2406+
quota = get_quota(gear)
2407+
source_used_blocks = quota[1] unless quota.nil?
23782408
log_debug "DEBUG: Gear platform is '#{platform}'"
2409+
destination_avail_space = destination_container.get_node_disk_free
2410+
destination_total_space = destination_container.get_node_total_size
2411+
2412+
# check here to make sure addition of gear to destination_container
2413+
# will not result in > 95% full destination_container
2414+
if (destination_avail_space - source_used_blocks.to_i)/destination_total_space > 0.05
2415+
raise OpenShift::NodeUnavailableException.new("Gear '#{gear.uuid}' cannot be moved to '#{destination_container.id}'. Not enough disk space, node would be > 95% full after move.", 140)
2416+
end
2417+
23792418
log_debug "DEBUG: Creating new account for gear '#{gear.uuid}' on #{destination_container.id}"
23802419
sshkey_required = false
23812420
initial_deployment_dir_required = false

plugins/msg-node/mcollective/facts/openshift_facts.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def get_node_config_value(key, default)
5050
#
5151
results = OpenShift::Runtime::Node.node_utilization
5252

53+
Facter.add(:node_disk_free) { setcode { results['node_disk_free'] } }
54+
Facter.add(:node_total_size) { setcode { results['node_total_size'] } }
5355
Facter.add(:node_profile) { setcode { results['node_profile'] } }
5456
Facter.add(:max_active_gears) { setcode { results['max_active_gears'] || '0' } }
5557
Facter.add(:no_overcommit_active) { setcode { results['no_overcommit_active'] || false } }

0 commit comments

Comments
 (0)