kubernetes/kops · error

reading file %q: %v

Error message

reading file %q: %v

What it means

Returned when `factory.VFSContext().ReadFile(f)` fails reading a file (or VFS location like s3://) passed to `kops delete -f`. The VFS context supports local files and cloud URLs; the wrapped error (not found, permission denied, S3 error) identifies the actual cause.

Source

Thrown at cmd/kops/delete.go:95

	return cmd
}

func RunDelete(ctx context.Context, factory *util.Factory, out io.Writer, d *DeleteOptions) error {
	// We could have more than one cluster in a manifest so we are using a set
	deletedClusters := sets.NewString()

	for _, f := range d.Filenames {
		var contents []byte
		var err error
		if f == "-" {
			contents, err = ConsumeStdin()
			if err != nil {
				return fmt.Errorf("reading from stdin: %v", err)
			}
		} else {
			contents, err = factory.VFSContext().ReadFile(f)
			if err != nil {
				return fmt.Errorf("reading file %q: %v", f, err)
			}
		}

		sections := text.SplitContentToSections(contents)
		for _, section := range sections {
			o, gvk, err := kopscodecs.Decode(section, nil)
			if err != nil {
				return fmt.Errorf("parsing file %q: %v", f, err)
			}

			switch v := o.(type) {
			case *kopsapi.Cluster:
				options := &DeleteClusterOptions{
					ClusterName: v.ObjectMeta.Name,
					Yes:         d.Yes,
				}
				err = RunDeleteCluster(ctx, factory, out, options)
				if err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the file/URL exists (`ls -l <path>` or `aws s3 ls <url>`) and correct typos.
  2. For remote URLs, confirm cloud credentials and region are configured correctly.
  3. Run from the intended working directory or switch to absolute paths.

Example fix

// before
kops delete -f manifests/cluter.yaml
// after
kops delete -f manifests/cluster.yaml
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
if (target.startsWith('s3://')) {
  execSync(`aws s3 ls ${target}`, { stdio: 'inherit' }); // creds/reachability check
} else if (!fs.existsSync(target)) {
  throw new Error(`delete manifest not found: ${target}`);
}

Type guard

function manifestReadable(target) {
  try { return require('fs').accessSync(target, require('fs').constants.R_OK) === undefined; } catch { return false; }
}

Try / catch

try {
  runKops(['delete', '-f', target]);
} catch (e) {
  if (/reading file/.test(e.message)) {
    console.error(`Cannot read ${target}; verify path or VFS credentials.`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `kops delete -f <path>` where the path doesn't exist, is unreadable, or the remote VFS URL (e.g. s3://bucket/manifest.yaml) can't be fetched due to missing credentials or wrong region.

Common situations: Typo'd manifest path; deleted or renamed manifest file; reading from an S3 URL without valid AWS credentials or with a wrong region; running from a different working directory with a relative path.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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