Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 69601e8

Browse files
committed
Add first party of log system. #13
1 parent b366a88 commit 69601e8

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

actions.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,44 @@ func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {
5555

5656
return err
5757
}
58+
59+
// Show views logs
60+
func showViewLogs(g *gocui.Gui, v *gocui.View) error {
61+
vn := "logs"
62+
63+
debug(g, "Action: Show view logs")
64+
g.SetViewOnTop(vn)
65+
g.SetCurrentView(vn)
66+
67+
// TODO Enable logs
68+
switch LOG_MOD {
69+
case "pod":
70+
v, err := g.View(vn)
71+
if err != nil {
72+
return err
73+
}
74+
getPodLogs(POD, v)
75+
}
76+
77+
return nil
78+
}
79+
80+
// View pods: Logs
81+
func actionViewPodsLogs(g *gocui.Gui, v *gocui.View) error {
82+
LOG_MOD = "pod"
83+
err := showViewLogs(g, v)
84+
85+
return err
86+
}
87+
88+
// View logs: Hide
89+
func actionViewLogsHide(g *gocui.Gui, v *gocui.View) error {
90+
g.SetViewOnBottom("logs")
91+
g.SetCurrentView("pods")
92+
93+
v.Clear()
94+
95+
debug(g, "Action: Hide view logs)")
96+
97+
return nil
98+
}

kubernetes.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"io"
56
"strconv"
67
"time"
78

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

50+
// Get pod logs
51+
func getPodLogs(p string, out io.Writer) error {
52+
cs := getClientSet()
53+
54+
opts := &v1.PodLogOptions{}
55+
56+
req := cs.CoreV1().Pods(NAMESPACE).GetLogs(p, opts)
57+
58+
readCloser, err := req.Stream()
59+
if err != nil {
60+
return err
61+
}
62+
defer readCloser.Close()
63+
64+
_, err = io.Copy(out, readCloser)
65+
66+
return err
67+
}
68+
4969
// Column helper: Restarts
5070
func columnHelperRestarts(cs []v1.ContainerStatus) string {
5171
r := 0

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
var DEBUG_DISPLAYED bool = false
13+
var LOG_MOD string = "pod"
1314
var NAMESPACE string = "default"
1415
var POD string = ""
1516

@@ -20,6 +21,8 @@ var keys []Key = []Key{
2021
Key{"pods", gocui.KeyArrowUp, actionViewPodsUp},
2122
Key{"pods", gocui.KeyArrowDown, actionViewPodsDown},
2223
Key{"pods", 'd', actionViewPodsDelete},
24+
Key{"pods", 'l', actionViewPodsLogs},
25+
Key{"logs", 'l', actionViewLogsHide},
2326
}
2427

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

5154
viewDebug(g, maxX, maxY)
55+
viewLogs(g, maxX, maxY)
5256
viewOverlay(g, maxX, maxY)
5357
viewTitle(g, maxX, maxY)
5458
viewPods(g, maxX, maxY)

views.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ func viewDebug(g *gocui.Gui, lMaxX int, lMaxY int) error {
5757
return nil
5858
}
5959

60+
// View: Logs
61+
func viewLogs(g *gocui.Gui, lMaxX int, lMaxY int) error {
62+
if v, err := g.SetView("logs", 2, 2, lMaxX-4, lMaxY-2); err != nil {
63+
if err != gocui.ErrUnknownView {
64+
return err
65+
}
66+
67+
// Settings
68+
v.Title = " Logs "
69+
v.Autoscroll = true
70+
}
71+
72+
return nil
73+
}
74+
6075
// View: Pods
6176
func viewPods(g *gocui.Gui, lMaxX int, lMaxY int) error {
6277
if v, err := g.SetView("pods", -1, 1, lMaxX, lMaxY-1); err != nil {

0 commit comments

Comments
 (0)