kubernetes/kops · error
error parsing %v: %w
Error message
error parsing %v: %w
What it means
After reading the raw bytes of the cluster config, GetCluster decodes them into the kops API type via kopscodecs.Decode with the Cluster GVK. Decode failing means the bytes are not a valid Cluster manifest (corrupt YAML/JSON, wrong kind, wrong apiVersion), so the read data can't be turned into a *kops.Cluster.
Source
Thrown at cmd/kops-controller/pkg/controllerclientset/clientset.go:70
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.vfsContext
}
// CreateCluster creates a cluster
func (c *client) CreateCluster(ctx context.Context, cluster *kops.Cluster) (*kops.Cluster, error) {
return nil, fmt.Errorf("method CreateCluster not supported in server-side client")
}View on GitHub (pinned to 4c8573c808)
Solutions
- Validate the file at the printed path is well-formed YAML/JSON with kind: Cluster and correct apiVersion
- Restore the cluster config from version control/backup and re-check
- Round-trip the cluster via `kops get cluster -o yaml` and replace the corrupted file
- Re-run `kops update`/`kops toolbox` to regenerate a schema-compatible manifest
Example fix
// before (corrupt config file content) kind: Clustr // after apiVersion: kops.k8s.io/v1alpha2 kind: Cluster metadata: name: dev.example.com
Defensive patterns
Strategy: try-catch
Validate before calling
// validate the manifest decodes as Cluster before use
b, err := os.ReadFile(configPath)
if err == nil {
gvk := kops.SchemeGroupVersion.WithKind("Cluster")
if _, _, derr := kopscodecs.Decode(b, &gvk); derr != nil {
return fmt.Errorf("config at %s is not a valid Cluster manifest: %w", configPath, derr)
}
} Try / catch
cluster, err := clientset.GetCluster(ctx, name)
if err != nil {
if strings.Contains(err.Error(), "error parsing") {
// corrupt/incompatible manifest: restore from backup
return err
}
return err
} Prevention
- Never hand-edit cluster config without running `kops toolbox validate` afterwards
- Keep on-disk manifests at the kops apiVersion matching the binary
- Store cluster configs in version control so corrupt files are recoverable
When it happens
Trigger: kopscodecs.Decode(b, &gvk) returns err in GetCluster — typically triggered by a hand-edited or truncated config file, or a file of a different kind stored at the config path.
Common situations: Manual edits to the cluster config introducing invalid YAML/unknown fields; file overwritten with a wrong object (e.g. an InstanceGroup); schema changes from a kops upgrade leaving an incompatible on-disk format.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- parsing file %q: %v
- error marshaling yaml: %v
- failed to convert private networks to object: %w
- error unmarshaling subobject %s: %v
- error parsing addons or manifest: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/01450238a1e76cf3.
Report an issue: GitHub.