derailed/k9s · error
failed to process field selector template: %w
Error message
failed to process field selector template: %w
What it means
Same template pipeline as the label selector, but for the jump rule's fieldSelector: applyTemplate(rule.FieldSelector, sourceObj) failed while rendering. The cause (%w) is the template engine error, usually a missing field in the source object map.
Source
Thrown at internal/view/custom_jump.go:79
}
labelSel, labelErr = labels.Parse(labelStr)
if labelErr != nil {
return fmt.Errorf("invalid label selector: %w", labelErr)
}
}
// Set label selector if we have one
if labelSel != nil {
v.SetLabelSelector(labelSel, true)
}
// Build field selector if specified
var fieldSel string
if rule.FieldSelector != "" {
var fieldErr error
fieldSel, fieldErr = applyTemplate(rule.FieldSelector, sourceObj)
if fieldErr != nil {
return fmt.Errorf("failed to process field selector template: %w", fieldErr)
}
}
// Set up the context for the jump
v.SetContextFn(func(ctx context.Context) context.Context {
if fieldSel != "" {
ctx = context.WithValue(ctx, internal.KeyFields, fieldSel)
}
return ctx
})
// Jump to the target namespace if needed
if targetNS != "" && targetNS != client.NamespaceAll && targetNS != client.ClusterScope {
if err := app.Config.SetActiveNamespace(targetNS); err != nil {
slog.Error("Unable to set active namespace during custom jump", slogs.Error, err)
}
}
View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Check the source object's YAML for the referenced field path
- Use only universally present fields (metadata.name, metadata.namespace) in fieldSelector templates
- Drop the fieldSelector from the rule if it is not needed — it is optional
Example fix
// before
fieldSelector: "spec.nodeName={{ .spec.nodeName }}" // fails on objects without spec.nodeName
// after
fieldSelector: "metadata.namespace={{ .metadata.namespace }}" Defensive patterns
Strategy: validation
Validate before calling
// confirm every referenced field exists on a sample object
obj, _ := fetchResourceObject(app, sourceGVR, sourcePath)
if _, err := applyTemplate(rule.FieldSelector, obj); err != nil {
return fmt.Errorf("fieldSelector template references a missing field: %w", err)
} Prevention
- Use only metadata.name and metadata.namespace in field-selector templates — the only fields every object carries
- Verify field names against the API schema; CRD fields vary wildly between versions
- Omit fieldSelector entirely when not needed; it is optional
When it happens
Trigger: A rule like fieldSelector: "metadata.name={{ .metadata.name }}" where a referenced path (e.g. .spec.nodeName) does not exist on the fetched source object.
Common situations: Field selectors written for pods reused on other kinds; CRDs whose spec lacks the referenced field; objects created by older API versions without the field.
Related errors
- failed to process label selector template: %w
- invalid label selector: %w
- re.Description()
- no active context available
- custom column resolution error
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/bcd46a835c855eea.
Report an issue: GitHub.