Skip to content

[v16] Refactor cache to support storing resources in memory#54820

Closed
rosstimothy wants to merge 1 commit intobranch/v16from
tross/backport-cache-collections/v16
Closed

[v16] Refactor cache to support storing resources in memory#54820
rosstimothy wants to merge 1 commit intobranch/v16from
tross/backport-cache-collections/v16

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

Backports #52210, #54637, and #54499 branch/v16

@rosstimothy rosstimothy added backport no-changelog Indicates that a PR does not require a changelog entry labels May 15, 2025
@rosstimothy rosstimothy force-pushed the tross/backport-cache-collections/v16 branch from 0f25e2f to d1375f3 Compare May 15, 2025 01:38
Base automatically changed from tross/backport-52414/v16 to branch/v16 May 15, 2025 11:40
@rosstimothy rosstimothy force-pushed the tross/backport-cache-collections/v16 branch from d1375f3 to 8283d26 Compare May 15, 2025 12:04
While the current cache storage is also in memory, it leverages
the memory backend which requires converting resources to and from
json. Marshaling json is suboptimal and is often a source of CPU
and memory consumption. The biggest problem with json marshaling
though is that it requires calling CheckAndSetDefaults. When
validations enforced in CASD become stricter it can leave caches
unable to become healthy when there are mixed versions within a
cluster as they all might have a slightly different view of what
should be allowed.

As a means to solve both problems, this changes the cache to store
resources received from the upstream directly in memory without
doing any conversion to json. There are two gotchas with this
approach, caching is no longer "free" and cloning of resources
must be done diligently to avoid races. Historically the cache
relied on the storage implementation in services/local to manage
persisting resources in the cache's backend.Memory. However, that
will no longer be the case as the cache needs to support storage
directly in memory. In order to reduce the burden this may pose on
developers the new collection machinery is simpler, and helpers
will be added on top of sortcache.SortCache to make a second
storage implementation trivial.

The changes here mark the existing collections machinery as legacy
and introduce new machinery to operate entirely in memory. The only
resources converted over are AccessRequests and HeadlessAuthentication.
@rosstimothy rosstimothy force-pushed the tross/backport-cache-collections/v16 branch from 8283d26 to 35a9788 Compare May 15, 2025 12:15
@rosstimothy rosstimothy marked this pull request as ready for review May 15, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport no-changelog Indicates that a PR does not require a changelog entry size/lg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants