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,6 +173,8 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey {
}
func (v *podView) shellIn(path, co string) {
v.suspend()
{
ns, po := namespaced(path)
args := make([]string, 0, 12)
args = append(args, "exec", "-it")
@ -185,6 +187,8 @@ func (v *podView) shellIn(path, co string) {
args = append(args, "--", "sh")
log.Debug().Msgf("Shell args %v", args)
runK(true, v.app, args...)
}
v.resume()
}
func (v *podView) extraActions(aa keyActions) {

View File

@ -6,6 +6,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"
"github.com/derailed/k9s/internal/config"
@ -43,6 +44,8 @@ type (
decorateFn decorateFn
colorerFn colorerFn
actions keyActions
mx sync.Mutex
suspended bool
}
)
@ -78,6 +81,15 @@ func (v *resourceView) init(ctx context.Context, ns string) {
}
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) {
for {
select {
@ -85,17 +97,37 @@ func (v *resourceView) init(ctx context.Context, ns string) {
log.Debug().Msgf("%s watcher canceled!", v.title)
return
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.refresh()
})
}
}
}(ctx)
v.refresh()
if tv, ok := v.CurrentPage().Item.(*tableView); ok {
tv.Select(1, 0)
v.selChanged(1, 0)
}
func (v *resourceView) suspend() {
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) {