#46 scope ALL_NODES to cluster
This commit is contained in:
20
app.py
20
app.py
@@ -99,18 +99,32 @@ def index():
|
|||||||
return flask.render_template('index.html', app_js=app_js)
|
return flask.render_template('index.html', app_js=app_js)
|
||||||
|
|
||||||
|
|
||||||
|
def hash_int(x: int):
|
||||||
|
x = ((x >> 16) ^ x) * 0x45d9f3b
|
||||||
|
x = ((x >> 16) ^ x) * 0x45d9f3b
|
||||||
|
x = (x >> 16) ^ x
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
def generate_mock_cluster_data(index: int):
|
def generate_mock_cluster_data(index: int):
|
||||||
|
'''Generate deterministic (no randomness!) mock data'''
|
||||||
nodes = []
|
nodes = []
|
||||||
|
pod_phases = ['Pending', 'Running', 'Running']
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
labels = {}
|
labels = {}
|
||||||
if i < 2:
|
if i < 2:
|
||||||
labels['master'] = 'true'
|
labels['master'] = 'true'
|
||||||
pods = []
|
pods = []
|
||||||
for j in range(32):
|
for j in range(hash_int((index + 1) * (i + 1)) % 32):
|
||||||
|
phase = pod_phases[hash_int((index + 1) * (i + 1) * (j + 1)) % len(pod_phases)]
|
||||||
containers = []
|
containers = []
|
||||||
for k in range(1):
|
for k in range(1):
|
||||||
containers.append({'name': 'myapp', 'image': 'foo/bar/{}'.format(j), 'resources': {}})
|
containers.append({'name': 'myapp', 'image': 'foo/bar/{}'.format(j), 'resources': {'requests': {'cpu': '100m', 'memory': '100Mi'}}})
|
||||||
pods.append({'name': 'my-pod-{}'.format(j), 'namespace': 'default', 'labels': {}, 'status': {}, 'containers': containers})
|
status = {'phase': phase}
|
||||||
|
if phase == 'Running':
|
||||||
|
if j % 10 == 0:
|
||||||
|
status['containerStatuses'] = [{'ready': False, 'state': {'waiting': {'reason': 'CrashLoopBackOff'}}}]
|
||||||
|
pods.append({'name': 'my-pod-{}'.format(j), 'namespace': 'kube-system' if j < 3 else 'default', 'labels': labels, 'status': status, 'containers': containers})
|
||||||
nodes.append({'name': 'node-{}'.format(i), 'labels': labels, 'status': {'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'}}, 'pods': pods})
|
nodes.append({'name': 'node-{}'.format(i), 'labels': labels, 'status': {'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'}}, 'pods': pods})
|
||||||
unassigned_pods = []
|
unassigned_pods = []
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export default class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
animatePodCreation(originalPod, globalX, globalY) {
|
animatePodCreation(originalPod, globalX, globalY) {
|
||||||
const pod = new Pod(originalPod.pod, this.tooltip, false)
|
const pod = new Pod(originalPod.pod, this.tooltip, null)
|
||||||
pod.draw()
|
pod.draw()
|
||||||
const targetPosition = new PIXI.Point(globalX, globalY)
|
const targetPosition = new PIXI.Point(globalX, globalY)
|
||||||
const angle = Math.random()*Math.PI*2
|
const angle = Math.random()*Math.PI*2
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default class Cluster extends PIXI.Graphics {
|
|||||||
draw () {
|
draw () {
|
||||||
var rows = [10, 10]
|
var rows = [10, 10]
|
||||||
for (var node of this.cluster.nodes) {
|
for (var node of this.cluster.nodes) {
|
||||||
var nodeBox = new Node(node, this.tooltip)
|
var nodeBox = new Node(node, this, this.tooltip)
|
||||||
nodeBox.draw()
|
nodeBox.draw()
|
||||||
if (nodeBox.isMaster()) {
|
if (nodeBox.isMaster()) {
|
||||||
nodeBox.x = rows[0]
|
nodeBox.x = rows[0]
|
||||||
@@ -29,7 +29,7 @@ export default class Cluster extends PIXI.Graphics {
|
|||||||
|
|
||||||
|
|
||||||
for (const pod of this.cluster.unassigned_pods) {
|
for (const pod of this.cluster.unassigned_pods) {
|
||||||
var podBox = Pod.getOrCreate(pod, this.tooltip)
|
var podBox = Pod.getOrCreate(pod, this, this.tooltip)
|
||||||
podBox.x = rows[0]
|
podBox.x = rows[0]
|
||||||
podBox.y = 20
|
podBox.y = 20
|
||||||
podBox.draw()
|
podBox.draw()
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import {parseResource} from './utils.js'
|
|||||||
const PIXI = require('pixi.js')
|
const PIXI = require('pixi.js')
|
||||||
|
|
||||||
export default class Node extends PIXI.Graphics {
|
export default class Node extends PIXI.Graphics {
|
||||||
constructor(node, tooltip) {
|
constructor(node, cluster, tooltip) {
|
||||||
super()
|
super()
|
||||||
this.node = node
|
this.node = node
|
||||||
|
this.cluster = cluster
|
||||||
this.tooltip = tooltip
|
this.tooltip = tooltip
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ export default class Node extends PIXI.Graphics {
|
|||||||
var py = 20
|
var py = 20
|
||||||
for (const pod of this.node.pods) {
|
for (const pod of this.node.pods) {
|
||||||
if (pod.namespace != 'kube-system') {
|
if (pod.namespace != 'kube-system') {
|
||||||
const podBox = Pod.getOrCreate(pod, this.tooltip) //new Pod(pod, this.tooltip)
|
const podBox = Pod.getOrCreate(pod, this.cluster, this.tooltip) //new Pod(pod, this.tooltip)
|
||||||
podBox.x = px
|
podBox.x = px
|
||||||
podBox.y = py
|
podBox.y = py
|
||||||
nodeBox.addChild(podBox.draw())
|
nodeBox.addChild(podBox.draw())
|
||||||
@@ -98,7 +99,7 @@ export default class Node extends PIXI.Graphics {
|
|||||||
py = 100
|
py = 100
|
||||||
for (const pod of this.node.pods) {
|
for (const pod of this.node.pods) {
|
||||||
if (pod.namespace == 'kube-system') {
|
if (pod.namespace == 'kube-system') {
|
||||||
const podBox = Pod.getOrCreate(pod, this.tooltip) //new Pod(pod, this.tooltip)
|
const podBox = Pod.getOrCreate(pod, this.cluster, this.tooltip) //new Pod(pod, this.tooltip)
|
||||||
podBox.x = px
|
podBox.x = px
|
||||||
podBox.y = py
|
podBox.y = py
|
||||||
nodeBox.addChild(podBox.draw())
|
nodeBox.addChild(podBox.draw())
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ export const ALL_PODS = {}
|
|||||||
|
|
||||||
export class Pod extends PIXI.Graphics {
|
export class Pod extends PIXI.Graphics {
|
||||||
|
|
||||||
constructor(pod, tooltip, register=true) {
|
constructor(pod, tooltip, cluster) {
|
||||||
super()
|
super()
|
||||||
this.pod = pod
|
this.pod = pod
|
||||||
this.tooltip = tooltip
|
this.tooltip = tooltip
|
||||||
this.tick = null
|
this.tick = null
|
||||||
this._progress = 1
|
this._progress = 1
|
||||||
|
|
||||||
if (register) {
|
if (cluster) {
|
||||||
ALL_PODS[pod.namespace + '/' + pod.name] = this
|
ALL_PODS[cluster.cluster.api_server_url + '/' + pod.namespace + '/' + pod.name] = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +51,8 @@ export class Pod extends PIXI.Graphics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getOrCreate(pod, tooltip) {
|
static getOrCreate(pod, cluster, tooltip) {
|
||||||
const existingPod = ALL_PODS[pod.namespace + '/' + pod.name]
|
const existingPod = ALL_PODS[cluster.cluster.api_server_url + '/' + pod.namespace + '/' + pod.name]
|
||||||
if (existingPod) {
|
if (existingPod) {
|
||||||
existingPod.pod = pod
|
existingPod.pod = pod
|
||||||
existingPod.clear()
|
existingPod.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user