Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/controllers/clusterresourceplacement/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ func (r *Reconciler) shouldSelectResource(gvr schema.GroupVersionResource) bool

// generateRawContent strips all the unnecessary fields to prepare the objects for dispatch.
func generateRawContent(object *unstructured.Unstructured) ([]byte, error) {
// Make a deep copy of the object as we are modifying it.
object = object.DeepCopy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who else is read/write it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The informer. I put the story in the PR description.

Copy link
Contributor

@ryanzhang-oss ryanzhang-oss May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the go-client informer returns a deep copy of the object so there is no race condition between those.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The informer lister lists resources from the indexer, which is backed by the underlying threadsafestore. Reading the doc: https://pkg.go.dev/k8s.io/client-go/tools/cache#ThreadSafeStore, "TL;DR caveats: you must not modify anything returned by Get or List as it will break the indexing feature in addition to not being thread safe." It's required to keep the objects r/o. I don't see a deep copy as I dig the code path.

// we keep the annotation/label/finalizer/owner references/delete grace period
object.SetResourceVersion("")
object.SetGeneration(0)
Expand Down
Loading