-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
⚠️ Accept options in remote.NewClusterCacheTracker #4693
⚠️ Accept options in remote.NewClusterCacheTracker #4693
Conversation
/cc @vincepri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/retitle
controllers/remote/cluster_cache.go
Outdated
type clusterCacheTrackerOptions struct { | ||
log logr.Logger | ||
clientDisableCacheFor []client.Object | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just export this instead of having variable functions?
type clusterCacheTrackerOptions struct { | |
log logr.Logger | |
clientDisableCacheFor []client.Object | |
} | |
type ClusterCacheTrackerOptions struct { | |
Logger logr.Logger | |
ClientDisableCacheFor []client.Object | |
} |
controllers/remote/cluster_cache.go
Outdated
|
||
func setDefaultOptions(opts *clusterCacheTrackerOptions) { | ||
if opts.log == nil { | ||
opts.log = ctrl.Log.WithName("remote").WithName("ClusterCacheTracker") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should NullLogger be the default here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Will change it
afdcf89
to
49cce11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Two nits, not blocking
exp/addons/controllers/suite_test.go
Outdated
@@ -38,7 +38,7 @@ func TestMain(m *testing.M) { | |||
fmt.Println("Creating new test environment") | |||
testEnv = helpers.NewTestEnvironment() | |||
|
|||
trckr, err := remote.NewClusterCacheTracker(log.NullLogger{}, testEnv.Manager) | |||
trckr, err := remote.NewClusterCacheTracker(testEnv.Manager, remote.SetLogger(log.NullLogger{})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trckr, err := remote.NewClusterCacheTracker(testEnv.Manager, remote.SetLogger(log.NullLogger{})) | |
trckr, err := remote.NewClusterCacheTracker(testEnv.Manager) |
Give it is already the default
controllers/remote/cluster_cache.go
Outdated
|
||
// SetClientDisableCacheFor allows to set the objects that should not be | ||
// cached by the client. | ||
func SetClientDisableCacheFor(objs []client.Object) Option { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
func SetClientDisableCacheFor(objs []client.Object) Option { | |
func SetClientDisableCacheFor(objs ...client.Object) Option { |
So the callers can simply do SetClientDisableCacheFor(Object1, Object2)
without creating an array/slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I suggested above to not use functions, but instead just expose the Options struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincepri Regarding the options argument, are you suggesting to change the function signature from
func NewClusterCacheTracker(manager ctrl.Manager, options ...Option) (*ClusterCacheTracker, error) {...}
to
func NewClusterCacheTracker(manager ctrl.Manager, options ClusterCacheTrackerOptions) (*ClusterCacheTracker, error) {...}
this will make options
a mandatory argument and I remember you suggesting to make it an optional one.
If we want to keep the options
argument as optional we will have to do
func NewClusterCacheTracker(manager ctrl.Manager, options ...ClusterCacheTrackerOptions) (*ClusterCacheTracker, error) {...}
and then perform merging of structs to construct the final options and this doesn't look like a pattern followed elsewhere in the project.
/kind release-blocking |
49cce11
to
03a862e
Compare
03a862e
to
002d323
Compare
controllers/remote/cluster_cache.go
Outdated
type ClusterCacheTrackerOptions struct { | ||
Log logr.Logger | ||
ClientDisableCacheFor []client.Object | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type ClusterCacheTrackerOptions struct { | |
Log logr.Logger | |
ClientDisableCacheFor []client.Object | |
} | |
type ClusterCacheTrackerOptions struct { | |
// Log is the logger used throughout the lifecycle of caches. | |
// Defaults to a no-op logger if it's not set. | |
Log logr.Logger | |
// ClientDisableCacheFor instructs the Client to never cache the following objects, | |
// it'll instead query the API server directly. | |
ClientDisableCacheFor []client.Object | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last comment, rest LGTM
002d323
to
d58e314
Compare
@vincepri addressed comments. |
/test pull-cluster-api-e2e-main |
controllers/remote/cluster_cache.go
Outdated
client client.Client | ||
scheme *runtime.Scheme | ||
log logr.Logger | ||
clientDisableCacheFor []client.Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be name this clientUncachedObjects
(or just uncachedObjects
since this is a field of ClusterCacheTracker
) to be consistent NewDelegatingClientInput
d58e314
to
1fe22fc
Compare
@ykakarap: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 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:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
This PR add an new optional
options
argument to theNewClusterCacheTracker
function.This new options argument can be used to control the objects that the client should not cache. Defaults to:
It can also be used to pass a desired logger. Defaults to
ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #4146