Skip to content

Commit

Permalink
[Bug] fix #2592
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Mar 19, 2024
1 parent d0dad50 commit 4ddccc7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
6 changes: 3 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ func (a *APIClient) ServerVersion() (*version.Info, error) {
return info, nil
}

func (a *APIClient) IsValidNamespace(n string) bool {
ok, err := a.isValidNamespace(n)
func (a *APIClient) IsValidNamespace(ns string) bool {
ok, err := a.isValidNamespace(ns)
if err != nil {
log.Warn().Err(err).Msgf("namespace validation failed for: %q", n)
log.Warn().Err(err).Msgf("namespace validation failed for: %q", ns)
}

return ok
Expand Down
1 change: 1 addition & 0 deletions internal/config/data/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewActiveNamespace(n string) *Namespace {
if n == client.BlankNamespace {
n = client.DefaultNamespace
}

return &Namespace{
Active: n,
Favorites: []string{client.DefaultNamespace},
Expand Down
10 changes: 7 additions & 3 deletions internal/render/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ func (s StatefulSet) Render(o interface{}, ns string, r *model1.Row) error {
podContainerNames(sts.Spec.Template.Spec, true),
podImageNames(sts.Spec.Template.Spec, true),
mapToStr(sts.Labels),
AsStatus(s.diagnose(sts.Status.Replicas, sts.Status.ReadyReplicas)),
AsStatus(s.diagnose(sts.Spec.Replicas, sts.Status.Replicas, sts.Status.ReadyReplicas)),
ToAge(sts.GetCreationTimestamp()),
}

return nil
}

func (StatefulSet) diagnose(d, r int32) error {
func (StatefulSet) diagnose(w *int32, d, r int32) error {
if d != r {
return fmt.Errorf("desiring %d replicas got %d available", d, r)
return fmt.Errorf("desired %d replicas got %d available", d, r)
}
if w != nil && *w != r {
return fmt.Errorf("want %d replicas got %d available", *w, r)
}

return nil
}
21 changes: 3 additions & 18 deletions internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ func (a *App) Init(version string, rate int) error {
ns := a.Config.ActiveNamespace()

a.factory = watch.NewFactory(a.Conn())
ok, err := a.isValidNS(ns)
if !ok && err == nil {
return fmt.Errorf("app-init - invalid namespace: %q", ns)
}
a.initFactory(ns)

a.clusterModel = model.NewClusterInfo(a.factory, a.version, a.Config.K9s)
Expand Down Expand Up @@ -438,18 +434,6 @@ func (a *App) switchNS(ns string) error {
return a.factory.SetActiveNS(ns)
}

func (a *App) isValidNS(ns string) (bool, error) {
if ns == client.BlankNamespace || ns == client.NamespaceAll {
return true, nil
}

if !a.Conn().IsValidNamespace(ns) {
return false, fmt.Errorf("invalid namespace: %q", ns)
}

return true, nil
}

func (a *App) switchContext(ci *cmd.Interpreter, force bool) error {
name, ok := ci.HasContext()
if !ok || a.Config.ActiveContextName() == name {
Expand Down Expand Up @@ -477,12 +461,13 @@ func (a *App) switchContext(ci *cmd.Interpreter, force bool) error {
}
ns := a.Config.ActiveNamespace()
if !a.Conn().IsValidNamespace(ns) {
a.Flash().Errf("Unable to validate namespace %q. Using %q namespace", ns, client.DefaultNamespace)
ns = client.DefaultNamespace
log.Warn().Msgf("Unable to validate namespace: %q. Using %q as active namespace", ns, ns)
if err := a.Config.SetActiveNamespace(ns); err != nil {
return err
}
}
a.Flash().Errf("Using %q namespace", ns)

if err := a.Config.Save(true); err != nil {
log.Error().Err(err).Msg("config save failed!")
} else {
Expand Down

0 comments on commit 4ddccc7

Please sign in to comment.