kubernetes/kops · error
error unmarshaling subobject %s: %v
Error message
error unmarshaling subobject %s: %v
What it means
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).
Source
Thrown at pkg/kubemanifest/manifest.go:244
v, found := current[field]
if !found {
return fmt.Errorf("field %q in %s not found", field, humanFields)
}
m, ok := v.(map[string]interface{})
if !ok {
return fmt.Errorf("field %q in %s was not an object, was %T", field, humanFields, v)
}
current = m
}
b, err := yaml.Marshal(current)
if err != nil {
return fmt.Errorf("error marshaling %s to yaml: %v", humanFields, err)
}
if err := yaml.Unmarshal(b, obj); err != nil {
return fmt.Errorf("error unmarshaling subobject %s: %v", humanFields, err)
}
return nil
}
// Set mutates a subfield to the newValue
func (m *Object) Set(newValue interface{}, fieldPath ...string) error {
humanFields := strings.Join(fieldPath, ".")
current := m.data
if len(fieldPath) >= 2 {
for _, field := range fieldPath[:len(fieldPath)-1] {
v, found := current[field]
if !found {
return fmt.Errorf("field %q in %s not found", field, humanFields)
}
m, ok := v.(map[string]interface{})View on GitHub (pinned to 4c8573c808)
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
Example fix
// before: type mismatch in manifest replicas: "3" // after replicas: 3
Defensive patterns
Strategy: try-catch
Validate before calling
b, _ := yaml.Marshal(subObj)
var probe map[string]interface{}
if err := yaml.Unmarshal(b, &probe); err != nil {
// subobject is not a valid mapping; fix manifest first
} Try / catch
var spec apiv1.PodSpec
if err := obj.Reparse(&spec, "spec"); err != nil {
return fmt.Errorf("manifest does not match PodSpec schema: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error marshaling %s to yaml: %v
- error parsing %v: %w
- parsing kops-channels manifest: %w
- failed to convert private networks to object: %w
- error reading cluster configuration %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/51d2982fc1f52dec.
Report an issue: GitHub.