Skip to content

go composition function: observed XR managedFields leak into SSA status patch #182

Description

@olvesh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions