kubernetes/kops · error
error creating temp file in %q: %w
Error message
error creating temp file in %q: %w
What it means
WriteFile stages data in a temp file named .tmp-<random> inside the target directory, created via sftpClient.Create. If the SFTP server refuses to create that temp file, this error wraps the cause. It indicates the directory exists (mkdirAll passed) but a new file cannot be created there.
Source
Thrown at util/pkg/vfs/sshfs.go:188
func (p *SSHPath) WriteFile(ctx context.Context, data io.ReadSeeker, acl ACL) error {
sftpClient, err := p.newClient(ctx)
if err != nil {
return err
}
defer sftpClient.Close()
dir := path.Dir(p.path)
err = mkdirAll(sftpClient, dir)
if err != nil {
return err
}
tempfile := path.Join(dir, fmt.Sprintf(".tmp-%d", rand.Int63()))
f, err := sftpClient.Create(tempfile)
if err != nil {
// TODO: Retry if concurrently created?
return fmt.Errorf("error creating temp file in %q: %w", dir, err)
}
// Note from here on in we have to close f and delete or rename the temp file
shouldClose := true
defer func() {
if shouldClose {
// Something went wrong; try to close the temp file
if err := f.Close(); err != nil {
klog.Warningf("unable to close temp file %q: %v", tempfile, err)
}
}
}()
deleteTempFile := true
defer func() {
if deleteTempFile {
// Something went wrong; try to remove the temp file
if err := sftpClient.Remove(tempfile); err != nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Check free disk space on the remote host (`df -h <dir>`) and free space if full.
- Verify the SSH user has write permission on the directory; `sudo chown`/`chmod` it or pre-create writable staging.
- If an old .tmp-* file blocks creation (stale from a crashed run), remove it: `rm <dir>/.tmp-*`.
- Retry — the comment notes concurrent creation is possible; the random suffix makes collisions unlikely.
Example fix
// before: full disk on remote host Filesystem / has 0 available // after $ ssh host 'rm -rf /var/log/journal/*old*' && kops replace ... # retry succeeds
Defensive patterns
Strategy: validation
Validate before calling
// verify disk space and writability on the remote directory before writing
out := sshRun(host, fmt.Sprintf("df --output=avail -B1 %s | tail -1; test -w %s && echo ok", dir, dir))
// require available > neededBytes and "ok" present Try / catch
err := path.WriteFile(ctx, data, acl)
if err != nil && strings.Contains(err.Error(), "error creating temp file") {
// clean stale temp files then retry once
sshRun(host, fmt.Sprintf("rm -f %s/.tmp-*", dir))
return path.WriteFile(ctx, data, acl)
} Prevention
- Monitor remote disk usage on nodes that receive cluster state files.
- Clean stale .tmp-* files left by crashed runs.
- Ensure the SFTP subsystem (internal-sftp) is not chrooted to a read-only tree.
When it happens
Trigger: WriteFile on an SSHPath where the directory is not writable by the SFTP user, the disk is full, or (rarely) the random temp name collides with an existing file that cannot be opened for writing.
Common situations: Writing node bootstrap files to /etc/kubernetes/manifests with a non-root SFTP user; full disk on the master node; immutable directory; SFTP chroot/subsystem restricting writes to certain paths.
Related errors
- not a directory: %q
- error writing temp file: %v
- error reading SSH public key %v: %v
- error reading /var/log: %v
- error listing %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e4d829d9f972a533.
Report an issue: GitHub.