#49 move pod.status.phase to pod.phase
This commit is contained in:
17
app.py
17
app.py
@@ -276,7 +276,6 @@ def generate_mock_pod(index: int, i: int, j: int):
|
||||
pod_phases = ['Pending', 'Running', 'Running']
|
||||
labels = {}
|
||||
phase = pod_phases[hash_int((index + 1) * (i + 1) * (j + 1)) % len(pod_phases)]
|
||||
status = {'phase': phase}
|
||||
containers = []
|
||||
for k in range(1 + j % 2):
|
||||
container = {
|
||||
@@ -290,7 +289,7 @@ def generate_mock_pod(index: int, i: int, j: int):
|
||||
elif j % 7 == 0:
|
||||
container.update(**{'ready': True, 'state': {'running': {}}, 'restartCount': 3})
|
||||
containers.append(container)
|
||||
pod = {'name': '{}-{}-{}'.format(names[hash_int((i + 1) * (j + 1)) % len(names)], i, j), 'namespace': 'kube-system' if j < 3 else 'default', 'labels': labels, 'status': status, 'containers': containers}
|
||||
pod = {'name': '{}-{}-{}'.format(names[hash_int((i + 1) * (j + 1)) % len(names)], i, j), 'namespace': 'kube-system' if j < 3 else 'default', 'labels': labels, 'phase': phase, 'containers': containers}
|
||||
if phase == 'Running' and j % 17 == 0:
|
||||
pod['deleted'] = 123
|
||||
|
||||
@@ -357,20 +356,17 @@ def map_node(node: dict):
|
||||
}
|
||||
|
||||
|
||||
def map_pod_status(status: dict):
|
||||
return {'phase': status.get('phase'), 'startTime': status.get('startTime')}
|
||||
|
||||
|
||||
def map_pod(pod: dict):
|
||||
return {
|
||||
'name': pod['metadata']['name'],
|
||||
'namespace': pod['metadata']['namespace'],
|
||||
'labels': pod['metadata'].get('labels', {}),
|
||||
'status': map_pod_status(pod['status']),
|
||||
'phase': pod['status'].get('phase'),
|
||||
'startTime': pod['status']['startTime'] if 'startTime' in pod['status'] else '',
|
||||
'containers': []
|
||||
}
|
||||
|
||||
|
||||
def map_container(cont: dict, pod: dict):
|
||||
obj = {'name': cont['name'], 'image': cont['image'], 'resources': cont['resources']}
|
||||
status = list([s for s in pod.get('status', {}).get('containerStatuses', []) if s['name'] == cont['name']])
|
||||
@@ -449,9 +445,10 @@ def event(cluster_ids: set):
|
||||
cluster = STORE.get(cluster_id)
|
||||
yield 'event: clusterupdate\ndata: ' + json.dumps(cluster, separators=(',', ':')) + '\n\n'
|
||||
while True:
|
||||
for event_type, cluster in STORE.listen():
|
||||
if not cluster_ids or cluster['id'] in cluster_ids:
|
||||
yield 'event: ' + event_type + '\ndata: ' + json.dumps(cluster, separators=(',', ':')) + '\n\n'
|
||||
for event_type, event_data in STORE.listen():
|
||||
# hacky, event_data can be delta or full cluster object
|
||||
if not cluster_ids or event_data.get('cluster_id', event_data.get('id')) in cluster_ids:
|
||||
yield 'event: ' + event_type + '\ndata: ' + json.dumps(event_data, separators=(',', ':')) + '\n\n'
|
||||
|
||||
|
||||
@app.route('/events')
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"homepage": "https://github.com/hjacobs/kube-ops-view#readme",
|
||||
"dependencies": {
|
||||
"pixi-display": "^1.0.1",
|
||||
"pixi.js": "^4.3.0",
|
||||
"pixi.js": "^4.3.2",
|
||||
"webpack-dev-server": "^1.16.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -10,8 +10,8 @@ const sortByName = (a, b) => {
|
||||
}
|
||||
|
||||
const sortByAge = (a, b) => {
|
||||
const dateA = new Date(a.status.startTime)
|
||||
const dateB = new Date(b.status.startTime)
|
||||
const dateA = new Date(a.startTime)
|
||||
const dateB = new Date(b.startTime)
|
||||
if (dateA.getTime() < dateB.getTime()) {
|
||||
return -1
|
||||
} else if (dateA.getTime() === dateB.getTime())
|
||||
@@ -54,6 +54,7 @@ export class Pod extends PIXI.Graphics {
|
||||
if (this.tick) {
|
||||
PIXI.ticker.shared.remove(this.tick, this)
|
||||
}
|
||||
PIXI.ticker.shared.remove(this.animateMove, this)
|
||||
super.destroy()
|
||||
}
|
||||
|
||||
@@ -162,8 +163,8 @@ export class Pod extends PIXI.Graphics {
|
||||
podBox.on('mouseover', function () {
|
||||
podBox.filters = podBox.filters.filter(x => x != BRIGHTNESS_FILTER).concat([BRIGHTNESS_FILTER])
|
||||
let s = this.pod.name
|
||||
s += '\nStatus : ' + this.pod.status.phase + ' (' + ready + '/' + this.pod.containers.length + ' ready)'
|
||||
s += '\nStart Time: ' + this.pod.status.startTime
|
||||
s += '\nStatus : ' + this.pod.phase + ' (' + ready + '/' + this.pod.containers.length + ' ready)'
|
||||
s += '\nStart Time: ' + this.pod.startTime
|
||||
s += '\nLabels :'
|
||||
for (var key of Object.keys(this.pod.labels).sort()) {
|
||||
if (key !== 'pod-template-hash') {
|
||||
@@ -210,16 +211,16 @@ export class Pod extends PIXI.Graphics {
|
||||
i++
|
||||
}
|
||||
let color
|
||||
if (this.pod.status.phase == 'Succeeded') {
|
||||
if (this.pod.phase == 'Succeeded') {
|
||||
// completed Job
|
||||
color = 0xaaaaff
|
||||
} else if (this.pod.status.phase == 'Running' && allReady) {
|
||||
} else if (this.pod.phase == 'Running' && allReady) {
|
||||
color = 0xaaffaa
|
||||
} else if (this.pod.status.phase == 'Running' && allRunning && !allReady) {
|
||||
} else if (this.pod.phase == 'Running' && allRunning && !allReady) {
|
||||
// all containers running, but some not ready (readinessProbe)
|
||||
newTick = this.pulsate
|
||||
color = 0xaaffaa
|
||||
} else if (this.pod.status.phase == 'Pending') {
|
||||
} else if (this.pod.phase == 'Pending') {
|
||||
newTick = this.pulsate
|
||||
color = 0xffffaa
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user