kubens - fails: No previous namespace found for current context
Routes kubens dash-toggle failures. Use when kubens - reports No previous namespace found for current context. Not for unknown names or RBAC errors.
The dash toggles to the previous namespace, but kubens has not recorded one for this context yet - first switch, or the per-context cache was cleared. Switch namespaces once with kubens [name] (that records the previous one), and kubens - toggles from then on.
The error
No previous namespace found for current contextWhat to do
- Switch once to record a previous namespace:
kubens [first]
kubens [second] Expected: Each prints Active namespace is "[name]"..
- Toggle:
kubens - Expected: Prints Active namespace is "[first]"..
- If it still fails, the cache lives per context under ~/.kube/cache/kubens/ - check it exists and is writable.
Expected: Cache file present after a successful switch.
When this applies
- the exact No previous namespace found for current context message
- first use of kubens - on a context
- after clearing ~/.kube/cache/kubens
When it does NOT apply
- no namespace exists with name (different error)
- the dash toggling to an unexpected namespace (stale cache - switch twice)
Works with
kubens (ahmetb/kubectx)
no previous context found (kubectx -)
The kubectx twin of this error. Same shape: switch once with an explicit name first.
Why it happens
kubens saves the previous namespace per context in a cache file under your home on every switch. No recorded switch for this context means the toggle has nothing to return to.
Edge cases
- Each context tracks its own previous namespace - toggling after a context switch uses that context's history.
- Read-only HOME (containers) breaks the cache; use explicit names there.
Resolved from
gh:nao1215/atago (e2e kubens behavior spec) - https://github.com/nao1215/atago/blob/HEAD/doc/e2e/kubectx.md
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.