kubernetes/kops · error
reading file %v: %w
Error message
reading file %v: %w
What it means
GetCluster builds the path <clusterBasePath>/config and reads the cluster's serialized Cluster manifest; any read error (other than the name mismatch above) is wrapped as this message. The controller-side clientset is file-backed, so a missing or unreadable config file surfaces here.
Source
Thrown at cmd/kops-controller/pkg/controllerclientset/clientset.go:64
type client struct {
vfsContext *vfs.VFSContext
clusterBasePath vfs.Path
clusterName string
clusterKeystore fi.CAStore
clusterSecretStore fi.SecretStore
}
// GetCluster reads a cluster by name
func (c *client) GetCluster(ctx context.Context, name string) (*kops.Cluster, error) {
if name != c.clusterName {
return nil, fmt.Errorf("clientset bound to cluster %q, got cluster %q", c.clusterName, name)
}
p := c.clusterBasePath.Join("config")
b, err := p.ReadFile(ctx)
if err != nil {
return nil, fmt.Errorf("reading file %v: %w", p, err)
}
gvk := kops.SchemeGroupVersion.WithKind("Cluster")
object, _, err := kopscodecs.Decode(b, &gvk)
if err != nil {
return nil, fmt.Errorf("error parsing %v: %w", p, err)
}
cluster, ok := object.(*kops.Cluster)
if !ok {
return nil, fmt.Errorf("unexpected kind for cluster, got %T, want kops.Cluster", object)
}
return cluster, nil
}
// VFSContext returns a VFSContext.
func (c *client) VFSContext() *vfs.VFSContext {
return c.vfsContextView on GitHub (pinned to 4c8573c808)
Solutions
- Verify the cluster config file exists at the printed path (state store layout: <base>/cluster/config)
- Check permissions and volume mounts providing the state directory
- Confirm the cluster name and base path configuration (clusterBasePath) are correct
- Restore/recreate the cluster config if it was deleted
Defensive patterns
Strategy: validation
Validate before calling
// pre-check that the cluster config file exists
p := clusterBasePath.Join("config")
if _, err := os.Stat(string(p)); os.IsNotExist(err) {
return fmt.Errorf("cluster config missing at %s", p)
} Try / catch
cluster, err := clientset.GetCluster(ctx, name)
if err != nil {
if strings.Contains(err.Error(), "reading file") {
// path missing/unreadable: check state store config
return err
}
return err
} Prevention
- Verify state-store base path config before starting the controller
- Back up cluster config files; never hand-delete them
- Ensure state directory mounts survive pod rescheduling
When it happens
Trigger: p.ReadFile(ctx) fails in GetCluster — file absent, permission denied, or mount unavailable; invoked from RunGetAll/RunGetClusters via GetCluster.
Common situations: Wrong state-store/base path configuration so the cluster config file isn't where expected; cluster deleted or renamed; controller pod lost access to the mounted state directory.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- error reading cluster configuration: %v
- error reading addons file %s: %v
- error parsing %v: %w
- error loading NodeupConfig %q: %v
- error reading file %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7d737837eb557a39.
Report an issue: GitHub.