kubernetes/kops · error

error reading %s: %v

Error message

error reading %s: %v

What it means

After listing the tree, loadFrom reads each file's contents. A read failure that is NOT os.IsNotExist is fatal: the file exists in the listing but its contents could not be fetched, so the template set is incomplete and the error reports which file failed.

Source

Thrown at pkg/templates/templates.go:69

// IsTemplate reports whether key was loaded from a file ending in .template.
func (t *Templates) IsTemplate(key string) bool {
	return t.isTemplate[key]
}

func (t *Templates) loadFrom(ctx context.Context, base vfs.Path) error {
	files, err := base.ReadTree(ctx)
	if err != nil {
		return fmt.Errorf("error reading from %s", base)
	}

	for _, f := range files {
		contents, err := f.ReadFile(ctx)
		if err != nil {
			if os.IsNotExist(err) {
				// This is just an annoyance of gobindata - we can't tell the difference between files & directories.  Ignore.
				continue
			}
			return fmt.Errorf("error reading %s: %v", f, err)
		}

		key, err := vfs.RelativePath(base, f)
		if err != nil {
			return fmt.Errorf("error getting relative path for %s", f)
		}

		isTemplate := strings.HasSuffix(key, ".template")
		key = strings.TrimSuffix(key, ".template")
		klog.V(6).Infof("loading resource %q", key)
		t.resources[key] = fi.NewBytesResource(contents)
		t.isTemplate[key] = isTemplate
	}
	return nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Re-run the command; intermittent storage/network failures often resolve
  2. Check read permissions on the named file in the VFS backend (IAM/ACLs)
  3. Re-sync or restore the missing/corrupt file in the template directory
  4. If from embedded assets, rebuild kops (make kops) to regenerate gobindata

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check readability of the tree entry
if _, err := f.ReadFile(ctx); err != nil && !os.IsNotExist(err) {
	klog.Warningf("file %s may be unreadable: %v", f, err)
}

Try / catch

contents, err := f.ReadFile(ctx)
if err != nil && !os.IsNotExist(err) {
	// retry transient errors before failing
	if isTransient(err) { return t.loadFrom(ctx, base) }
	return err
}

Prevention

When it happens

Trigger: f.ReadFile(ctx) on an entry from base.ReadTree fails with a permission, network, checksum, or partial-read error (anything other than IsNotExist).

Common situations: S3 object deleted between listing and read, IAM policy lacking GetObject on some objects, corrupted gobindata asset, or an intermittent storage/network failure during cluster spec rendering.

Related errors


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