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

  1. Read the underlying yaml error to find the mismatched field and fix its type in the manifest
  2. Update the manifest so field types match the Go struct (e.g. quote numeric-looking strings)
  3. 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

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


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/51d2982fc1f52dec. Report an issue: GitHub.