Skip to content

Commit

Permalink
fix #2476
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Jan 17, 2024
1 parent c6c8ecc commit 3bac277
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
14 changes: 13 additions & 1 deletion internal/config/k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (k *K9s) resetConnection(conn client.Connection) {

// Save saves the k9s config to disk.
func (k *K9s) Save() error {
k.mx.RLock()
defer k.mx.RUnlock()

if k.activeConfig == nil {
log.Warn().Msgf("Save failed. no active config detected")
return nil
Expand Down Expand Up @@ -177,6 +180,9 @@ func (k *K9s) ActiveContext() (*data.Context, error) {

// ActivateContext initializes the active context if not present.
func (k *K9s) ActivateContext(n string) (*data.Context, error) {
k.mx.Lock()
defer k.mx.Unlock()

k.activeContextName = n
ct, err := k.ks.GetContext(n)
if err != nil {
Expand All @@ -187,7 +193,7 @@ func (k *K9s) ActivateContext(n string) (*data.Context, error) {
return nil, err
}

k.Validate(k.conn, k.ks)
k.validate(k.conn, k.ks)
// If the context specifies a namespace, use it!
if ns := ct.Namespace; ns != client.BlankNamespace {
k.activeConfig.Context.Namespace.Active = ns
Expand Down Expand Up @@ -293,6 +299,12 @@ func (k *K9s) IsReadOnly() bool {

// Validate the current configuration.
func (k *K9s) Validate(c client.Connection, ks data.KubeSettings) {
k.mx.Lock()
defer k.mx.Unlock()
k.validate(c, ks)
}

func (k *K9s) validate(c client.Connection, ks data.KubeSettings) {
if k.RefreshRate <= 0 {
k.RefreshRate = defaultRefreshRate
}
Expand Down
21 changes: 16 additions & 5 deletions internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ui

import (
"fmt"
"sync"

"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/model"
Expand Down Expand Up @@ -83,6 +84,7 @@ type Prompt struct {
styles *config.Styles
model PromptModel
spacer int
mx sync.RWMutex
}

// NewPrompt returns a new command view.
Expand Down Expand Up @@ -206,12 +208,21 @@ func (p *Prompt) activate() {
p.model.Notify(false)
}

func (p *Prompt) update(text, suggestion string) {
p.Clear()
p.write(text, suggestion)
func (p *Prompt) Clear() {
p.mx.Lock()
defer p.mx.Unlock()

p.TextView.Clear()
}

func (p *Prompt) suggest(text, suggestion string) {
func (p *Prompt) Draw(sc tcell.Screen) {
p.mx.RLock()
defer p.mx.RUnlock()

p.TextView.Draw(sc)
}

func (p *Prompt) update(text, suggestion string) {
p.Clear()
p.write(text, suggestion)
}
Expand Down Expand Up @@ -240,7 +251,7 @@ func (p *Prompt) BufferChanged(text, suggestion string) {

// SuggestionChanged notifies the suggestion changed.
func (p *Prompt) SuggestionChanged(text, suggestion string) {
p.suggest(text, suggestion)
p.update(text, suggestion)
}

// BufferActive indicates the buff activity changed.
Expand Down
3 changes: 3 additions & 0 deletions internal/view/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (n *Namespace) useNsCmd(evt *tcell.EventKey) *tcell.EventKey {

func (n *Namespace) useNamespace(fqn string) {
_, ns := client.Namespaced(fqn)
if client.CleanseNamespace(n.App().Config.ActiveNamespace()) == ns {
return
}
if err := n.App().switchNS(ns); err != nil {
n.App().Flash().Err(err)
return
Expand Down

0 comments on commit 3bac277

Please sign in to comment.