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

  1. Check disk space (df -h) and free space on the artifacts volume.
  2. Fix permissions on the artifacts directory: chown/chmod so the kops user can write (MkdirAll failures earlier are only warned).
  3. Verify the artifacts dir path is valid and not a file; avoid exotic characters in node/service names affecting the path.
  4. Ensure only one dump process writes the same artifacts directory at a time.
  5. 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

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


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