Skip to content

Commit

Permalink
Add locking favorite namespaces (derailed#1449) (derailed#1519)
Browse files Browse the repository at this point in the history
* add locking favorite namespaces (derailed#1449)

* let favorites be set via type default
  • Loading branch information
tyzbit authored May 19, 2022
1 parent 838174a commit 25e02db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ var expectedConfig = `k9s:
blee:
namespace:
active: default
lockFavorites: false
favorites:
- default
view:
Expand All @@ -316,6 +317,7 @@ var expectedConfig = `k9s:
fred:
namespace:
active: default
lockFavorites: false
favorites:
- default
- kube-public
Expand All @@ -338,6 +340,7 @@ var expectedConfig = `k9s:
minikube:
namespace:
active: kube-system
lockFavorites: false
favorites:
- default
- kube-public
Expand Down Expand Up @@ -389,6 +392,7 @@ var resetConfig = `k9s:
blee:
namespace:
active: default
lockFavorites: false
favorites:
- default
view:
Expand Down
7 changes: 4 additions & 3 deletions internal/config/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 25e02db

Please sign in to comment.