Skip to content

Conversation

@svghadi
Copy link
Collaborator

@svghadi svghadi commented Sep 11, 2025

What type of PR is this?
/kind enhancement

What does this PR do / why we need it:

This PR reduces memory usage in the Argo CD Operator by introducing a cache transform and client wrapper for Secrets and ConfigMaps.

  • Cache transform: Strips large data fields from non-operator Secrets/ConfigMaps before storing them in the controller-runtime cache, while retaining full content for operator-tracked objects.
  • Client wrapper: Falls back to the live client when a stripped object is accessed and applies a tracking label so future updates are fully cached.
  • Integration: Wired into main.go via cache.Options.ByObject and applied across reconcilers.

See the attached proposal in this PR for design details, trade-offs, PoC results, and future scope.

Results
These metrics were collected from a test cluster containing 100 ConfigMaps and 100 Secrets, each approximately 1 MB in size. The cluster was running four Argo CD instances and no other workload operators.

With the optimization enabled, operator memory usage dropped from ~350 MB to ~100 MB.

UnOptimized Operator Manager Memory:

unoptimized-manager-memory

Optimized Operator Manager Memory:

optimized-manager-memory

However, we could not reduce the startup memory consumption, which remained at ~750 MB in both cases.

We previously attempted another approach in #1795, but it introduced significant complexity and restricted how watches could be set up. Compared to that, this solution provides a better balance between complexity, maintenance overhead, and outcome.

@svghadi svghadi marked this pull request as draft September 11, 2025 07:25
@svghadi svghadi changed the title WIP feat: Cache transform for Secrets and ConfigMaps to reduce memory Sep 22, 2025
Signed-off-by: Siddhesh Ghadi <[email protected]>
Signed-off-by: Siddhesh Ghadi <[email protected]>
Signed-off-by: Siddhesh Ghadi <[email protected]>
@svghadi svghadi marked this pull request as ready for review September 22, 2025 16:45
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add some tests for the wrapper?

cmd/main.go Outdated
if watchedNsCache := getDefaultWatchedNamespacesCacheOptions(); watchedNsCache != nil {
// Use transformers to strip data from Secrets and ConfigMaps
// that are not tracked by the operator to reduce memory usage.
if strings.ToLower(os.Getenv("MEMORY_OPTIMIZATION_ENABLED")) != "false" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use DISABLE_MEMORY_OPTIMIZATION env var which users should explicitly set to true to disable optimization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@anandrkskd anandrkskd requested a review from anandf October 30, 2025 14:46
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.

3 participants