kcp icon indicating copy to clipboard operation
kcp copied to clipboard

Remove live-client fallback from local Secret lookup in serviceaccount cache

Open mjudeikis-bot opened this issue 1 month ago • 2 comments

What exists today

In pkg/server/serviceaccount/cache.go (Cache.Cluster, around lines 175-185 on the head of #4528), the local lookup func for Secrets was changed from a plain lister read to:

secret, err := secretsLister.Secrets(namespace).Get(name)
if !kerrors.IsNotFound(err) {
	return secret, err
}
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
return kubeShardClient.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{})

So every lister miss on the local path now triggers a live GET against the shard. This is a hot path: any token/secret lookup for a missing secret (e.g. repeated requests with a stale or bogus token reference) turns into a request per call. Per the review discussion, the fetch function passed to shardlookup.NewLookup already handles falling back to the remote shard, so this fallback in the local func is redundant.

What should replace it

Restore the local func to a plain lister read (return secretsLister.Secrets(namespace).Get(name)) and rely on the existing fetch fallback in shardlookup.Lookup. If the Secret informer filtering in #4528 means some secrets are intentionally absent from the informer, handle that through the fetch path rather than the local func.

Context

  • PR: https://github.com/kcp-dev/kcp/pull/4528
  • Requesting comment: https://github.com/kcp-dev/kcp/pull/4528#discussion_r4454635024 (follow-up to https://github.com/kcp-dev/kcp/pull/4528#discussion_r4454611265)

Steps

  • [ ] Revert the local Secret getter in pkg/server/serviceaccount/cache.go to a lister-only read
  • [ ] Confirm shardlookup.Lookup falls back to fetch for secrets not in the informer, and that it is not hot-pathed on repeated misses
  • [ ] Add or adjust a unit/e2e test covering a Secret missing from the local informer

mjudeikis-bot avatar Nov 03 '26 12:11 mjudeikis-bot

@mjudeikis-bot The PR has been merged, fix this issue.

ntnn avatar Nov 03 '26 13:11 ntnn

Opened https://github.com/kcp-dev/kcp/pull/4542. Note that shardlookup.Lookup does not fall back to fetch for local misses, so a local Secret missing from the informer now returns NotFound. Details are in the PR.

mjudeikis-bot avatar Nov 03 '26 13:11 mjudeikis-bot