-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ clustercache: add optional uncached client support for workload clusters #12803
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
base: main
Are you sure you want to change the base?
Conversation
@bnallapeta: The label(s) In response to this:
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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @bnallapeta! |
Hi @bnallapeta. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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-sigs/prow repository. |
/ok-to-test |
1eb12e4
to
66f5ea6
Compare
} | ||
} | ||
|
||
log.V(6).Info("Creating uncached client (finalized)") |
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.
WDYT about instead doing the following in l.101 (inside the if):
log.V(6).Info(fmt.Sprintf("Creating uncached client with updated REST config with host %q", restConfig.Host))
uncachedClient, err = createUncachedClient(ca.config.Scheme, restConfig, httpClient, mapper)
if err != nil {
return nil, errors.Wrapf(err, "error creating uncached client (using in-cluster config)")
}
+ moving newClientWithTimeout inside the createUncachedClient func?
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.
Makes sense. We use the same uncachedClient var throughout and avoids double-creation.
g.Expect(accessor.lockedState.healthChecking.lastProbeSuccessTime.IsZero()).To(BeFalse()) | ||
} | ||
|
||
func TestGetUncachedClientLifecycle(t *testing.T) { |
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.
Can we integrate this into TestConnect?
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.
Done.
// UncachedClientProvider provides live (uncached) access to the workload cluster API server. | ||
// This is an optional extension interface; callers can type assert a ClusterCache to this interface to retrieve an uncached client for a given workload cluster. | ||
type UncachedClientProvider interface { | ||
GetUncachedClient(ctx context.Context, cluster client.ObjectKey) (client.Client, error) |
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.
Let's add this to the existing ClusterCache
interface instead. I don't want to introduce a new interface for every new method that we're adding
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.
I considered this. But if we do this, then won't it be a breaking Go API change? Whoever has implemented/used ClusterCache has to adjust no? (including tests, backports). Additionally, if most people don't need uncached access, then the main interface feels bloated.
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.
I'm not aware of anyone using our interface but with a different implementation. If they do, they should consider using a subset of our interface. I don't want to make our implementation unnecessary complicated for that use case
Yes technically this is a breaking change, but I would prefer making changes like this from time to time over making our code unnecessary complicated. (both client-go and controller-runtime handle this the same way).
(Additional context, clustercache uses controller-runtime interfaces in its own interface, particularly the client interface is also not stable, so no breaking changes in general is not achievable)
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.
(The current implementation also means that we have to check if our ClusterCache also implements the other interface if we want to use the new func anywhere)
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.
Alright, I have included it in the existing ClusterCache
interface.
66f5ea6
to
a9c3cf3
Compare
Signed-off-by: Bharath Nallapeta <[email protected]>
a9c3cf3
to
6f2d5be
Compare
@bnallapeta: 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-sigs/prow repository. I understand the commands that are listed here. |
@sbueringer I believe all the comments are addressed. Please take a look and let me know if there's anything else. Thank you. |
How do we handle the pull-cluster-api-apidiff-main that is failing? I get that its failing due to a API breaking change. But I could not find any file in the codebase where we can make it happy. |
What this PR does / why we need it:
Adds GetUncachedClient method to the ClusterCache interface to support live (uncached) API calls to workload clusters. This helps reduce memory usage when you want to cache only a few types instead of having to exclude most types via DisableFor.
The uncached client is created alongside the cached one during connection setup and follows the same lifecycle (connect/disconnect).
Note: This introduces a breaking change to any existing implementations that are directly using ClusterCache.
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 #12784
/area controllers
/area clustercache