MCPcopy
hub / github.com/derailed/k9s / switchNamespaceCmd

Method switchNamespaceCmd

internal/view/browser.go:560–596  ·  view source on GitHub ↗
(evt *tcell.EventKey)

Source from the content-addressed store, hash-verified

558}
559
560func (b *Browser) switchNamespaceCmd(evt *tcell.EventKey) *tcell.EventKey {
561 i, err := strconv.Atoi(string(evt.Rune()))
562 if err != nil {
563 slog.Error("Unable to convert keystroke", slogs.Error, err)
564 return nil
565 }
566 ns := b.namespaces[i]
567
568 auth, err := b.App().factory.Client().CanI(ns, b.GVR(), "", client.ListAccess)
569 if !auth {
570 if err == nil {
571 err = fmt.Errorf("access denied for user on: %s/%s", ns, b.GVR())
572 }
573 b.App().Flash().Err(err)
574 return nil
575 }
576
577 if err := b.app.switchNS(ns); err != nil {
578 b.App().Flash().Err(err)
579 return nil
580 }
581 b.setNamespace(ns)
582 if client.IsClusterScoped(ns) {
583 b.app.Flash().Infof("Viewing %s...", b.GVR())
584 } else {
585 b.app.Flash().Infof("Viewing %s in namespace `%s`...", b.GVR(), client.PrintNamespace(ns))
586 }
587 b.refresh()
588 b.UpdateTitle()
589 b.SelectRow(1, 0, true)
590 b.app.CmdBuff().Reset()
591 if err := b.app.Config.SetActiveNamespace(b.GetModel().GetNamespace()); err != nil {
592 slog.Error("Unable to set active namespace during ns switch", slogs.Error, err)
593 }
594
595 return nil
596}
597
598// ----------------------------------------------------------------------------
599// Helpers...

Callers

nothing calls this directly

Calls 15

setNamespaceMethod · 0.95
refreshMethod · 0.95
IsClusterScopedFunction · 0.92
PrintNamespaceFunction · 0.92
switchNSMethod · 0.80
InfofMethod · 0.80
SelectRowMethod · 0.80
SetActiveNamespaceMethod · 0.80
CanIMethod · 0.65
ClientMethod · 0.65
AppMethod · 0.65
GVRMethod · 0.65

Tested by

no test coverage detected