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

⚠ Cache's ByObject is now a map Object -> options #2166

Merged
merged 1 commit into from Feb 2, 2023

Conversation

vincepri
Copy link
Member

@vincepri vincepri commented Feb 1, 2023

This is a breaking change and revisits some of the previous changes we've made. It brings the options ByObject to a top level map, which now contains all the options the internal informer can be configured with. In addition, it removes the ObjectAll object, which was super confusing and only used to disable the deep copy for every object; instead it's now possible to disable deep copy through a top level option.

Signed-off-by: Vince Prignano vincepri@redhat.com

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 1, 2023
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 1, 2023
@vincepri
Copy link
Member Author

vincepri commented Feb 1, 2023

/assign @alvaroaleman @sbueringer

pkg/cache/cache.go Outdated Show resolved Hide resolved
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

One nit

pkg/cache/cache.go Show resolved Hide resolved
// ByObject offers more fine-grained control over the cache's ListWatch by object.
type ByObject struct {
// Label represents a label selector for the object.
Label labels.Selector
Copy link
Contributor

Choose a reason for hiding this comment

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

Why separate Label and Field selectors here, but use one ObjectSelector type for the DefaultSelector field above?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was a suggestion by @alvaroaleman, I'm happy to do either way, although to reduce verbosity of the ByObject struct, might make sense to keep it this way

Copy link
Member

Choose a reason for hiding this comment

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

yeah IMHO this is easier to use when keeping them separate. I guess we could also do the same for the DefaultSelector

Copy link
Member Author

Choose a reason for hiding this comment

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

As in, separate DefaultLabelSelector and DefaultFieldSelector?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah

Copy link
Member Author

Choose a reason for hiding this comment

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

done, ptal

// [2] https://pkg.go.dev/k8s.io/apimachinery/pkg/fields#Set
Selectors SelectorsByObject
// ByObject offers more fine-grained control over the cache's ListWatch by object.
type ByObject struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is a little weird when it is used as cache.ByObject, should it be OptionsByObject?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can rename if we want to, the Struct is only used within the options, and was trying to reduce overall verbosity

Copy link
Member

Choose a reason for hiding this comment

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

Maybe ObjectOptions? But no strong opining either way

Copy link
Member Author

Choose a reason for hiding this comment

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

cache.Options{
  ByObject: map[client.Object]cache.ByObject{
    &corev1.Pod{}: {}
  }
}

IMO, this reads well and looks nice. @FillZpp if you feel that we should change it, happy to do it though

pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache_unit_test.go Outdated Show resolved Hide resolved
pkg/cache/cache_unit_test.go Outdated Show resolved Hide resolved
pkg/cache/cache_unit_test.go Outdated Show resolved Hide resolved
@vincepri vincepri force-pushed the rework-cache-sanity branch 6 times, most recently from 0cb8f51 to 6e7c24c Compare February 2, 2023 17:10
pkg/cache/cache_test.go Outdated Show resolved Hide resolved
This is a breaking change and revisits some of the previous changes
we've made. It brings the options ByObject to a top level map, which now
contains all the options the internal informer can be configured with.
In addition, it removes the ObjectAll object, which was super confusing
and only used to disable the deep copy for every object; instead it's
now possible to disable deep copy through a top level option.

Signed-off-by: Vince Prignano <vincepri@redhat.com>
@sbueringer
Copy link
Member

lgtm from my side

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 2, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, vincepri

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 [alvaroaleman,vincepri]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants