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

  1. Free disk space on the node (`df -h`) — ENOSPC is the most common cause
  2. Verify /tmp exists, is writable, and is not mounted read-only
  3. Check TMPDIR env is valid or unset it so /tmp is used
  4. 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

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


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/277c840ba843aa7e. Report an issue: GitHub.