kubernetes/kops · error

creating directory %q: %w

Error message

creating directory %q: %w

What it means

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.

Source

Thrown at pkg/dump/resourcedumper.go:209

		} else {
			lister = d.dynamicClient.Resource(job.gvr)
		}
		resourceList, err := lister.List(ctx, metav1.ListOptions{})
		if err != nil {
			var statusErr *k8sErrors.StatusError
			if errors.As(err, &statusErr) && statusErr.ErrStatus.Code >= 400 && statusErr.ErrStatus.Code < 500 {
				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 {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check/fix permissions on the artifacts directory: `ls -ld <artifactsDir>` and `chmod`/`chown` or run as a user with write access.
  2. Verify no file exists where a directory is needed: `ls -la` on the parent path and remove/rename the conflicting file.
  3. Pass a different --artifacts-dir located on a writable volume.
  4. Check disk space (`df -h`) and quota, and free space if ENOSPC.
  5. Inspect SELinux/AppArmor denials in audit logs if permissions look correct.

Example fix

// before (shell)
kops toolbox dump --artifacts-dir /mnt/ro-out --out yaml
// after (shell)
mkdir -p /mnt/out && kops toolbox dump --artifacts-dir /mnt/out --out yaml
Defensive patterns

Strategy: validation

Validate before calling

dir := path.Join(artifactsDir, "cluster-info")
if info, err := os.Stat(dir); err != nil {
  if !os.IsNotExist(err) { return fmt.Errorf("artifacts dir unusable: %w", err) }
} else if !info.IsDir() {
  return fmt.Errorf("%s exists but is not a directory", dir)
}
if err := os.MkdirAll(dir, 0o755); err != nil {
  return fmt.Errorf("cannot create artifacts dir %s: %w", dir, err)
}

Try / catch

// Go: errors are values; inspect the wrapped *os.PathError
if err := dump(...); err != nil {
  var pe *os.PathError
  if errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {
    // fix permissions or choose another artifacts dir
  }
  return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


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