Open 593769290 opened 5 years ago
some code to make it work:
lib/ui/dashboard.js
function updatePodsTable(pods) {
const selected = pods_table.selected;
pods_table.setData(pods.items.reduce((data, pod) => {
const uid = pod.metadata.uid;
data.push([
uid === pod_selected ? `{blue-fg}${pod.metadata.name}{/blue-fg}` : pod.metadata.name,
// TODO: add a visual hint depending on the status
k8s.podStatus(pod),
k8s.podReadyCount(pod),
k8s.podRestartsCount(pod),
// FIXME: negative duration is displayed when pod starts as clocks may not be synced
util.formatDuration(moment.duration(moment().diff(moment(pod.status.startTime)))),
pod.status.podIP,
pod.status.hostIP
]);
return data;
}, [['NAME', 'STATUS', 'READY', 'RESTARTS', 'AGE', 'IP', 'NODE']]));
pods_table.select(selected);
}
lib/kubernetes.js
module.exports.podReadyCount = function (pod) {
let readycount = 0;
let allcount = 0;
if (pod.status.initContainerStatuses){
(pod.status.initContainerStatuses || []).forEach(container => {
allcount++;
const state = container.state;
if (state.terminated && state.terminated.exitCode === 0) {
readycount++;
}
});
}else{
(pod.status.containerStatuses || []).forEach(container => {
allcount++;
const state = container.state;
if (container.ready && state.running) {
readycount++;
}
});
}
return ''+readycount+'/'+allcount;
}
module.exports.podRestartsCount = function (pod) {
let recount = 0;
(pod.status.containerStatuses || []).forEach(container => {
if (container.restartCount){
recount+= container.restartCount;
}
});
return ''+recount;
}
Thanks for the suggestion. This is something we plan to do.
Actually, I was thinking the output of kubectl get pod -owide
could be used directly. As I researched a way to solve the issue when the client clock is not in sync with the server clock, I found it is the only way to retrieve the correct pod ages.
to solve the problem that client clock is not in sync with server clock.
think about change 'AGE' field to ‘STARTTIME’, or just add a field ‘STARTTIME’.
Indeed, replacing the age by the start time would be a good idea in case there is no way to retrieve the age server-side.
Add some fields to pods_table, as result, it looks like kubectl get pod -owide. 'NAME', 'STATUS', 'READY', 'RESTARTS', 'AGE', 'IP', 'NODE'.