ahmetb/kubectx · error
failed to create temp kubeconfig file: %w
Error message
failed to create temp kubeconfig file: %w
What it means
Wrapper error in ReadonlyShellOp's transformKubeconfig: os.CreateTemp failed to create the temporary file that will hold the original kubeconfig for the readonly proxy (disk full, no writable temp dir, permission denied). The read-only shell cannot be set up; error wrapped with %w.
Source
Thrown at cmd/kubectx/readonly_shell.go:52
badgeColor := color.New(color.BgYellow, color.FgBlack, color.Bold)
printer.EnableOrDisableColor(badgeColor)
s := &shellSession{
target: op.Target,
extraEnv: []string{env.EnvReadonlyShell + "=1"},
printEntry: func(w io.Writer, ctxName string) {
fmt.Fprintf(w, "%s kubectl context is %s in READ-ONLY mode — type 'exit' to leave.\n",
badgeColor.Sprint("[READONLY SHELL]"), printer.WarningColor.Sprint(ctxName))
},
printExit: func(w io.Writer, prevCtx string) {
fmt.Fprintf(w, "%s kubectl context is now %s.\n",
badgeColor.Sprint("[READONLY SHELL EXITED]"), printer.WarningColor.Sprint(prevCtx))
},
transformKubeconfig: func(data []byte) ([]byte, func(), error) {
// Write original kubeconfig to temp file for the proxy to load TLS/auth.
origFile, err := os.CreateTemp("", "kubectx-readonly-orig-*.yaml")
if err != nil {
return nil, nil, fmt.Errorf("failed to create temp kubeconfig file: %w", err)
}
origPath := origFile.Name()
if _, err := origFile.Write(data); err != nil {
origFile.Close()
os.Remove(origPath)
return nil, nil, fmt.Errorf("failed to write temp kubeconfig: %w", err)
}
origFile.Close()
// Start the readonly proxy.
p, err := proxy.Start(proxy.Config{
KubeconfigPath: origPath,
ContextName: op.Target,
})
if err != nil {
os.Remove(origPath)
return nil, nil, fmt.Errorf("failed to start readonly proxy: %w", err)View on GitHub (pinned to 12ad6fb22e)
Solutions
- Check TMPDIR/free space and permissions on the temp directory
- Retry after freeing disk space or fixing TMPDIR
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/readonly_shell.go:52 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/c49c5f71fe25bb38.
Report an issue: GitHub.