kubernetes/kops · error
error building annotation patch: %v
Error message
error building annotation patch: %v
What it means
SetInstalledVersion builds a JSON strategic-merge patch containing only the annotations map, then applies it to the namespace. This error is thrown if json.Marshal of the in-memory annotationPatch struct fails. Since the struct is simple (map[string]string), this is rare and typically indicates an unexpected serialization problem.
Source
Thrown at channels/pkg/channels/channel_version.go:202
Annotations map[string]string `json:"annotations,omitempty"`
}
func (c *Channel) SetInstalledVersion(ctx context.Context, k8sClient kubernetes.Interface, version *ChannelVersion) error {
// Primarily to check it exists
_, err := k8sClient.CoreV1().Namespaces().Get(ctx, c.Namespace, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("error querying namespace %q: %v", c.Namespace, err)
}
value, err := version.Encode()
if err != nil {
return err
}
annotationPatch := &annotationPatch{Metadata: annotationPatchMetadata{Annotations: map[string]string{c.AnnotationName(): value}}}
annotationPatchJSON, err := json.Marshal(annotationPatch)
if err != nil {
return fmt.Errorf("error building annotation patch: %v", err)
}
klog.V(2).Infof("sending patch: %q", string(annotationPatchJSON))
_, err = k8sClient.CoreV1().Namespaces().Patch(ctx, c.Namespace, types.StrategicMergePatchType, annotationPatchJSON, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("error applying annotation to namespace: %v", err)
}
return nil
}
View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped %v marshal error to identify the cause.
- Verify the annotation value produced by version.Encode() is a plain string (no invalid content).
- Upgrade/patch the library if a serialization bug is confirmed.
- Report with the full wrapped error if reproducible.
Defensive patterns
Strategy: try-catch
Try / catch
if err := ch.SetInstalledVersion(ctx, k8sClient, version); err != nil {
if strings.Contains(err.Error(), "error building annotation patch") {
return fmt.Errorf("patch construction bug: %w", err)
}
return err
} Prevention
- Keep channel version payloads as plain strings.
- Test version.Encode() output in unit tests.
- Report serialization failures upstream with full error text.
When it happens
Trigger: json.Marshal failing on the annotationPatch struct during SetInstalledVersion — practically only due to a programming-level issue, since the payload contains only strings.
Common situations: Rarely hit in practice; would surface as a bug in the patch construction code rather than a cluster/environment issue.
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
- building node patch: %w
- error building node patch: %v
- marshaling to json for %v: %w
- error marshaling into JSON: %v
- error patching needs-update label: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/8409f97c98542193.
Report an issue: GitHub.