Skip to content

feat: Cache transform for Secrets and ConfigMaps to reduce memory#1866

Merged
svghadi merged 16 commits intoargoproj-labs:masterfrom
svghadi:mem-optmz
Nov 4, 2025
Merged

feat: Cache transform for Secrets and ConfigMaps to reduce memory#1866
svghadi merged 16 commits intoargoproj-labs:masterfrom
svghadi:mem-optmz

Conversation

@svghadi
Copy link
Copy Markdown
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
@svghadi svghadi marked this pull request as ready for review September 22, 2025 16:45
Comment thread pkg/cacheutils/utlis.go Outdated
Comment thread pkg/cacheutils/utlis.go Outdated
Comment thread pkg/cacheutils/utlis.go Outdated
Comment thread pkg/clientwrapper/client.go
Comment thread docs/usage/environment_variables.md Outdated
Comment thread cmd/main.go
Comment thread cmd/main.go Outdated
@anandrkskd anandrkskd requested a review from anandf October 30, 2025 14:46
Comment thread cmd/main.go Outdated
svghadi and others added 9 commits November 3, 2025 10:18
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Comment thread pkg/clientwrapper/client.go Outdated
Comment thread docs/usage/environment_variables.md Outdated
Comment thread pkg/cacheutils/utils.go Outdated
Comment thread pkg/clientwrapper/client.go Outdated
Comment thread pkg/clientwrapper/client.go Outdated
Comment thread pkg/clientwrapper/client.go Outdated
Comment thread pkg/clientwrapper/client_test.go
Comment thread pkg/clientwrapper/client.go
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Copy link
Copy Markdown
Collaborator

@anandf anandf left a comment

Choose a reason for hiding this comment

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

LGTM.

@svghadi svghadi merged commit 5d93ce3 into argoproj-labs:master Nov 4, 2025
7 checks passed
@svghadi svghadi deleted the mem-optmz branch November 4, 2025 09:55
mikeshng pushed a commit to mikeshng/argocd-operator that referenced this pull request Nov 4, 2025
…goproj-labs#1866)

* WIP

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Code clenup and commenting

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Add proposal doc

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* merge transform func, add tests for configmap and secret

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* add env var to disable optimization, update docs

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* fix CI lint failure

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* incorporate PR review

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* update IsTrackedByOperator func to take in runtime.Object

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* Fix minor issues

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Minor code comment updates

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Add unit test for client

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Fix linting

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Use positive notion for env

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Remove space and return patch error to caller

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Add unit test for patch error

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Move trackedby check out of referesh check func

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

---------

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Mike Ng <ming@redhat.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.

3 participants