kubernetes/kops · error
error building node patch: %v
Error message
error building node patch: %v
What it means
patchNodeLabels marshals a strategic-merge patch (labels map with null for deletions) to JSON before sending it; this wraps json.Marshal failing. The patch structure is built from simple label maps, so a failure here signals an internal bug rather than bad input.
Source
Thrown at cmd/kops-controller/controllers/node_controller.go:161
// patchNodeLabels patches the node labels to set the specified labels
func patchNodeLabels(client *corev1client.CoreV1Client, ctx context.Context, node *corev1.Node, setLabels map[string]string, deleteLabels map[string]struct{}) error {
nodePatchMetadata := &nodePatchMetadata{
Labels: make(map[string]*string),
}
for k, v := range setLabels {
v := v
nodePatchMetadata.Labels[k] = &v
}
for k := range deleteLabels {
nodePatchMetadata.Labels[k] = nil
}
nodePatch := &nodePatch{
Metadata: nodePatchMetadata,
}
nodePatchJson, err := json.Marshal(nodePatch)
if err != nil {
return fmt.Errorf("error building node patch: %v", err)
}
klog.V(2).Infof("sending patch for node %q: %q", node.Name, string(nodePatchJson))
_, err = client.Nodes().Patch(ctx, node.Name, types.StrategicMergePatchType, nodePatchJson, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("error applying patch to node: %v", err)
}
return nil
}
View on GitHub (pinned to 4c8573c808)
Solutions
- Read the wrapped %v error to see the offending field/type
- Remove or fix the unmarshalable field in the nodePatch struct
- Verify all fields have JSON-compatible types and tags
Example fix
// before
Patch Metadata map[string]interface{} `json:"metadata"` // may hold funcs
// after
Patch Metadata *nodePatchMetadata `json:"metadata,omitempty"` Defensive patterns
Strategy: validation
Validate before calling
if _, err := json.Marshal(nodePatch); err != nil {
return fmt.Errorf("error building node patch: %v", err)
}
Prevention
- Keep nodePatch fields JSON-serializable with explicit json tags
- Add a unit test marshalling nodePatch
- Avoid interface{} fields that can hold funcs/channels
When it happens
Trigger: json.Marshal(nodePatch) returns an error — practically only if the patch struct contains an unsupported value (e.g. a channel, func, or unmarshalable type added to nodePatch).
Common situations: Extremely rare with the stock struct; would appear if a contributor added a field with a non-serializable type or a bad custom MarshalJSON.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- error building annotation patch: %v
- building node patch: %w
- marshaling to json for %v: %w
- error marshaling into JSON: %v
- error parsing version spec %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/09c786e5053afb93.
Report an issue: GitHub.