diff --git a/internal/views/pod.go b/internal/views/pod.go index a5565462..8b6cb7ea 100644 --- a/internal/views/pod.go +++ b/internal/views/pod.go @@ -173,18 +173,22 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey { } func (v *podView) shellIn(path, co string) { - ns, po := namespaced(path) - args := make([]string, 0, 12) - args = append(args, "exec", "-it") - args = append(args, "--context", v.app.config.K9s.CurrentContext) - args = append(args, "-n", ns) - args = append(args, po) - if len(co) != 0 { - args = append(args, "-c", co) + v.suspend() + { + ns, po := namespaced(path) + args := make([]string, 0, 12) + args = append(args, "exec", "-it") + args = append(args, "--context", v.app.config.K9s.CurrentContext) + args = append(args, "-n", ns) + 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") - log.Debug().Msgf("Shell args %v", args) - runK(true, v.app, args...) + v.resume() } func (v *podView) extraActions(aa keyActions) { diff --git a/internal/views/resource.go b/internal/views/resource.go index c1861444..6d5931f6 100644 --- a/internal/views/resource.go +++ b/internal/views/resource.go @@ -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) {