kubernetes/kops · error
error creating temp dir: %v
Error message
error creating temp dir: %v
What it means
AptSource.RenderLocal creates a temporary directory with os.MkdirTemp to stage the apt key file before running apt-key add. If directory creation fails (filesystem/permission problems), it returns this wrapped error. Without the temp dir, the apt repository key cannot be installed.
Source
Thrown at upup/pkg/fi/nodeup/nodetasks/aptsource.go:64
func (f *AptSource) String() string {
return f.Name
}
func (f *AptSource) Run(c *fi.NodeupContext) error {
return fi.NodeupDefaultDeltaRunMethod(f, c)
}
func (*AptSource) CheckChanges(a, e, changes *AptSource) error {
return nil
}
func (f *AptSource) RenderLocal(t *local.LocalTarget, a, e, changes *AptSource) error {
// Not adding ctx to signature as RenderLocal seems to be part of a common interface
ctx := context.TODO()
tmpDir, err := os.MkdirTemp("", "aptsource")
if err != nil {
return fmt.Errorf("error creating temp dir: %v", err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
klog.Warningf("error deleting temp dir %q: %v", tmpDir, err)
}
}()
filename := path.Join(tmpDir, f.Name+".gpg")
if _, err := fi.DownloadURL(ctx, f.Keyring, filename, nil); err != nil {
return err
}
args := []string{"apt-key", "add", filename}
klog.Infof("running command %s", args)
cmd := exec.Command(args[0], args[1:]...)
output, err := cmd.CombinedOutput()
if exitCode := cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(); err != nil && exitCode != 100 {View on GitHub (pinned to 4c8573c808)
Solutions
- Free disk space on the node (`df -h`) — ENOSPC is the most common cause
- Verify /tmp exists, is writable, and is not mounted read-only
- Check TMPDIR env is valid or unset it so /tmp is used
- Re-run nodeup after fixing the filesystem
Defensive patterns
Strategy: validation
Validate before calling
if st, err := os.Stat("/tmp"); err != nil || !st.IsDir() {
return errors.New("/tmp missing or not a directory")
}
if err := os.MkdirTemp("", "aptsource-check"); err != nil {
return fmt.Errorf("cannot create temp dirs: %w", err)
} Try / catch
if err := nodeup.Run(ctx); err != nil {
if strings.Contains(err.Error(), "error creating temp dir") {
// check df -h and /tmp mount flags before retry
}
} Prevention
- Monitor node disk usage; free space before bootstrap
- Keep /tmp writable and not mounted read-only/noexec for temp staging
- Avoid setting TMPDIR to custom paths in nodeup's environment
- Set up disk alerts on node / filesystem
When it happens
Trigger: os.MkdirTemp("", "aptsource") fails — typically ENOSPC (disk full), read-only /tmp, or permission errors on TMPDIR.
Common situations: Node disk full during bootstrap; /tmp mounted noexec/readonly or with restrictive permissions; TMPDIR pointing at a nonexistent path in containers.
Related errors
- path: %s already exists but is not a directory
- failed to read %s: %w
- error checking for /run/cilium/cgroupv2: %v
- failed to ensure the directory: %s, error: %w
- error closing target: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/277c840ba843aa7e.
Report an issue: GitHub.