GoogleContainerTools/skaffold · error

cannot create temp file: %w

Error message

cannot create temp file: %w

What it means

After marshaling the build artifacts, writeBuildArtifacts creates a temp file (builds*.yaml via os.CreateTemp). If temp-file creation fails (e.g. no writable temp directory), this error is returned and the post-renderer setup aborts.

Source

Thrown at pkg/skaffold/helm/util.go:42

	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph"
	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest"
	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
)

// copy of cmd/skaffold/app/flags.BuildOutputs
type buildOutputs struct {
	Builds []graph.Artifact `json:"builds"`
}

func writeBuildArtifacts(builds []graph.Artifact) (string, func(), error) {
	buildOutput, err := json.Marshal(buildOutputs{builds})
	if err != nil {
		return "", nil, fmt.Errorf("cannot marshal build artifacts: %w", err)
	}

	f, err := os.CreateTemp("", "builds*.yaml")
	if err != nil {
		return "", nil, fmt.Errorf("cannot create temp file: %w", err)
	}
	if _, err := f.Write(buildOutput); err != nil {
		return "", nil, fmt.Errorf("cannot write to temp file: %w", err)
	}
	if err := f.Close(); err != nil {
		return "", nil, fmt.Errorf("cannot close temp file: %w", err)
	}
	return f.Name(), func() { os.Remove(f.Name()) }, nil
}

// SanitizeFilePath is used to sanitize filepaths that are provided to the `setFiles` flag
// helm `setFiles` doesn't work with the unescaped filepath separator (\) for Windows or if there are unescaped tabs and spaces in the directory names.
// So we escape all odd count occurrences of `\` for Windows, and wrap the entire string in quotes if it has spaces.
// This is very specific to the way helm handles its flags.
// See https://github.com/helm/helm/blob/d55c53df4e394fb62b0514a09c57bce235dd7877/pkg/cli/values/options.
// Otherwise the windows `syscall` package implements its own sanitizing for command args that's used by `exec.Cmd`.
// See https://github.com/golang/go/blob/6951da56b0ae2cd4250fc1b0350d090aed633ac1/src/syscall/exec_windows.go#L27
func SanitizeFilePath(s string, isWindowsOS bool) string {

View on GitHub (pinned to a1189de023)

Solutions

  1. Check disk space on the temp filesystem (`df -h $TMPDIR /tmp`)
  2. Set TMPDIR to an existing writable directory: `export TMPDIR=$(mktemp -d)`
  3. Raise the open-file limit: `ulimit -n 4096` (or fix fd leaks)
  4. Remount tmp writable or use a container image with writable /tmp

Example fix

// CI before
TMPDIR=/nonexistent skaffold deploy
// after
export TMPDIR=$(mktemp -d) && skaffold deploy
Defensive patterns

Strategy: validation

Validate before calling

TD="${TMPDIR:-/tmp}"; test -d "$TD" && test -w "$TD" && df --output=avail "$TD" | awk 'NR==2{exit ($1<104857600)?1:0}' || { echo "temp dir missing/unwritable or <100MB free"; exit 1; }

Prevention

When it happens

Trigger: os.CreateTemp("", "builds*.yaml") fails: TMPDIR is unwritable or nonexistent, /tmp is read-only, disk full, or too many open files (EMFILE) exhausted the fd limit.

Common situations: Locked-down containers with read-only rootfs; TMPDIR set to a path that doesn't exist; ulimit -n too low in CI; full tmpfs.

Related errors


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