Skip to content

SSA status patch applies the whole primary resource, so the controller co-owns metadata and spec on Kubernetes <= 1.35 #3721

Done

Description

@afalhambra-hivemq

UpdateControl.patchStatus(resource) and ErrorStatusUpdateControl.patchStatus(resource) with useSSAToPatchPrimaryResource send the given object as the server-side apply body of the status subresource (CustomResourceFacade.patchStatus only nulls managedFields). Most reconcilers pass the reconciled primary resource, as the WebPage sample does in WebPageReconciler#reconcile for the invalid HTML case, so the body carries labels, annotations, finalizers and the spec.

Up to Kubernetes 1.35 the API server discards everything but status on that subresource, yet records the controller's field manager (subresource status) as owner of every field in the body. Kubernetes 1.36 fixed the ownership tracking (kubernetes/kubernetes#137689 adds metadata to the reset fields of the custom resource status strategy), without backports. 1.35 is supported until February 2027.

Effect: any other server-side applier that changes a co-owned field conflicts with the controller. Real case, a Helm 4 chart upgrade of a custom resource managed by a JOSDK 5.6.4 operator:

Error: UPGRADE FAILED: ... Apply failed with 2 conflicts: conflicts with "hivemq-controller" with subresource "status":
- .metadata.labels.app.kubernetes.io/version
- .metadata.labels.helm.sh/chart

The managedFields entry for the controller with subresource: status listed f:metadata and f:spec next to f:status.

Proposal: in the SSA path of CustomResourceFacade.patchStatus, apply a fresh instance that carries only apiVersion, kind, metadata.name, metadata.namespace, metadata.resourceVersion when set (keeps optimistic locking opt-in) and the status, the same way ResourceOperations.finalizerApplyFor already builds the finalizer body. Verified on a 1.35.0 API server: the first apply with the reduced body shrinks the existing entry to f:status, labels stay on the resource, the Helm upgrade applies. The custom resource status strategy has replaced everything but status with the stored object since v1.16, so the trimmed body changes nothing on any server version except the ownership tracking. If trimming for every HasMetadata is a concern because of the grandfathered built-in types that may change metadata through status, scope it to CustomResource or make it configurable. At minimum, the UpdateControl.patchStatus Javadoc (still "Uses JSON Patch") and the docs should tell users to pass a fresh resource with only name, namespace and status.

Workaround today: build that resource in the reconciler.

Happy to open a PR for this if you agree with the approach.

Activity

  1. csviri commented on Nov 23, 2026

    @csviri
    Collaborator

    @afalhambra-hivemq thank you, go for it pls create the pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions