{"record":{"id":"b045d261614a7867","repo":"kubernetes/kops","slug":"creating-directory-q-w-b045d2","errorCode":null,"errorMessage":"creating directory %q: %w","messagePattern":"creating directory %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/resourcedumper.go","lineNumber":209,"sourceCode":"\t\t} else {\n\t\t\tlister = d.dynamicClient.Resource(job.gvr)\n\t\t}\n\t\tresourceList, err := lister.List(ctx, metav1.ListOptions{})\n\t\tif err != nil {\n\t\t\tvar statusErr *k8sErrors.StatusError\n\t\t\tif errors.As(err, &statusErr) && statusErr.ErrStatus.Code >= 400 && statusErr.ErrStatus.Code < 500 {\n\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 {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/resourcedumper.go#L191-L227","documentation":"In kOps' resource dumper, dumpGVRNamespaces writes each listed Kubernetes resource to <artifactsDir>/cluster-info/. Before creating the output file it runs os.MkdirAll on the file's parent directory; if that fails, the underlying OS error (e.g. permission denied, ENOSPC, path is a file) is wrapped as \"creating directory %q: %w\". This is a local filesystem error, not a Kubernetes API error.","triggerScenarios":"os.MkdirAll(path.Dir(resPath)) returns a non-nil error: artifactsDir points somewhere unwritable (read-only filesystem, non-existent root with permissions blocked, owned by another user), an intermediate path component exists as a regular file, the disk is full, or SELinux/AppArmor denies writes.","commonSituations":"Running `kops get cluster -o kubecfg --dump` (or `kops toolbox dump`) with --artifacts-dir on a read-only mount or a directory the user cannot write; the artifacts dir path colliding with an existing file; running in a container with a restricted root filesystem; disk quota exceeded on the node.","solutions":["Check/fix permissions on the artifacts directory: `ls -ld <artifactsDir>` and `chmod`/`chown` or run as a user with write access.","Verify no file exists where a directory is needed: `ls -la` on the parent path and remove/rename the conflicting file.","Pass a different --artifacts-dir located on a writable volume.","Check disk space (`df -h`) and quota, and free space if ENOSPC.","Inspect SELinux/AppArmor denials in audit logs if permissions look correct."],"exampleFix":"// before (shell)\nkops toolbox dump --artifacts-dir /mnt/ro-out --out yaml\n// after (shell)\nmkdir -p /mnt/out && kops toolbox dump --artifacts-dir /mnt/out --out yaml","handlingStrategy":"validation","validationCode":"dir := path.Join(artifactsDir, \"cluster-info\")\nif info, err := os.Stat(dir); err != nil {\n  if !os.IsNotExist(err) { return fmt.Errorf(\"artifacts dir unusable: %w\", err) }\n} else if !info.IsDir() {\n  return fmt.Errorf(\"%s exists but is not a directory\", dir)\n}\nif err := os.MkdirAll(dir, 0o755); err != nil {\n  return fmt.Errorf(\"cannot create artifacts dir %s: %w\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"// Go: errors are values; inspect the wrapped *os.PathError\nif err := dump(...); err != nil {\n  var pe *os.PathError\n  if errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {\n    // fix permissions or choose another artifacts dir\n  }\n  return err\n}","preventionTips":["Point --artifacts-dir at a pre-created directory owned by the user running kops.","Avoid mounting artifacts dirs read-only; test writability with `touch <dir>/.wtest` first.","Never place a file where a directory component of the path is expected.","Monitor disk space before large cluster dumps."],"tags":["filesystem","permissions","kops","dump"],"backgroundTag":"mkdir-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"}