GoogleContainerTools/skaffold · error

writing k8s manifest to file: %w

Error message

writing k8s manifest to file: %w

What it means

When skaffold init finishes, WriteData writes any newly generated Kubernetes manifests to disk with os.WriteFile(path, manifest, 0644). If the write fails (unwritable directory, permission problem, path is a directory), the OS error is wrapped as 'writing k8s manifest to file'.

Source

Thrown at pkg/skaffold/initializer/init.go:132

	pipeline, err := yaml.Marshal(newConfig)
	if err != nil {
		return err
	}

	if c.Opts.ConfigurationFile == "-" {
		out.Write(pipeline)
		return nil
	}

	if !c.Force && !c.Opts.AutoInit {
		if done, err := prompt.WriteSkaffoldConfig(out, pipeline, newManifests, c.Opts.ConfigurationFile); done {
			return err
		}
	}

	for path, manifest := range newManifests {
		if err = os.WriteFile(path, manifest, 0644); err != nil {
			return fmt.Errorf("writing k8s manifest to file: %w", err)
		}
		fmt.Fprintf(out, "Generated manifest %s was written\n", path)
	}

	if c.Opts.AutoInit {
		return nil
	}

	if err = os.WriteFile(c.Opts.ConfigurationFile, pipeline, 0644); err != nil {
		return fmt.Errorf("writing config to file: %w", err)
	}

	fmt.Fprintf(out, "Configuration %s was written\n", c.Opts.ConfigurationFile)
	tips.PrintForInit(out, c.Opts)

	return nil
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Check the wrapped OS error for the exact cause (ENOENT/EACCES/EISDIR)
  2. Ensure the target directory exists and is writable (mkdir -p, chown/chmod)
  3. Verify the path isn't a directory; remove or rename the conflicting entry
  4. If the repo is read-only, run init in a writable checkout

Example fix

// before
skaffold init   # manifests/target.yaml is a directory
// after
rm -rf manifests/target.yaml && mkdir -p manifests
skaffold init
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight the manifest output paths before running init:
for _, p := range candidateManifestPaths {
    if fi, err := os.Stat(p); err == nil && fi.IsDir() {
        return fmt.Errorf("%s is a directory; init cannot write a manifest there", p)
    }
    if err := os.WriteFile(p+".writetest", nil, 0o644); err != nil {
        return fmt.Errorf("cannot write %s: %w", p, err)
    }
    os.Remove(p + ".writetest")
}

Try / catch

if err := initData.WriteData(out); err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) {
        return fmt.Errorf("init failed writing %s: check perms/dir (%v)", pe.Path, pe.Err)
    }
    return err
}

Prevention

When it happens

Trigger: DoInit/Transparent reach the manifest-writing loop and os.WriteFile fails for one of the generated manifest paths — directory doesn't exist, no write permission, path points to an existing directory, or the filesystem is read-only.

Common situations: init run in a read-only mounted repo; manifest target path conflicts with an existing directory of the same name; running without ownership of the project directory (sudo-created files); disk full.

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 GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/9bf306a9dc26f176. Report an issue: GitHub.