From 25e02db101d5318feeae3296238499e02e77a1cd Mon Sep 17 00:00:00 2001 From: tyzbit <3319104+tyzbit@users.noreply.github.com> Date: Thu, 19 May 2022 11:15:40 -0400 Subject: [PATCH] Add locking favorite namespaces (#1449) (#1519) * add locking favorite namespaces (#1449) * let favorites be set via type default --- README.md | 2 ++ internal/config/config.go | 2 +- internal/config/config_test.go | 4 ++++ internal/config/ns.go | 7 ++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f5c54533..4a53ea8d 100644 --- a/README.md +++ b/README.md @@ -326,6 +326,8 @@ K9s uses aliases to navigate most K8s resources. coolio: namespace: active: coolio + # With this set, the favorites list won't be updated as you switch namespaces + lockFavorites: false favorites: - cassandra - default diff --git a/internal/config/config.go b/internal/config/config.go index eb103cc6..b67a6c93 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -259,7 +259,7 @@ func (c *Config) Validate() { func (c *Config) Dump(msg string) { log.Debug().Msgf("Current Cluster: %s\n", c.K9s.CurrentCluster) for k, cl := range c.K9s.Clusters { - log.Debug().Msgf("K9s cluster: %s -- %s\n", k, cl.Namespace) + log.Debug().Msgf("K9s cluster: %s -- %+v\n", k, cl.Namespace) } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index f7883241..29cc70f5 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -298,6 +298,7 @@ var expectedConfig = `k9s: blee: namespace: active: default + lockFavorites: false favorites: - default view: @@ -316,6 +317,7 @@ var expectedConfig = `k9s: fred: namespace: active: default + lockFavorites: false favorites: - default - kube-public @@ -338,6 +340,7 @@ var expectedConfig = `k9s: minikube: namespace: active: kube-system + lockFavorites: false favorites: - default - kube-public @@ -389,6 +392,7 @@ var resetConfig = `k9s: blee: namespace: active: default + lockFavorites: false favorites: - default view: diff --git a/internal/config/ns.go b/internal/config/ns.go index 0cde6e2b..b49925d8 100644 --- a/internal/config/ns.go +++ b/internal/config/ns.go @@ -14,8 +14,9 @@ const ( // Namespace tracks active and favorites namespaces. type Namespace struct { - Active string `yaml:"active"` - Favorites []string `yaml:"favorites"` + Active string `yaml:"active"` + LockFavorites bool `yaml:"lockFavorites"` + Favorites []string `yaml:"favorites"` } // NewNamespace create a new namespace configuration. @@ -48,7 +49,7 @@ func (n *Namespace) Validate(c client.Connection, ks KubeSettings) { // SetActive set the active namespace. func (n *Namespace) SetActive(ns string, ks KubeSettings) error { n.Active = ns - if ns != "" { + if ns != "" && !n.LockFavorites { n.addFavNS(ns) } return nil