derailed/k9s · warning

invalid resource name: %q

Error message

invalid resource name: %q

What it means

The alias resolver (built from cluster discovery and user alias config) could not map the xray argument to a GVR. The token is not a known resource short name, full name, or configured alias, so there is nothing to x-ray.

Source

Thrown at internal/view/command.go:156

	filter, _ := p.FilterArg()

	v := NewAlias(client.AliGVR)
	v.SetFilter(filter, true)

	return c.exec(p, client.AliGVR, v, false, pushCmd)
}

func (c *Command) xrayCmd(p *cmd.Interpreter, pushCmd bool) error {
	arg, cns, ok := p.XrayArgs()
	if !ok {
		return errors.New("invalid command. use `xray xxx`")
	}
	if c.alias == nil {
		return fmt.Errorf("no connection available")
	}
	gvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg))
	if !ok {
		return fmt.Errorf("invalid resource name: %q", arg)
	}
	if !allowedXRay(gvr) {
		return fmt.Errorf("unsupported resource %q", arg)
	}
	ns := c.app.Config.ActiveNamespace()
	if cns != "" {
		ns = cns
	}
	if err := c.app.Config.SetActiveNamespace(client.CleanseNamespace(ns)); err != nil {
		return err
	}
	if err := c.app.switchNS(ns); err != nil {
		return err
	}

	return c.exec(p, client.XGVR, NewXray(gvr), true, pushCmd)
}

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Use a canonical short name: xray po, xray svc, xray dp, xray ds, xray sts, xray rs.
  2. List what resolves: check your aliases (alias command / config aliases section) and kubectl api-resources for installed types.
  3. Reconnect/restart so discovery refreshes if the CRD was just installed.
  4. Fix typos; note some resources are named differently across API groups.

Example fix

# before
:xray deploymnt

# after
:xray dp
Defensive patterns

Strategy: validation

Validate before calling

if c.alias == nil { return fmt.Errorf("no connection available") }
gvr, ok := c.alias.Resolve(cmd.NewInterpreter(arg))
if !ok {
    return fmt.Errorf("unknown resource %q — try po, svc, dp, ds, sts, rs; list types via kubectl api-resources", arg)
}

Try / catch

if err := c.xrayCmd(p, push); err != nil {
    if strings.Contains(err.Error(), "invalid resource name") {
    suggestCanonicalNames(arg)
    }
}

Prevention

When it happens

Trigger: Running `xray deploymnt` (typo), `xray mycustomthing` where the CRD is not installed, or a resource name valid on another cluster but absent here because the RESTMapper/discovery data differs.

Common situations: Typos and wrong short-names; CRDs not yet installed or discovery cache stale after installing a CRD; per-cluster alias differences; aliases defined in config for one cluster only.

Related errors


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