From c57909e31a4bff9a77fefcf489c0fcbccef58ac5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Mar 2026 08:15:23 +0000 Subject: [PATCH] kubens: show slow-listing warning after 3s during namespace list When `kubens` is run with no args in non-interactive mode (ListOp), start a background goroutine that prints a warning to stderr after 3 seconds if the Kubernetes API call is still in progress. The warning advises users to switch directly with `kubens -f ` to avoid the slow list call. The goroutine is cancelled immediately if listing completes before the timeout. https://claude.ai/code/session_01XJXHq8WG22iqX8KaDb9RZz --- cmd/kubens/list.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/kubens/list.go b/cmd/kubens/list.go index dd7633a..6ed9528 100644 --- a/cmd/kubens/list.go +++ b/cmd/kubens/list.go @@ -21,6 +21,7 @@ import ( "io" "os" "slices" + "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -52,6 +53,16 @@ func (op ListOp) Run(stdout, stderr io.Writer) error { return fmt.Errorf("cannot read current namespace: %w", err) } + done := make(chan struct{}) + defer close(done) + go func() { + select { + case <-time.After(3 * time.Second): + printer.Warning(stderr, `listing namespaces is taking long, switch to a namespace directly with "kubens -f "`) + case <-done: + } + }() + ns, err := queryNamespaces(kc) if err != nil { return fmt.Errorf("could not list namespaces (is the cluster accessible?): %w", err)