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

Commit b366a88

Browse files
committed
Add pod deletion. Close #12
1 parent 03e75ea commit b366a88

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

actions.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ func actionViewPodsDown(g *gocui.Gui, v *gocui.View) error {
4545
debug(g, " - Select down in pods view: "+POD)
4646
return err
4747
}
48+
49+
// View pods: Delete
50+
func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {
51+
debug(g, "Delete pod: "+POD)
52+
err := deletePod(POD)
53+
54+
go viewPodsRefreshList(g)
55+
56+
return err
57+
}

kubernetes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ func getPods() (*v1.PodList, error) {
3939
return cs.CoreV1().Pods(NAMESPACE).List(metav1.ListOptions{})
4040
}
4141

42+
// Delete pod
43+
func deletePod(p string) error {
44+
cs := getClientSet()
45+
46+
return cs.CoreV1().Pods(NAMESPACE).Delete(p, &metav1.DeleteOptions{})
47+
}
48+
4249
// Column helper: Restarts
4350
func columnHelperRestarts(cs []v1.ContainerStatus) string {
4451
r := 0

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
var DEBUG_DISPLAYED bool = false
13-
var NAMESPACE string = ""
13+
var NAMESPACE string = "default"
1414
var POD string = ""
1515

1616
// Configure globale keys
@@ -19,6 +19,7 @@ var keys []Key = []Key{
1919
Key{"", gocui.KeyCtrlD, actionGlobalToggleDebug},
2020
Key{"pods", gocui.KeyArrowUp, actionViewPodsUp},
2121
Key{"pods", gocui.KeyArrowDown, actionViewPodsDown},
22+
Key{"pods", 'd', actionViewPodsDelete},
2223
}
2324

2425
// Main or not main, that's the question^^

views.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,30 @@ func viewPods(g *gocui.Gui, lMaxX int, lMaxY int) error {
7575
g.SetCurrentView(v.Name())
7676

7777
// Content
78-
go viewPodsActualize(g, lMaxX)
79-
go viewPodsAutoRefresh(g, lMaxX)
78+
go viewPodsShowWithAutoRefresh(g)
8079
}
8180

8281
return nil
8382
}
8483

8584
// Auto refresh view pods
86-
func viewPodsAutoRefresh(g *gocui.Gui, lMaxX int) {
85+
func viewPodsShowWithAutoRefresh(g *gocui.Gui) {
8786
c := getConfig()
8887
t := time.NewTicker(time.Duration(c.frequency) * time.Second)
88+
go viewPodsRefreshList(g)
8989
for {
9090
select {
9191
case <-t.C:
9292
debug(g, fmt.Sprintf("View pods: Refreshing (%ds)", c.frequency))
93-
go viewPodsActualize(g, lMaxX)
93+
go viewPodsRefreshList(g)
9494
}
9595
}
9696
}
9797

98-
// Actualize pods view
99-
func viewPodsActualize(g *gocui.Gui, lMaxX int) {
98+
// Actualize list in pods view
99+
func viewPodsRefreshList(g *gocui.Gui) {
100100
g.Execute(func(g *gocui.Gui) error {
101+
lMaxX, _ := g.Size()
101102
debug(g, "View pods: Actualize")
102103
v, err := g.View("pods")
103104
if err != nil {

0 commit comments

Comments
 (0)