Add env var to disable node pod counts (#2168)

* Add env var to disable node pod counts

* Move disabling pod counting to config

* Correct alias context function name
mine
Nick Mills-Barrett 2023-11-12 17:32:02 +00:00 committed by GitHub
parent 23e600bef5
commit 9d804c6c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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,

View File

@ -30,4 +30,5 @@ const (
KeyWithMetrics ContextKey = "withMetrics"
KeyViewConfig ContextKey = "viewConfig"
KeyWait ContextKey = "wait"
KeyPodCounting ContextKey = "podCounting"
)

View File

@ -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),