diff --git a/internal/config/k9s.go b/internal/config/k9s.go index 37bb6044..4afbb2b1 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -29,6 +29,7 @@ type K9s struct { Clusters map[string]*Cluster `yaml:"clusters,omitempty"` Thresholds Threshold `yaml:"thresholds"` ScreenDumpDir string `yaml:"screenDumpDir"` + DisablePodCounting bool `yaml:"disablePodCounting"` manualRefreshRate int manualHeadless *bool manualLogoless *bool diff --git a/internal/dao/node.go b/internal/dao/node.go index 8f9cb0b5..9504f110 100644 --- a/internal/dao/node.go +++ b/internal/dao/node.go @@ -155,6 +155,8 @@ func (n *Node) List(ctx context.Context, ns string) ([]runtime.Object, error) { nmx, _ = client.DialMetrics(n.Client()).FetchNodesMetricsMap(ctx) } + shouldCountPods, _ := ctx.Value(internal.KeyPodCounting).(bool) + res := make([]runtime.Object, 0, len(oo)) for _, o := range oo { u, ok := o.(*unstructured.Unstructured) @@ -164,9 +166,12 @@ func (n *Node) List(ctx context.Context, ns string) ([]runtime.Object, error) { fqn := extractFQN(o) _, name := client.Namespaced(fqn) - podCount, err := n.CountPods(name) - if err != nil { - log.Error().Err(err).Msgf("unable to get pods count for %s", name) + podCount := -1 + if shouldCountPods { + podCount, err = n.CountPods(name) + if err != nil { + log.Error().Err(err).Msgf("unable to get pods count for %s", name) + } } res = append(res, &render.NodeWithMetrics{ Raw: u, diff --git a/internal/keys.go b/internal/keys.go index 522d0f9b..f184b49d 100644 --- a/internal/keys.go +++ b/internal/keys.go @@ -30,4 +30,5 @@ const ( KeyWithMetrics ContextKey = "withMetrics" KeyViewConfig ContextKey = "viewConfig" KeyWait ContextKey = "wait" + KeyPodCounting ContextKey = "podCounting" ) diff --git a/internal/view/node.go b/internal/view/node.go index 63011832..d70b2b51 100644 --- a/internal/view/node.go +++ b/internal/view/node.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/derailed/k9s/internal" "github.com/derailed/k9s/internal/client" "github.com/derailed/k9s/internal/dao" "github.com/derailed/k9s/internal/ui" @@ -26,10 +27,15 @@ func NewNode(gvr client.GVR) ResourceViewer { } n.AddBindKeysFn(n.bindKeys) n.GetTable().SetEnterFn(n.showPods) + n.SetContextFn(n.nodeContext) return &n } +func (n *Node) nodeContext(ctx context.Context) context.Context { + return context.WithValue(ctx, internal.KeyPodCounting, !n.App().Config.K9s.DisablePodCounting) +} + func (n *Node) bindDangerousKeys(aa ui.KeyActions) { aa.Add(ui.KeyActions{ ui.KeyC: ui.NewKeyAction("Cordon", n.toggleCordonCmd(true), true),