ahmetb/kubectx · error
failed to list namespaces from k8s API: %w
Error message
failed to list namespaces from k8s API: %w
What it means
A paginated CoreV1().Namespaces().List call against the cluster API failed. Causes: RBAC denying namespace list to the authenticated user, API server errors, or the connection dropping mid-pagination (the code loops with Limit 500 + Continue tokens).
Source
Thrown at cmd/kubens/list.go:98
return []string{"ns1", "ns2"}, nil
}
clientset, err := newKubernetesClientSet(kc)
if err != nil {
return nil, fmt.Errorf("failed to initialize k8s REST client: %w", err)
}
var out []string
var next string
for {
list, err := clientset.CoreV1().Namespaces().List(
context.Background(),
metav1.ListOptions{
Limit: 500,
Continue: next,
})
if err != nil {
return nil, fmt.Errorf("failed to list namespaces from k8s API: %w", err)
}
next = list.Continue
out = slices.Grow(out, len(list.Items))
for _, it := range list.Items {
out = append(out, it.Name)
}
if next == "" {
break
}
}
return out, nil
}
func newKubernetesClientSet(kc *kubeconfig.Kubeconfig) (*kubernetes.Clientset, error) {
var cfg *rest.Config
var err error
if paths := kc.ConfigPaths(); len(paths) > 0 {View on GitHub (pinned to 12ad6fb22e)
Solutions
- Verify RBAC: kubectl auth can-i list namespaces
- Retry in case of transient API server unavailability
- Check the wrapped API error for Forbidden/Timeout details
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at cmd/kubens/list.go:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ahmetb/kubectx@12ad6fb22e (2026-09-02).
Data as JSON: /api/errors/a53898903b5ea57f.
Report an issue: GitHub.