fix locking issue when shelling out #171

mine
derailed 2019-04-29 21:01:36 -06:00
parent d0fd83f90f
commit 1357608f95
2 changed files with 51 additions and 15 deletions

View File

@ -173,18 +173,22 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey {
} }
func (v *podView) shellIn(path, co string) { func (v *podView) shellIn(path, co string) {
ns, po := namespaced(path) v.suspend()
args := make([]string, 0, 12) {
args = append(args, "exec", "-it") ns, po := namespaced(path)
args = append(args, "--context", v.app.config.K9s.CurrentContext) args := make([]string, 0, 12)
args = append(args, "-n", ns) args = append(args, "exec", "-it")
args = append(args, po) args = append(args, "--context", v.app.config.K9s.CurrentContext)
if len(co) != 0 { args = append(args, "-n", ns)
args = append(args, "-c", co) args = append(args, po)
if len(co) != 0 {
args = append(args, "-c", co)
}
args = append(args, "--", "sh")
log.Debug().Msgf("Shell args %v", args)
runK(true, v.app, args...)
} }
args = append(args, "--", "sh") v.resume()
log.Debug().Msgf("Shell args %v", args)
runK(true, v.app, args...)
} }
func (v *podView) extraActions(aa keyActions) { func (v *podView) extraActions(aa keyActions) {

View File

@ -6,6 +6,7 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/config"
@ -43,6 +44,8 @@ type (
decorateFn decorateFn decorateFn decorateFn
colorerFn colorerFn colorerFn colorerFn
actions keyActions actions keyActions
mx sync.Mutex
suspended bool
} }
) )
@ -78,6 +81,15 @@ func (v *resourceView) init(ctx context.Context, ns string) {
} }
v.getTV().setColorer(colorer) v.getTV().setColorer(colorer)
go v.updater(ctx)
v.refresh()
if tv, ok := v.CurrentPage().Item.(*tableView); ok {
tv.Select(1, 0)
v.selChanged(1, 0)
}
}
func (v *resourceView) updater(ctx context.Context) {
go func(ctx context.Context) { go func(ctx context.Context) {
for { for {
select { select {
@ -85,17 +97,37 @@ func (v *resourceView) init(ctx context.Context, ns string) {
log.Debug().Msgf("%s watcher canceled!", v.title) log.Debug().Msgf("%s watcher canceled!", v.title)
return return
case <-time.After(time.Duration(v.app.config.K9s.RefreshRate) * time.Second): case <-time.After(time.Duration(v.app.config.K9s.RefreshRate) * time.Second):
var suspended bool
v.mx.Lock()
{
suspended = v.suspended
}
v.mx.Unlock()
if suspended == true {
continue
}
v.app.QueueUpdate(func() { v.app.QueueUpdate(func() {
v.refresh() v.refresh()
}) })
} }
} }
}(ctx) }(ctx)
v.refresh() }
if tv, ok := v.CurrentPage().Item.(*tableView); ok {
tv.Select(1, 0) func (v *resourceView) suspend() {
v.selChanged(1, 0) v.mx.Lock()
{
v.suspended = true
} }
v.mx.Unlock()
}
func (v *resourceView) resume() {
v.mx.Lock()
{
v.suspended = false
}
v.mx.Unlock()
} }
func (v *resourceView) setExtraActionsFn(f actionsFn) { func (v *resourceView) setExtraActionsFn(f actionsFn) {