ahmetb/kubectx · error
could not list namespaces (is the cluster accessible?): %w
Error message
could not list namespaces (is the cluster accessible?): %w
What it means
queryNamespaces (via the k8s REST client) failed while listing namespaces, most commonly because the cluster referenced by the current context is unreachable or credentials are rejected. The hint in the message reflects that this is a connectivity/API-level failure, not a local config parse error.
Source
Thrown at cmd/kubens/list.go:65
// of namespaces available in the current context to w (one per line). It
// mirrors what ListOp.Run prints so the interactive fzf picker shows the same
// list the user would see from `kubens | fzf`.
func formatNamespaceList(kc *kubeconfig.Kubeconfig, w io.Writer) error {
ctx, err := kc.GetCurrentContext()
if err != nil {
return fmt.Errorf("failed to get current context: %w", err)
}
if ctx == "" {
return errors.New("current-context is not set")
}
curNs, err := kc.NamespaceOfContext(ctx)
if err != nil {
return fmt.Errorf("cannot read current namespace: %w", err)
}
ns, err := queryNamespaces(kc)
if err != nil {
return fmt.Errorf("could not list namespaces (is the cluster accessible?): %w", err)
}
for _, c := range ns {
s := c
if c == curNs {
s = printer.ActiveItemColor.Sprint(c)
}
fmt.Fprintf(w, "%s\n", s)
}
return nil
}
func queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {
if os.Getenv("_MOCK_NAMESPACES") != "" {
return []string{"ns1", "ns2"}, nil
}
clientset, err := newKubernetesClientSet(kc)View on GitHub (pinned to 12ad6fb22e)
Solutions
- Test connectivity: kubectl get namespaces — expect the same failure
- Verify the API server URL is reachable (VPN, network, DNS)
- Refresh expired credentials for the current context
- Set _MOCK_NAMESPACES=1 for local testing without a cluster
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubens/list.go:65 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/d8321789363daa82.
Report an issue: GitHub.