@@ -39,7 +39,7 @@ import (
3939 "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
4040 notificationsprovisioner "github.com/argoproj-labs/argocd-operator/controllers/notificationsconfiguration"
4141 "github.com/argoproj-labs/argocd-operator/pkg/cacheutils"
42- wc "github.com/argoproj-labs/argocd-operator/pkg/clientwrapper"
42+ cw "github.com/argoproj-labs/argocd-operator/pkg/clientwrapper"
4343 appsv1 "github.com/openshift/api/apps/v1"
4444 configv1 "github.com/openshift/api/config/v1"
4545 console "github.com/openshift/api/console/v1"
@@ -152,7 +152,8 @@ func main() {
152152 TLSOpts : []func (* tls.Config ){disableHTTP2 },
153153 }
154154
155- mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
155+ // Set default manager options
156+ options := ctrl.Options {
156157 Scheme : scheme ,
157158 Metrics : metricsServerOptions ,
158159 WebhookServer : webhookServer ,
@@ -162,21 +163,38 @@ func main() {
162163 Controller : controllerconfig.Controller {
163164 SkipNameValidation : & skipControllerNameValidation ,
164165 },
165- Cache : cache.Options {
166+ }
167+
168+ // Use transformers to strip data from Secrets and ConfigMaps
169+ // that are not tracked by the operator to reduce memory usage.
170+ if strings .ToLower (os .Getenv ("MEMORY_OPTIMIZATION_ENABLED" )) != "false" {
171+ setupLog .Info ("memory optimization is enabled" )
172+ options .Cache = cache.Options {
166173 Scheme : scheme ,
167174 ByObject : map [crclient.Object ]cache.ByObject {
168- & corev1.Secret {}: {Transform : cacheutils .StripSecretDataTranform ()},
169- & corev1.ConfigMap {}: {Transform : cacheutils .StripConfigMapDataTransform ()},
175+ & corev1.Secret {}: {Transform : cacheutils .StripDataFromSecretOrConfigMapTransform ()},
176+ & corev1.ConfigMap {}: {Transform : cacheutils .StripDataFromSecretOrConfigMapTransform ()},
170177 },
171- },
172- })
178+ }
179+ }
180+
181+ mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), options )
173182 if err != nil {
174183 setupLog .Error (err , "unable to start manager" )
175184 os .Exit (1 )
176185 }
177186
178- liveClient , _ := crclient .New (ctrl .GetConfigOrDie (), crclient.Options {Scheme : mgr .GetScheme ()})
179- client := wc .NewClientWrapper (mgr .GetClient (), liveClient )
187+ var client crclient.Client
188+ if strings .ToLower (os .Getenv ("MEMORY_OPTIMIZATION_ENABLED" )) != "false" {
189+ liveClient , err := crclient .New (ctrl .GetConfigOrDie (), crclient.Options {Scheme : mgr .GetScheme ()})
190+ if err != nil {
191+ setupLog .Error (err , "unable to create live client" )
192+ os .Exit (1 )
193+ }
194+ client = cw .NewClientWrapper (mgr .GetClient (), liveClient )
195+ } else {
196+ client = mgr .GetClient ()
197+ }
180198
181199 registerComponentOrExit (mgr , console .AddToScheme )
182200 registerComponentOrExit (mgr , routev1 .AddToScheme ) // Adding the routev1 api
0 commit comments