Skip to content

Commit

Permalink
Add first party of log system. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienBreux committed Aug 15, 2017
1 parent b366a88 commit 69601e8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
41 changes: 41 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,44 @@ func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {

return err
}

// Show views logs
func showViewLogs(g *gocui.Gui, v *gocui.View) error {
vn := "logs"

debug(g, "Action: Show view logs")
g.SetViewOnTop(vn)
g.SetCurrentView(vn)

// TODO Enable logs
switch LOG_MOD {
case "pod":
v, err := g.View(vn)
if err != nil {
return err
}
getPodLogs(POD, v)
}

return nil
}

// View pods: Logs
func actionViewPodsLogs(g *gocui.Gui, v *gocui.View) error {
LOG_MOD = "pod"
err := showViewLogs(g, v)

return err
}

// View logs: Hide
func actionViewLogsHide(g *gocui.Gui, v *gocui.View) error {
g.SetViewOnBottom("logs")
g.SetCurrentView("pods")

v.Clear()

debug(g, "Action: Hide view logs)")

return nil
}
20 changes: 20 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"strconv"
"time"

Expand Down Expand Up @@ -46,6 +47,25 @@ func deletePod(p string) error {
return cs.CoreV1().Pods(NAMESPACE).Delete(p, &metav1.DeleteOptions{})
}

// Get pod logs
func getPodLogs(p string, out io.Writer) error {
cs := getClientSet()

opts := &v1.PodLogOptions{}

req := cs.CoreV1().Pods(NAMESPACE).GetLogs(p, opts)

readCloser, err := req.Stream()
if err != nil {
return err
}
defer readCloser.Close()

_, err = io.Copy(out, readCloser)

return err
}

// Column helper: Restarts
func columnHelperRestarts(cs []v1.ContainerStatus) string {
r := 0
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var DEBUG_DISPLAYED bool = false
var LOG_MOD string = "pod"
var NAMESPACE string = "default"
var POD string = ""

Expand All @@ -20,6 +21,8 @@ var keys []Key = []Key{
Key{"pods", gocui.KeyArrowUp, actionViewPodsUp},
Key{"pods", gocui.KeyArrowDown, actionViewPodsDown},
Key{"pods", 'd', actionViewPodsDelete},
Key{"pods", 'l', actionViewPodsLogs},
Key{"logs", 'l', actionViewLogsHide},
}

// Main or not main, that's the question^^
Expand Down Expand Up @@ -49,6 +52,7 @@ func uiLayout(g *gocui.Gui) error {
maxX, maxY := g.Size()

viewDebug(g, maxX, maxY)
viewLogs(g, maxX, maxY)
viewOverlay(g, maxX, maxY)
viewTitle(g, maxX, maxY)
viewPods(g, maxX, maxY)
Expand Down
15 changes: 15 additions & 0 deletions views.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ func viewDebug(g *gocui.Gui, lMaxX int, lMaxY int) error {
return nil
}

// View: Logs
func viewLogs(g *gocui.Gui, lMaxX int, lMaxY int) error {
if v, err := g.SetView("logs", 2, 2, lMaxX-4, lMaxY-2); err != nil {
if err != gocui.ErrUnknownView {
return err
}

// Settings
v.Title = " Logs "
v.Autoscroll = true
}

return nil
}

// View: Pods
func viewPods(g *gocui.Gui, lMaxX int, lMaxY int) error {
if v, err := g.SetView("pods", -1, 1, lMaxX, lMaxY-1); err != nil {
Expand Down

0 comments on commit 69601e8

Please sign in to comment.