GoogleContainerTools/skaffold · error

failed to create the tmp directory: %w

Error message

failed to create the tmp directory: %w

What it means

ManifestList.Write with an output starting with gs:// first creates a temp staging directory via os.MkdirTemp. If that fails, the error is wrapped by writeErr as 'failed to create the tmp directory' and the manifests are not written.

Source

Thrown at pkg/skaffold/kubernetes/manifest/util.go:47

const (
	manifestsStagingFolder       = "manifest_tmp"
	renderedManifestsStagingFile = "rendered_manifest.yaml"
	gcsPrefix                    = "gs://"
)

var ManifestTmpDir = filepath.Join(os.TempDir(), manifestsStagingFolder)

// Write writes manifests to a file, a writer or a GCS bucket.
func Write(manifests string, output string, manifestOut io.Writer) error {
	switch {
	case output == "":
		_, err := fmt.Fprintln(manifestOut, manifests)
		return err
	case strings.HasPrefix(output, gcsPrefix):
		tempDir, err := os.MkdirTemp("", manifestsStagingFolder)
		if err != nil {
			return writeErr(fmt.Errorf("failed to create the tmp directory: %w", err))
		}
		defer os.RemoveAll(tempDir)
		tempFile := filepath.Join(tempDir, renderedManifestsStagingFile)
		if err := dumpToFile(manifests, tempFile); err != nil {
			return err
		}
		gcs := client.Native{}
		if err := gcs.UploadFile(context.Background(), tempFile, output); err != nil {
			return writeErr(fmt.Errorf("failed to copy rendered manifests to GCS: %w", err))
		}
		return nil
	default:
		return dumpToFile(manifests, output)
	}
}

func dumpToFile(manifests string, filepath string) error {
	f, err := os.Create(filepath)

View on GitHub (pinned to a1189de023)

Solutions

  1. Fix or unset the TMPDIR environment variable so it points to a writable directory
  2. Ensure the filesystem backing os.TempDir() has free space and write permission
  3. Alternatively write rendered manifests to a local path instead of gs://

Example fix

# before
export TMPDIR=/nonexistent
# after
export TMPDIR=/tmp  # writable directory
Defensive patterns

Strategy: validation

Validate before calling

tmp := os.TempDir()
if st, err := os.Stat(tmp); err != nil || !st.IsDir() {
    return fmt.Errorf("TMPDIR %q is not a usable directory", tmp)
}

Try / catch

if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) && errors.Is(pe.Err, os.ErrPermission) {
        // point TMPDIR at a writable dir and retry
    }
    return err
}

Prevention

When it happens

Trigger: Calling Write (called from anonymous callers, e.g. render output handling) with output='gs://...' when os.MkdirTemp("", manifestsStagingFolder) fails — typically TMPDIR pointing somewhere unwritable or nonexistent.

Common situations: TMPDIR env var set to a missing/unwritable path in CI or containers; read-only root filesystem; disk full.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/d471251c6c169c4a. Report an issue: GitHub.