Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep copy by default #19

Merged
merged 2 commits into from
Apr 30, 2024
Merged

Deep copy by default #19

merged 2 commits into from
Apr 30, 2024

Conversation

JustinKuli
Copy link
Contributor

Not DeepCopying can save some resources in some situations, but is also a common way to introduce hard-to-find bugs, since items in the cache can then mutate unexpectedly. This library now follows the pattern from controller-runtime, which does a DeepCopy by default, which can be disabled with an option when creating the client.

The options passed to `NewObjectCache` were not actually being copied
into the returned object cache.

Signed-off-by: Justin Kulikauskas <[email protected]>
Copy link
Contributor

@dhaiducek dhaiducek left a comment

Choose a reason for hiding this comment

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

Minor comment on description wording

client/cache.go Outdated Show resolved Hide resolved
Not DeepCopying can save some resources in some situations, but is also
a common way to introduce hard-to-find bugs, since items in the cache
can then mutate unexpectedly. This library now follows the pattern from
controller-runtime, which does a DeepCopy by default, which can be
disabled with an option when creating the client.

Signed-off-by: Justin Kulikauskas <[email protected]>
@JustinKuli JustinKuli force-pushed the deep-copy-by-default branch from dfc2b14 to 2d95c84 Compare April 30, 2024 13:51
Copy link

Copy link
Contributor

@dhaiducek dhaiducek left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -87,6 +90,7 @@ func NewObjectCache(discoveryClient *discovery.DiscoveryClient, options ObjectCa
cache: &sync.Map{},
gvkToGVRCache: &sync.Map{},
discoveryClient: discoveryClient,
options: options,
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Was this just missed (or unnecessary) previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was just missed. The other options aren't tested (and I think that's ok; they'd be annoying to test for a low payoff).

Copy link

openshift-ci bot commented Apr 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhaiducek, JustinKuli

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JustinKuli,dhaiducek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 3400f94 into main Apr 30, 2024
5 checks passed
@openshift-merge-bot openshift-merge-bot bot deleted the deep-copy-by-default branch April 30, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants