Merge pull request #122 from hjacobs/allocatable-resources

#121 show and honor node allocatable
This commit is contained in:
Henning Jacobs
2017-02-12 14:20:11 +01:00
committed by GitHub
4 changed files with 21 additions and 7 deletions

View File

@@ -24,20 +24,24 @@ export default class Bars extends PIXI.Graphics {
const cpuHeight = barHeight / bars.resources.cpu.capacity const cpuHeight = barHeight / bars.resources.cpu.capacity
bars.interactive = true bars.interactive = true
bars.lineStyle(0, 0xaaffaa, 1) bars.lineStyle(0, 0xaaffaa, 1)
bars.beginFill(getBarColor(bars.resources.cpu.requested, bars.resources.cpu.capacity), 1) bars.beginFill(getBarColor(bars.resources.cpu.requested, bars.resources.cpu.capacity - bars.resources.cpu.reserved), 1)
bars.drawRect(5, 110 - bars.resources.cpu.requested * cpuHeight, 2.5, bars.resources.cpu.requested * cpuHeight) bars.drawRect(5, 110 - (bars.resources.cpu.requested + bars.resources.cpu.reserved) * cpuHeight, 2.5, (bars.resources.cpu.requested + bars.resources.cpu.reserved) * cpuHeight)
bars.beginFill(getBarColor(bars.resources.cpu.used, bars.resources.cpu.capacity), 1) bars.beginFill(getBarColor(bars.resources.cpu.used, bars.resources.cpu.capacity), 1)
bars.drawRect(7.5, 110 - bars.resources.cpu.used * cpuHeight, 2.5, bars.resources.cpu.used * cpuHeight) bars.drawRect(7.5, 110 - bars.resources.cpu.used * cpuHeight, 2.5, bars.resources.cpu.used * cpuHeight)
bars.endFill() bars.endFill()
bars.lineStyle(1, App.current.theme.primaryColor, 1)
bars.drawRect(5, 110 - bars.resources.cpu.reserved * cpuHeight, 5, bars.resources.cpu.reserved * cpuHeight)
// Memory // Memory
const scale = bars.resources.memory.capacity / barHeight const scale = bars.resources.memory.capacity / barHeight
bars.lineStyle(0, 0xaaffaa, 1) bars.lineStyle(0, 0xaaffaa, 1)
bars.beginFill(getBarColor(bars.resources.memory.requested, bars.resources.memory.capacity), 1) bars.beginFill(getBarColor(bars.resources.memory.requested, bars.resources.memory.capacity - bars.resources.memory.reserved), 1)
bars.drawRect(14, 110 - bars.resources.memory.requested / scale, 2.5, bars.resources.memory.requested / scale) bars.drawRect(14, 110 - (bars.resources.memory.requested + bars.resources.memory.reserved) / scale, 2.5, (bars.resources.memory.requested + bars.resources.memory.reserved) / scale)
bars.beginFill(getBarColor(bars.resources.memory.used, bars.resources.memory.capacity), 1) bars.beginFill(getBarColor(bars.resources.memory.used, bars.resources.memory.capacity), 1)
bars.drawRect(16.5, 110 - bars.resources.memory.used / scale, 2.5, bars.resources.memory.used / scale) bars.drawRect(16.5, 110 - bars.resources.memory.used / scale, 2.5, bars.resources.memory.used / scale)
bars.endFill() bars.endFill()
bars.lineStyle(1, App.current.theme.primaryColor, 1)
bars.drawRect(14, 110 - bars.resources.memory.reserved / scale, 5, bars.resources.memory.reserved / scale)
bars.lineStyle(1, App.current.theme.primaryColor, 1) bars.lineStyle(1, App.current.theme.primaryColor, 1)
for (var i = 0; i < bars.resources.cpu.capacity; i++) { for (var i = 0; i < bars.resources.cpu.capacity; i++) {
@@ -48,14 +52,16 @@ export default class Bars extends PIXI.Graphics {
bars.on('mouseover', function () { bars.on('mouseover', function () {
let s = 'CPU: \n' let s = 'CPU: \n'
const {capacity: cpuCap, requested: cpuReq, used: cpuUsed} = bars.resources.cpu const {capacity: cpuCap, reserved: cpuRes, requested: cpuReq, used: cpuUsed} = bars.resources.cpu
s += '\t\t Capacity : ' + cpuCap + '\n' s += '\t\t Capacity : ' + cpuCap + '\n'
s += '\t\t Reserved : ' + cpuRes.toFixed(2) + '\n'
s += '\t\t Requested : ' + cpuReq.toFixed(2) + '\n' s += '\t\t Requested : ' + cpuReq.toFixed(2) + '\n'
s += '\t\t Used : ' + cpuUsed.toFixed(2) + '\n' s += '\t\t Used : ' + cpuUsed.toFixed(2) + '\n'
s += '\nMemory: \n' s += '\nMemory: \n'
const {capacity: memCap, requested: memReq, used: memUsed} = bars.resources.memory const {capacity: memCap, reserved: memRes, requested: memReq, used: memUsed} = bars.resources.memory
s += '\t\t Capacity : ' + (memCap / FACTORS.Gi).toFixed(2) + ' GiB\n' s += '\t\t Capacity : ' + (memCap / FACTORS.Gi).toFixed(2) + ' GiB\n'
s += '\t\t Reserved : ' + (memRes / FACTORS.Gi).toFixed(2) + ' GiB\n'
s += '\t\t Requested : ' + (memReq / FACTORS.Gi).toFixed(2) + ' GiB\n' s += '\t\t Requested : ' + (memReq / FACTORS.Gi).toFixed(2) + ' GiB\n'
s += '\t\t Used : ' + (memUsed / FACTORS.Gi).toFixed(2) + ' GiB\n' s += '\t\t Used : ' + (memUsed / FACTORS.Gi).toFixed(2) + ' GiB\n'

View File

@@ -21,9 +21,14 @@ export default class Node extends PIXI.Graphics {
for (const key of Object.keys(this.node.status.capacity)) { for (const key of Object.keys(this.node.status.capacity)) {
resources[key] = { resources[key] = {
'capacity': parseResource(this.node.status.capacity[key]), 'capacity': parseResource(this.node.status.capacity[key]),
'reserved': 0,
'requested': 0, 'requested': 0,
'used': 0 'used': 0
} }
const allocatable = this.node.status.allocatable[key]
if (allocatable) {
resources[key]['reserved'] = resources[key]['capacity'] - parseResource(allocatable)
}
} }
if (this.node.usage) { if (this.node.usage) {
for (const key of Object.keys(this.node.usage)) { for (const key of Object.keys(this.node.usage)) {

View File

@@ -16,6 +16,7 @@ def map_node_status(status: dict):
return { return {
'addresses': status.get('addresses'), 'addresses': status.get('addresses'),
'capacity': status.get('capacity'), 'capacity': status.get('capacity'),
'allocatable': status.get('allocatable')
} }

View File

@@ -67,7 +67,9 @@ def query_mock_cluster(cluster):
else: else:
pod = generate_mock_pod(index, i, j) pod = generate_mock_pod(index, i, j)
pods['{}/{}'.format(pod['namespace'], pod['name'])] = pod pods['{}/{}'.format(pod['namespace'], pod['name'])] = pod
node = {'name': 'node-{}'.format(i), 'labels': labels, 'status': {'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'}}, 'pods': pods} node = {'name': 'node-{}'.format(i), 'labels': labels, 'status': {
'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'},
'allocatable': {'cpu': '3800m', 'memory': '31Gi'}}, 'pods': pods}
nodes[node['name']] = node nodes[node['name']] = node
pod = generate_mock_pod(index, 11, index) pod = generate_mock_pod(index, 11, index)
unassigned_pods = {'{}/{}'.format(pod['namespace'], pod['name']): pod} unassigned_pods = {'{}/{}'.format(pod['namespace'], pod['name']): pod}