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

Commit

Permalink
Add pod deletion. Close #12
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienBreux committed Aug 15, 2017
1 parent 03e75ea commit b366a88
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
10 changes: 10 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ func actionViewPodsDown(g *gocui.Gui, v *gocui.View) error {
debug(g, " - Select down in pods view: "+POD)
return err
}

// View pods: Delete
func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {
debug(g, "Delete pod: "+POD)
err := deletePod(POD)

go viewPodsRefreshList(g)

return err
}
7 changes: 7 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func getPods() (*v1.PodList, error) {
return cs.CoreV1().Pods(NAMESPACE).List(metav1.ListOptions{})
}

// Delete pod
func deletePod(p string) error {
cs := getClientSet()

return cs.CoreV1().Pods(NAMESPACE).Delete(p, &metav1.DeleteOptions{})
}

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

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

// Configure globale keys
Expand All @@ -19,6 +19,7 @@ var keys []Key = []Key{
Key{"", gocui.KeyCtrlD, actionGlobalToggleDebug},
Key{"pods", gocui.KeyArrowUp, actionViewPodsUp},
Key{"pods", gocui.KeyArrowDown, actionViewPodsDown},
Key{"pods", 'd', actionViewPodsDelete},
}

// Main or not main, that's the question^^
Expand Down
13 changes: 7 additions & 6 deletions views.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,30 @@ func viewPods(g *gocui.Gui, lMaxX int, lMaxY int) error {
g.SetCurrentView(v.Name())

// Content
go viewPodsActualize(g, lMaxX)
go viewPodsAutoRefresh(g, lMaxX)
go viewPodsShowWithAutoRefresh(g)
}

return nil
}

// Auto refresh view pods
func viewPodsAutoRefresh(g *gocui.Gui, lMaxX int) {
func viewPodsShowWithAutoRefresh(g *gocui.Gui) {
c := getConfig()
t := time.NewTicker(time.Duration(c.frequency) * time.Second)
go viewPodsRefreshList(g)
for {
select {
case <-t.C:
debug(g, fmt.Sprintf("View pods: Refreshing (%ds)", c.frequency))
go viewPodsActualize(g, lMaxX)
go viewPodsRefreshList(g)
}
}
}

// Actualize pods view
func viewPodsActualize(g *gocui.Gui, lMaxX int) {
// Actualize list in pods view
func viewPodsRefreshList(g *gocui.Gui) {
g.Execute(func(g *gocui.Gui) error {
lMaxX, _ := g.Size()
debug(g, "View pods: Actualize")
v, err := g.View("pods")
if err != nil {
Expand Down

0 comments on commit b366a88

Please sign in to comment.