kubernetes/kops · error
creating file %q: %w
Error message
creating file %q: %w
What it means
After ensuring the parent directory exists, dumpGVRNamespaces creates the output file for a resource job via os.Create(resPath). If creation fails, the OS error is wrapped as "creating file %q: %w". Like the directory error, this is a local write failure, not from the Kubernetes API.
Source
Thrown at pkg/dump/resourcedumper.go:216
continue
}
results <- resourceDumpResult{
err: fmt.Errorf("listing resources for %v: %w", job, err),
}
continue
}
resPath := path.Join(d.artifactsDir, "cluster-info", fmt.Sprintf("%v.%v", job.String(), d.output))
err = os.MkdirAll(path.Dir(resPath), 0755)
if err != nil {
results <- resourceDumpResult{
err: fmt.Errorf("creating directory %q: %w", resPath, err),
}
continue
}
resFile, err := os.Create(resPath)
if err != nil {
results <- resourceDumpResult{
err: fmt.Errorf("creating file %q: %w", resPath, err),
}
continue
}
err = resourceList.EachListItem(func(obj runtime.Object) error {
o, err := meta.Accessor(obj)
if err != nil {
return err
}
o.SetManagedFields(nil)
if err := maskObject(obj); err != nil {
return err
}
return nil
})
if err != nil {
results <- resourceDumpResult{
err: fmt.Errorf("creating accessor for %v: %w", job, err),View on GitHub (pinned to 4c8573c808)
Solutions
- Fix ownership/permissions of the artifacts/cluster-info directory so the running user can write.
- Shorten --artifacts-dir or the output path to keep filenames under the filesystem limit.
- Ensure no directory exists at the target file path; remove the collision.
- Free disk space or move the dump to a volume with room.
- If writing inside a container, mount a writable volume at the artifacts dir.
Example fix
// before
err = os.Create("/mnt/ro/cluster-info/pods.default.yaml") // permission denied
// after
chmod u+w /mnt/out/cluster-info # or use a writable --artifacts-dir Defensive patterns
Strategy: validation
Validate before calling
if len(path.Base(resPath)) > 255 {
return fmt.Errorf("output filename %q exceeds filesystem name limit", resPath)
}
if f, err := os.OpenFile(resPath, os.O_CREATE|os.O_WRONLY, 0o644); err != nil {
return fmt.Errorf("cannot write to %s: %w", resPath, err)
} else {
f.Close()
os.Remove(resPath)
} Try / catch
if err := run(); err != nil {
var pe *os.PathError
if errors.As(err, &pe) {
switch {
case errors.Is(pe.Err, syscall.ENAMETOOLONG): // shorten --artifacts-dir
case errors.Is(pe.Err, syscall.EACCES): // fix permissions
case errors.Is(pe.Err, syscall.ENOSPC): // free disk space
}
}
} Prevention
- Ensure the cluster-info artifacts directory is writable by the kops process user.
- Keep --artifacts-dir short so <gvr>.<namespace>.<output> filenames stay under 255 bytes.
- Check free disk space before dumping large clusters.
- Run dumps as the same user that owns the artifacts directory.
When it happens
Trigger: os.Create(<artifactsDir>/cluster-info/<gvr-namespace>.<output>) fails because the directory is not writable, the target name exists as a directory, the filename exceeds the filesystem's NAME_MAX, or the disk is full.
Common situations: Artifacts dir on a read-only volume; running kops as a non-root user against a root-owned dir; long resource/namespace names pushing the filename over 255 bytes on ext4; an output filename colliding with an existing directory; out-of-disk during a large cluster dump.
Related errors
- creating directory %q: %w
- unable to read snippet: %s, error: %s
- unable to read template: %s, error: %s
- encoding resources for %v: %w
- error creating output directory %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/601edcf79998262e.
Report an issue: GitHub.