Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields to pods table to match kubectl get pod -owide #44

Open
593769290 opened this issue May 16, 2019 · 4 comments
Open

Add fields to pods table to match kubectl get pod -owide #44

593769290 opened this issue May 16, 2019 · 4 comments

Comments

@593769290
Copy link
Contributor

593769290 commented May 16, 2019

Add some fields to pods_table, as result, it looks like kubectl get pod -owide.
'NAME', 'STATUS', 'READY', 'RESTARTS', 'AGE', 'IP', 'NODE'.

@593769290
Copy link
Contributor Author

593769290 commented May 16, 2019

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;
}

@astefanutti
Copy link
Owner

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.

@astefanutti astefanutti changed the title add some fields to pods_table,make it to look like kubectl get pod -owide. Add fields to pods table to match kubectl get pod -owide May 16, 2019
@593769290
Copy link
Contributor Author

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’.

@astefanutti
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants