{"record":{"id":"51d2982fc1f52dec","repo":"kubernetes/kops","slug":"error-unmarshaling-subobject-s-v","errorCode":null,"errorMessage":"error unmarshaling subobject %s: %v","messagePattern":"error unmarshaling subobject (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubemanifest/manifest.go","lineNumber":244,"sourceCode":"\t\tv, found := current[field]\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"field %q in %s not found\", field, humanFields)\n\t\t}\n\n\t\tm, ok := v.(map[string]interface{})\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"field %q in %s was not an object, was %T\", field, humanFields, v)\n\t\t}\n\t\tcurrent = m\n\t}\n\n\tb, err := yaml.Marshal(current)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshaling %s to yaml: %v\", humanFields, err)\n\t}\n\n\tif err := yaml.Unmarshal(b, obj); err != nil {\n\t\treturn fmt.Errorf(\"error unmarshaling subobject %s: %v\", humanFields, err)\n\t}\n\n\treturn nil\n}\n\n// Set mutates a subfield to the newValue\nfunc (m *Object) Set(newValue interface{}, fieldPath ...string) error {\n\thumanFields := strings.Join(fieldPath, \".\")\n\n\tcurrent := m.data\n\tif len(fieldPath) >= 2 {\n\t\tfor _, field := range fieldPath[:len(fieldPath)-1] {\n\t\t\tv, found := current[field]\n\t\t\tif !found {\n\t\t\t\treturn fmt.Errorf(\"field %q in %s not found\", field, humanFields)\n\t\t\t}\n\n\t\t\tm, ok := v.(map[string]interface{})","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubemanifest/manifest.go#L226-L262","documentation":"Object.Reparse in pkg/kubemanifest marshals the subobject at the given field path back to YAML and unmarshals it into the caller-supplied obj. This error fires when the resulting YAML does not fit the destination type, e.g. type mismatches between the generic manifest data and the struct fields (often wrapped by sigs.k8s.io/yaml conversions with strict typing).","triggerScenarios":"Calling Reparse with a destination struct whose field types conflict with the manifest data — e.g. a field is a string in the YAML but a int in the struct, or the subobject is actually a list where a map is expected.","commonSituations":"Cluster manifests edited by hand or by an older kOps version where a field's type changed (string vs numeric quantities), causing reparsing of spec containers/volumes into typed k8s API structs to fail.","solutions":["Read the underlying yaml error to find the mismatched field and fix its type in the manifest","Update the manifest so field types match the Go struct (e.g. quote numeric-looking strings)","Regenerate the manifest with a matching kOps version"],"exampleFix":"// before: type mismatch in manifest\nreplicas: \"3\"\n// after\nreplicas: 3","handlingStrategy":"try-catch","validationCode":"b, _ := yaml.Marshal(subObj)\nvar probe map[string]interface{}\nif err := yaml.Unmarshal(b, &probe); err != nil {\n    // subobject is not a valid mapping; fix manifest first\n}","typeGuard":null,"tryCatchPattern":"var spec apiv1.PodSpec\nif err := obj.Reparse(&spec, \"spec\"); err != nil {\n    return fmt.Errorf(\"manifest does not match PodSpec schema: %w\", err)\n}","preventionTips":["Keep manifest field types aligned with the Go struct definitions","Regenerate manifests with the kOps version matching your code","Validate manifests against the k8s OpenAPI schema before reparsing"],"tags":["go","yaml","deserialization","kubemanifest"],"backgroundTag":"yaml-unmarshal-type-mismatch","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"}