{"record":{"id":"01450238a1e76cf3","repo":"kubernetes/kops","slug":"error-parsing-v-w","errorCode":null,"errorMessage":"error parsing %v: %w","messagePattern":"error parsing (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops-controller/pkg/controllerclientset/clientset.go","lineNumber":70,"sourceCode":"\tclusterSecretStore fi.SecretStore\n}\n\n// GetCluster reads a cluster by name\nfunc (c *client) GetCluster(ctx context.Context, name string) (*kops.Cluster, error) {\n\tif name != c.clusterName {\n\t\treturn nil, fmt.Errorf(\"clientset bound to cluster %q, got cluster %q\", c.clusterName, name)\n\t}\n\n\tp := c.clusterBasePath.Join(\"config\")\n\tb, err := p.ReadFile(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading file %v: %w\", p, err)\n\t}\n\n\tgvk := kops.SchemeGroupVersion.WithKind(\"Cluster\")\n\tobject, _, err := kopscodecs.Decode(b, &gvk)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing %v: %w\", p, err)\n\t}\n\n\tcluster, ok := object.(*kops.Cluster)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected kind for cluster, got %T, want kops.Cluster\", object)\n\t}\n\treturn cluster, nil\n}\n\n// VFSContext returns a VFSContext.\nfunc (c *client) VFSContext() *vfs.VFSContext {\n\treturn c.vfsContext\n}\n\n// CreateCluster creates a cluster\nfunc (c *client) CreateCluster(ctx context.Context, cluster *kops.Cluster) (*kops.Cluster, error) {\n\treturn nil, fmt.Errorf(\"method CreateCluster not supported in server-side client\")\n}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops-controller/pkg/controllerclientset/clientset.go#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (corrupt config file content)\nkind: Clustr\n// after\napiVersion: kops.k8s.io/v1alpha2\nkind: Cluster\nmetadata:\n  name: dev.example.com","handlingStrategy":"try-catch","validationCode":"// validate the manifest decodes as Cluster before use\nb, err := os.ReadFile(configPath)\nif err == nil {\n\tgvk := kops.SchemeGroupVersion.WithKind(\"Cluster\")\n\tif _, _, derr := kopscodecs.Decode(b, &gvk); derr != nil {\n\t\treturn fmt.Errorf(\"config at %s is not a valid Cluster manifest: %w\", configPath, derr)\n\t}\n}","typeGuard":null,"tryCatchPattern":"cluster, err := clientset.GetCluster(ctx, name)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error parsing\") {\n\t\t// corrupt/incompatible manifest: restore from backup\n\t\treturn err\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["codec","deserialization","cluster-config","yaml"],"backgroundTag":"schema-validation-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}