What happened?
I am using the Crossplane project sturcture generating the go structs for the composed and composite
resources. The object retains the ManagedFields from the request and when set to the response via
mapAny, err := runtime.DefaultUnstructuredConverter.ToUnstructured(goStructOfComposite)
unstr := unstructured.Unstructured{Object: mapAny}
response.SetDesiredCompositeResource(rsp, &resource.Composite{Resource: &composite.Unstructured{Unstructured: unstr}}),
the metadata.managedFields populated by the API server survive into the SSA patch
body, and Kubernetes rejects it
Below is an analysis by Claude:
When a Go composition function round-trips the observed XR through a generated
struct and calls response.SetDesiredCompositeResource, the
metadata.managedFields populated by the API server survive into the SSA patch
body, and Kubernetes rejects it:
cannot apply composite resource status: metadata.managedFields must be nil
AsStruct() (L52–76)
copies the full observed XR backing map into the RunFunctionRequest proto
without stripping managedFields. Generated ObjectMeta structs include
ManagedFields *[]ManagedFieldsEntry, so the field survives the Go struct
round-trip and reaches the
SSA patch in composition_functions.go,
where Kubernetes rejects it.
crossplane render does not populate managedFields
in the observed XR proto, so render passes while the cluster fails.
Workaround: call unstr.SetManagedFields(nil) before SetDesiredCompositeResource.
Related: crossplane/crossplane#7453
What environment did it happen in?
Crossplane version: v2.3.2, v2.3.
What happened?
I am using the Crossplane project sturcture generating the go structs for the composed and composite
resources. The object retains the ManagedFields from the request and when set to the response via
the
metadata.managedFieldspopulated by the API server survive into the SSA patchbody, and Kubernetes rejects it
Below is an analysis by Claude:
When a Go composition function round-trips the observed XR through a generated
struct and calls
response.SetDesiredCompositeResource, themetadata.managedFieldspopulated by the API server survive into the SSA patchbody, and Kubernetes rejects it:
AsStruct()(L52–76)copies the full observed XR backing map into the
RunFunctionRequestprotowithout stripping
managedFields. Generated ObjectMeta structs includeManagedFields *[]ManagedFieldsEntry, so the field survives the Go structround-trip and reaches the
SSA patch in
composition_functions.go,where Kubernetes rejects it.
crossplane renderdoes not populatemanagedFieldsin the observed XR proto, so render passes while the cluster fails.
Workaround: call
unstr.SetManagedFields(nil)beforeSetDesiredCompositeResource.Related: crossplane/crossplane#7453
What environment did it happen in?
Crossplane version: v2.3.2, v2.3.