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

  1. Check the source object's YAML for the referenced field path
  2. Use only universally present fields (metadata.name, metadata.namespace) in fieldSelector templates
  3. 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

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


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