kubernetes/kops · error

unexpected object type: %T

Error message

unexpected object type: %T

What it means

kopscodecs.Decode returns a runtime.Object; the command asserts it is specifically a *kopsapi.InstanceGroup. If the user changed `kind` in the editor (or the decoder produced a different type), the type assertion fails and kOps reports the actual Go type with %T so the user can see what was decoded instead.

Source

Thrown at cmd/kops/create_instancegroup.go:282

		// launch the editor
		edited, file, err := edit.LaunchTempFile(fmt.Sprintf("%s-edit-", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw))
		defer func() {
			if file != "" {
				try.RemoveFile(file)
			}
		}()
		if err != nil {
			return fmt.Errorf("error launching editor: %v", err)
		}

		obj, _, err := kopscodecs.Decode(edited, nil)
		if err != nil {
			return fmt.Errorf("error parsing yaml: %v", err)
		}
		group, ok := obj.(*kopsapi.InstanceGroup)
		if !ok {
			return fmt.Errorf("unexpected object type: %T", obj)
		}

		err = validation.CrossValidateInstanceGroup(group, cluster, cloud, true).ToAggregate()
		if err != nil {
			return err
		}

		ig = group
	}

	_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})
	if err != nil {
		return fmt.Errorf("error storing InstanceGroup: %v", err)
	}

	return nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Restore `kind: InstanceGroup` (exact case) and the correct apiVersion (kops.k8s.io/v1alpha2 or current) in the edited YAML
  2. Do not paste other object types into the editor; edit only spec fields
  3. Re-run with --edit=false if editing is not needed
  4. Check the %T in the error to see which type was actually decoded and correct the manifest accordingly

Example fix

// before
kind: Cluster
metadata:
  name: nodes
// after
kind: InstanceGroup
metadata:
  name: nodes
Defensive patterns

Strategy: type-guard

Validate before calling

# ensure kind is untouched before saving
head -n 5 ig.yaml  # confirm 'kind: InstanceGroup' is present and unmodified

Type guard

group, ok := obj.(*kopsapi.InstanceGroup)
if !ok { return fmt.Errorf("unexpected object type: %T", obj) }

Try / catch

if err != nil && strings.Contains(err.Error(), "unexpected object type") {
	// re-edit and restore kind: InstanceGroup with correct apiVersion
}

Prevention

When it happens

Trigger: Editing the YAML and changing `kind: InstanceGroup` to another kind (e.g. Cluster, ClusterConfiguration, or a typo like Instancegroup), causing the codec to decode into a different registered type.

Common situations: Hand-editing kind/apiVersion fields; pasting a different kops object into the editor buffer; case mistakes in the kind name; using an apiVersion/group that maps to another type.

Related errors


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