Fix cache handling in IsNamespaced by resetting mapper#183
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
braghettos
added a commit
to braghettos/krateo-composition-dynamic-controller
that referenced
this pull request
Jun 18, 2026
…events (#2) * fix(dynamic): invalidate discovery cache on CustomResourceDefinition events The RESTMapper is a DeferredDiscoveryRESTMapper backed by a MemCache discovery client, built once at startup and never refreshed. CRDs (or new CRD versions) registered after the cache warms are therefore invisible to RESTMapping/IsNamespaced — and, for the installer umbrella, to the `inst.crdExists` Pass-B gate — until the controller is restarted. This is the stale-CRD-discovery-cache class that forces a manual cdc restart on every umbrella version bump / component CRD roll. Add WatchCRDsAndInvalidate: a dynamic informer on CustomResourceDefinition that calls mapper.Reset() on add/update/delete (debounced/coalesced, and skipping resync no-ops). Reset() invalidates the MemCache and drops the delegate, so the next lookup re-discovers from the live cluster — no restart needed. Wired into main after the mapper is built; non-fatal so the controller still runs (IsNamespaced keeps its reactive reset). Complements krateoplatformops#183 (reactive Reset on IsNamespaced miss) with a proactive refresh that also covers the render-time crdExists lookup. Note: the cdc ServiceAccount needs get;list;watch on customresourcedefinitions.apiextensions.k8s.io (already required for the crdExists lookup). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * review: surface CRD-watch sync failure (RBAC) + clarify coalescing window Self-review follow-ups: - WaitForCacheSync + log so a missing/denied CRD watch (RBAC) is visible instead of silently degrading to the reactive-only reset. - Add a startup Info log confirming the watch is active. - Rename crdInvalidateDebounce -> crdInvalidateWindow and correct the comment: it is a fixed coalescing window from the first event (a throttle that bounds staleness), not an extending debounce. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.