kubernetes/kops · warning
error creating file %q: %v
Error message
error creating file %q: %v
What it means
Returned by logDumperNode.shellToFile (pkg/dump/dumper.go:572) when os.Create(destPath) fails while preparing to capture a remote command's output into the local artifacts directory. The remote command is never run; the failure is purely local filesystem access at the destination path (under d.artifactsDir/<node>/). Errors here are collected by dump and logged as warnings, not fatal.
Source
Thrown at pkg/dump/dumper.go:572
for _, line := range strings.Split(stdout.String(), "\n") {
tokens := strings.Fields(line)
if len(tokens) == 0 || tokens[0] == "" {
continue
}
services = append(services, tokens[0])
}
return services, nil
}
// shellToFile executes a command and copies the output to a file
func (n *logDumperNode) shellToFile(ctx context.Context, command string, destPath string) error {
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
klog.Warningf("unable to mkdir on %q: %v", filepath.Dir(destPath), err)
}
f, err := os.Create(destPath)
if err != nil {
return fmt.Errorf("error creating file %q: %v", destPath, err)
}
defer f.Close()
if err := n.client.ExecPiped(ctx, command, f, f); err != nil {
return fmt.Errorf("error executing command %q: %v", command, err)
}
return nil
}
// sshClientImplementation is the default implementation of sshClient, binding to a *ssh.Client
type sshClientImplementation struct {
client *ssh.Client
forwardTo string
}
var _ sshClient = &sshClientImplementation{}
View on GitHub (pinned to 4c8573c808)
Solutions
- Check disk space (df -h) and free space on the artifacts volume.
- Fix permissions on the artifacts directory: chown/chmod so the kops user can write (MkdirAll failures earlier are only warned).
- Verify the artifacts dir path is valid and not a file; avoid exotic characters in node/service names affecting the path.
- Ensure only one dump process writes the same artifacts directory at a time.
- Re-run the dump after freeing space or fixing permissions — the capture is idempotent per file.
Example fix
// before
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
klog.Warningf("unable to mkdir on %q: %v", filepath.Dir(destPath), err)
}
f, err := os.Create(destPath)
// after
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
return fmt.Errorf("creating dir for %q: %w", destPath, err)
}
f, err := os.Create(destPath) Defensive patterns
Strategy: validation
Validate before calling
// pre-check artifacts dir writability before dumping
testFile := filepath.Join(artifactsDir, ".write-test")
if err := os.WriteFile(testFile, nil, 0o644); err != nil {
return fmt.Errorf("artifacts dir %s not writable: %w", artifactsDir, err)
}
os.Remove(testFile)
// also check free space
if st, err := os.Statfs(artifactsDir); err == nil && st.Bavail*uint64(st.Bsize) < 1<<30 {
return fmt.Errorf("less than 1GB free in %s", artifactsDir)
} Try / catch
f, err := os.Create(destPath)
if err != nil {
return fmt.Errorf("error creating file %q: %w", destPath, err)
}
defer f.Close() Prevention
- Verify disk space and write permissions on the artifacts directory before starting a dump.
- Run the dump as a user that owns (or can write to) the artifacts dir.
- Don't run two dump processes against the same artifacts directory.
- Make mkdir failures fatal in shellToFile instead of only warning.
When it happens
Trigger: os.Create(destPath) errors: artifacts directory read-only or owned by another user, disk full on the machine running kops, invalid path characters from a node/service name, or a destPath that resolves to a directory. Note os.MkdirAll failure is only warned about, so a failed mkdir surfaces here instead.
Common situations: Running `kops toolbox dump` with --artifacts-dir (or default dir) on a read-only or full disk; running as a user without write permission to the artifacts dir; race where two dumpers write the same artifacts directory concurrently.
Understand the failure class
Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.
Related errors
- error reading /var/log: %v
- error listing %q: %v
- creating directories %q: %w
- unable to read snippet: %s, error: %s
- unable to read template: %s, error: %s
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/20b731c00e0563ea.
Report an issue: GitHub.