From 5657b3cd725034201028656222f685e700c8c462 Mon Sep 17 00:00:00 2001 From: tyzbit <3319104+tyzbit@users.noreply.github.com> Date: Sun, 7 May 2023 10:15:11 -0400 Subject: [PATCH] fix: (views) use saved context view when switching (#2045) * fix: (views) use saved context view when switching * fix: (app) remove unnecessary variable --- README.md | 4 ++-- internal/view/app.go | 10 ++++------ internal/view/context.go | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ded9d859..2cbaa1f2 100644 --- a/README.md +++ b/README.md @@ -260,8 +260,8 @@ K9s uses aliases to navigate most K8s resources. | Fuzzy find a resource given a filter | `/`-f filter⏎ | | | Bails out of view/command/filter mode | `` | | | Key mapping to describe, view, edit, view logs,... | `d`,`v`, `e`, `l`,... | | -| To view and switch to another Kubernetes context | `:`ctx⏎ | | -| To view and switch to another Kubernetes context | `:`ctx context-name⏎ | | +| To view and switch to another Kubernetes context (Pod view) | `:`ctx⏎ | | +| To view and switch directl to another Kubernetes context (Last used view) | `:`ctx context-name⏎ | | | To view and switch to another Kubernetes namespace | `:`ns⏎ | | | To view all saved resources | `:`screendump or sd⏎ | | | To delete a resource (TAB and ENTER to confirm) | `ctrl-d` | | diff --git a/internal/view/app.go b/internal/view/app.go index da4cab6c..9840f87c 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -398,7 +398,7 @@ func (a *App) isValidNS(ns string) (bool, error) { return true, nil } -func (a *App) switchContext(name string, loadPods bool) error { +func (a *App) switchContext(name string) error { log.Debug().Msgf("--> Switching Context %q--%q", name, a.Config.ActiveView()) a.Halt() defer a.Resume() @@ -412,10 +412,8 @@ func (a *App) switchContext(name string, loadPods bool) error { if e := a.command.Reset(true); e != nil { return e } - v := a.Config.ActiveView() - if v == "" || isContextCmd(v) || loadPods { - v = "pod" - a.Config.SetActiveView(v) + if a.Config.ActiveView() == "" || isContextCmd(a.Config.ActiveView()) { + a.Config.SetActiveView("pod") } a.Config.Reset() a.Config.K9s.CurrentContext = name @@ -433,7 +431,7 @@ func (a *App) switchContext(name string, loadPods bool) error { a.Flash().Infof("Switching context to %s", name) a.ReloadStyles(name) - a.gotoResource(v, "", true) + a.gotoResource(a.Config.ActiveView(), "", true) a.clusterModel.Reset(a.factory) } diff --git a/internal/view/context.go b/internal/view/context.go index 77b5da16..2514b473 100644 --- a/internal/view/context.go +++ b/internal/view/context.go @@ -119,6 +119,6 @@ func useContext(app *App, name string) error { log.Error().Err(err).Msgf("Context switch failed") return err } - - return app.switchContext(name, true) + + return app.switchContext(name) }