Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Static node view
Browse files Browse the repository at this point in the history
  • Loading branch information
nityanandagohain committed Sep 13, 2020
1 parent b5a5aff commit 016270c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type data struct {
PodData []client.PodInfo
JobData []client.JobInfo
DeploymentData []client.DeploymentInfo
ServiceData []client.ServiceInfo
ServiceData []client.ServiceInfo
SecretData []client.SecretInfo
ConfigMapData []client.ConfigMapInfo
rsMux sync.RWMutex
Expand Down Expand Up @@ -73,6 +73,7 @@ func (gui *Gui) Run() error {
go gui.goEvery(time.Second, gui.reRenderNamespace)
go gui.goEvery(time.Second, gui.reRenderResource)
go gui.goEvery(time.Second, gui.reRenderClusterInfo)
go gui.goEvery(time.Second, gui.reRenderNodeInfo)

err = g.MainLoop()
return err
Expand Down
12 changes: 11 additions & 1 deletion pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
clusterInfoView.Highlight = true
}

namespaceViewHeight := termHeight - unitHeight - 1
namespaceViewHeight := termHeight - unitHeight - 7
namespaceView, err := g.SetViewBeneath("namespace", "cluster-info", namespaceViewHeight)
if err != nil {
if err.Error() != "unknown view" {
Expand All @@ -52,6 +52,16 @@ func (gui *Gui) layout(g *gocui.Gui) error {
namespaceView.Highlight = true
}

nodeViewHeight := termHeight - unitHeight - namespaceViewHeight - 1
nodeView, err := g.SetViewBeneath("node", "namespace", nodeViewHeight)
if err != nil {
if err.Error() != "unknown view" {
return err
}
nodeView.Title = "node"
nodeView.Highlight = true
}

resourceViewHeight := unitHeight * 2
if resourceView, err := g.SetView("resource", leftColumnWidth+1, 0, termWidth-1, resourceViewHeight, 0); err != nil {
if err.Error() != "unknown view" {
Expand Down
51 changes: 51 additions & 0 deletions pkg/gui/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gui

import (
"time"

"github.com/jesseduffield/gocui"
"github.com/yolossn/lazykubernetes/pkg/utils"
duration "k8s.io/apimachinery/pkg/util/duration"
)

func (gui *Gui) getNodeInfoView() *gocui.View {
v, _ := gui.g.View("node")
return v
}

func (gui *Gui) reRenderNodeInfo() error {

nodeView := gui.getNodeInfoView()
if nodeView == nil {
return nil
}

if gui.getNSCount() == 0 {
return nil
}

nodes, err := gui.k8sClient.ListNode()
if err != nil {
return err
}

nodeView.Clear()

data := make([][]string, cap(nodes))

for x := 0; x < cap(nodes); x++ {
data[x] = make([]string, 4)
}

headers := []string{"NAME", "STATUS", "VERSION", "AGE"}
for i, n := range nodes {
data[i][0] = n.Name
data[i][1] = n.Status
data[i][2] = n.Version
data[i][3] = duration.HumanDuration(time.Since(n.CreatedAt))
}

utils.RenderTable(nodeView, data, headers)

return nil
}

0 comments on commit 016270c

Please sign in to comment.