derailed/k9s · error

expected Unstructured, but got %T

Error message

expected Unstructured, but got %T

What it means

PersistentVolumeClaim.Render follows the k9s renderer contract: the object must be *unstructured.Unstructured so defaultRow can populate base columns and p.specs.realize can apply custom columns from defaultPVCHeader against the raw JSON. The comma-ok assertion fails and returns this error (printing the concrete %T) when any other Go type is passed. It indicates the PVC renderer received a wrongly-typed payload — a wiring bug in the caller, not a cluster issue.

Source

Thrown at internal/render/pvc.go:43

	model1.HeaderColumn{Name: "VALID", Attrs: model1.Attrs{Wide: true}},
	model1.HeaderColumn{Name: "AGE", Attrs: model1.Attrs{Time: true}},
}

// PersistentVolumeClaim renders a K8s PersistentVolumeClaim to screen.
type PersistentVolumeClaim struct {
	Base
}

// Header returns a header row.
func (p PersistentVolumeClaim) Header(_ string) model1.Header {
	return p.doHeader(defaultPVCHeader)
}

// Render renders a K8s resource to screen.
func (p PersistentVolumeClaim) Render(o any, _ string, row *model1.Row) error {
	raw, ok := o.(*unstructured.Unstructured)
	if !ok {
		return fmt.Errorf("expected Unstructured, but got %T", o)
	}

	if err := p.defaultRow(raw, row); err != nil {
		return err
	}
	if p.specs.isEmpty() {
		return nil
	}

	cols, err := p.specs.realize(raw, defaultPVCHeader, row)
	cols.hydrateRow(row)

	return err
}

func (p PersistentVolumeClaim) defaultRow(raw *unstructured.Unstructured, r *model1.Row) error {
	var pvc v1.PersistentVolumeClaim
	err := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &pvc)

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Pass the informer-cached object untouched as *unstructured.Unstructured
  2. Convert typed objects with runtime.DefaultUnstructuredConverter.ToUnstructured and wrap in &unstructured.Unstructured{Object: m}
  3. Verify the view factory binds PersistentVolumeClaim only to the PVC GVR
  4. Guard custom call sites with a comma-ok check and skip the row on mismatch

Example fix

// before
typed := &v1.PersistentVolumeClaim{}
err := pvcRenderer.Render(typed, ns, row)
// after
m, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(typed)
err := pvcRenderer.Render(&unstructured.Unstructured{Object: m}, ns, row)
Defensive patterns

Strategy: type-guard

Validate before calling

// gate before invoking the PVC renderer
if _, ok := o.(*unstructured.Unstructured); !ok {
	return fmt.Errorf("pvc view requires *unstructured.Unstructured, got %T", o)
}
err := pvcRenderer.Render(o, ns, row)

Type guard

func isUnstructured(o any) bool {
	_, ok := o.(*unstructured.Unstructured)
	return ok
}

Try / catch

if err := pvcRenderer.Render(o, ns, row); err != nil {
	slog.Warn("pvc row skipped", "type", fmt.Sprintf("%T", o), slogs.Error, err)
	return nil // drop the row, keep the view alive
}

Prevention

When it happens

Trigger: Calling PersistentVolumeClaim{}.Render with typed *v1.PersistentVolumeClaim objects, map[string]any, a value unstructured.Unstructured, or synthetic row types; mapping the pvc renderer to a different GVR in a custom view factory; pre-converting informer objects to typed structs.

Common situations: Writing k9s plugins or custom views that register renderers per GVR; refactoring a view to feed typed client-go objects; unit tests with typed fixtures.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/87943e8533d7eebf. Report an issue: GitHub.