{"record":{"id":"601edcf79998262e","repo":"kubernetes/kops","slug":"creating-file-q-w-601edc","errorCode":null,"errorMessage":"creating file %q: %w","messagePattern":"creating file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/resourcedumper.go","lineNumber":216,"sourceCode":"\t\t\t\tcontinue\n\t\t\t}\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"listing resources for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tresPath := path.Join(d.artifactsDir, \"cluster-info\", fmt.Sprintf(\"%v.%v\", job.String(), d.output))\n\t\terr = os.MkdirAll(path.Dir(resPath), 0755)\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"creating directory %q: %w\", resPath, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tresFile, err := os.Create(resPath)\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"creating file %q: %w\", resPath, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\terr = resourceList.EachListItem(func(obj runtime.Object) error {\n\t\t\to, err := meta.Accessor(obj)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\to.SetManagedFields(nil)\n\t\t\tif err := maskObject(obj); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"creating accessor for %v: %w\", job, err),","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/resourcedumper.go#L198-L234","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nerr = os.Create(\"/mnt/ro/cluster-info/pods.default.yaml\") // permission denied\n// after\nchmod u+w /mnt/out/cluster-info  # or use a writable --artifacts-dir","handlingStrategy":"validation","validationCode":"if len(path.Base(resPath)) > 255 {\n  return fmt.Errorf(\"output filename %q exceeds filesystem name limit\", resPath)\n}\nif f, err := os.OpenFile(resPath, os.O_CREATE|os.O_WRONLY, 0o644); err != nil {\n  return fmt.Errorf(\"cannot write to %s: %w\", resPath, err)\n} else {\n  f.Close()\n  os.Remove(resPath)\n}","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n  var pe *os.PathError\n  if errors.As(err, &pe) {\n    switch {\n    case errors.Is(pe.Err, syscall.ENAMETOOLONG): // shorten --artifacts-dir\n    case errors.Is(pe.Err, syscall.EACCES):      // fix permissions\n    case errors.Is(pe.Err, syscall.ENOSPC):      // free disk space\n    }\n  }\n}","preventionTips":["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."],"tags":["filesystem","permissions","kops","dump"],"backgroundTag":"file-create-permission-denied","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}