Skip to content

Fix cache handling in IsNamespaced by resetting mapper#183

Merged
matteogastaldello merged 1 commit into
mainfrom
fix-invalid-cache-bug
Jun 10, 2026
Merged

Fix cache handling in IsNamespaced by resetting mapper#183
matteogastaldello merged 1 commit into
mainfrom
fix-invalid-cache-bug

Conversation

@matteogastaldello

Copy link
Copy Markdown
Collaborator

No description provided.

@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/tools/dynamic/dynamic.go 71.42% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@matteogastaldello matteogastaldello merged commit 4377879 into main Jun 10, 2026
12 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant