derailed/k9s · error

expected Unstructured, but got %T

Error message

expected Unstructured, but got %T

What it means

PersistentVolume.Render follows the k9s renderer contract: cluster objects must arrive as *unstructured.Unstructured so defaultRow can fill base columns and the custom-column engine (p.specs.realize against defaultPVHeader) can walk the raw JSON. The comma-ok assertion on the any-typed parameter fails and returns this error with the concrete %T when any other Go type reaches the renderer. It signals a wiring bug — the wrong payload type was delivered to the PV renderer — not a cluster problem.

Source

Thrown at internal/render/pv.go:74

	model1.HeaderColumn{Name: "NAME"},
	model1.HeaderColumn{Name: "CAPACITY", Attrs: model1.Attrs{Capacity: true}},
	model1.HeaderColumn{Name: "ACCESS MODES"},
	model1.HeaderColumn{Name: "RECLAIM POLICY"},
	model1.HeaderColumn{Name: "STATUS"},
	model1.HeaderColumn{Name: "CLAIM"},
	model1.HeaderColumn{Name: "STORAGECLASS"},
	model1.HeaderColumn{Name: "REASON"},
	model1.HeaderColumn{Name: "VOLUMEMODE", Attrs: model1.Attrs{Wide: true}},
	model1.HeaderColumn{Name: "LABELS", Attrs: model1.Attrs{Wide: true}},
	model1.HeaderColumn{Name: "VALID", Attrs: model1.Attrs{Wide: true}},
	model1.HeaderColumn{Name: "AGE", Attrs: model1.Attrs{Time: true}},
}

// Render renders a K8s resource to screen.
func (p PersistentVolume) 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, defaultPVHeader, row)
	cols.hydrateRow(row)

	return err
}

func (p PersistentVolume) defaultRow(raw *unstructured.Unstructured, r *model1.Row) error {
	var pv v1.PersistentVolume
	err := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &pv)
	if err != nil {
		return err

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

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

Example fix

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

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

if err := pvRenderer.Render(o, ns, row); err != nil {
	slog.Warn("pv 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 PersistentVolume{}.Render with a typed *v1.PersistentVolume, a map[string]any, a value unstructured.Unstructured (the assertion is on the pointer), or a synthetic row type; binding the pv renderer to another GVR in a custom view; pre-converting informer objects to typed structs before rendering.

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; reusing the PV renderer for a volume-like CRD.

Related errors


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