derailed/k9s · error

expected WorkloadRes but got %T

Error message

expected WorkloadRes but got %T

What it means

The Workload renderer expects a *WorkloadRes — an internal wrapper that bundles a metav1.TableRow plus container info for workload views (pods and their owning workloads). The assertion failed because the caller passed a bare metav1.TableRow, unstructured object, or other type. This is an internal contract violation between the workload view and its data assembler.

Source

Thrown at internal/render/workload.go:59

		status := strings.TrimSpace(re.Row.Fields[idx])
		if status == "DEGRADED" {
			c = model1.PendingColor
		}

		return c
	}
}

// Header returns a header rbw.
func (Workload) Header(string) model1.Header {
	return defaultWKHeader
}

// Render renders a K8s resource to screen.
func (Workload) Render(o any, _ string, r *model1.Row) error {
	res, ok := o.(*WorkloadRes)
	if !ok {
		return fmt.Errorf("expected WorkloadRes but got %T", o)
	}

	r.ID = fmt.Sprintf("%s|%s|%s", res.Row.Cells[0].(string), res.Row.Cells[1].(string), res.Row.Cells[2].(string))
	r.Fields = model1.Fields{
		res.Row.Cells[0].(string),
		res.Row.Cells[1].(string),
		res.Row.Cells[2].(string),
		res.Row.Cells[3].(string),
		res.Row.Cells[4].(string),
		res.Row.Cells[5].(string),
		ToAge(res.Row.Cells[6].(metav1.Time)),
	}

	return nil
}

type WorkloadRes struct {
	Row metav1.TableRow

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Construct the wrapper before rendering: res := &WorkloadRes{Row: row, Containers: specs} then pass res to Render.
  2. If you only have a table row, use the Table renderer instead of Workload.
  3. Guard the cell casts too: after the type check, Render indexes Cells[0..6] with hard .(string) casts, so rows with fewer/different cells will panic — ensure the producer always emits 7 cells in the expected order.

Example fix

// before
err := wk.Render(&metav1.TableRow{Cells: cells}, ns, r)

// after
err := wk.Render(&WorkloadRes{Row: metav1.TableRow{Cells: cells}}, ns, r)
Defensive patterns

Strategy: type-guard

Validate before calling

res, ok := o.(*WorkloadRes)
if !ok {
    return fmt.Errorf("workload renderer needs *WorkloadRes, got %T", o)
}
_ = res

Type guard

func asWorkloadRes(o any) (*WorkloadRes, bool) {
    res, ok := o.(*WorkloadRes)
    return res, ok
}

Try / catch

if err := wk.Render(obj, ns, r); err != nil {
    if strings.Contains(err.Error(), "expected WorkloadRes") {
    slog.Error("workload renderer misuse", "actualType", fmt.Sprintf("%T", obj))
    }
}

Prevention

When it happens

Trigger: Calling Workload.Render(o, _, r) with a raw *unstructured.Unstructured or metav1.TableRow instead of the WorkloadRes wrapper built by the workload view's data path. Happens when a custom viewer reuses the Workload renderer without constructing WorkloadRes{Row: ..., Containers: ...}.

Common situations: Custom viewers that borrow the workload header/render logic; refactoring that drops the wrapper and passes the inner row directly; tests calling Render with simplified fixtures.

Related errors


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