Skip to content

Commit 65ea9f1

Browse files
committed
rebase and add environment variable to enable or disable optimization
Signed-off-by: Anand Kumar Singh <[email protected]>
1 parent 89ed503 commit 65ea9f1

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

cmd/main.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21j
2929
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
3030
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
3131
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
32+
<<<<<<< HEAD
3233
github.com/argoproj-labs/argo-rollouts-manager v0.0.7-0.20251029155400-4619e3168941 h1:uqkUVemiOX050ktlgbyYs4jef38HRU17C9sTzHTL9JU=
3334
github.com/argoproj-labs/argo-rollouts-manager v0.0.7-0.20251029155400-4619e3168941/go.mod h1:WPyZkNHZjir/OTt8mrRwcUZKe1euHrHPJsRv1Wp/F/0=
35+
=======
36+
github.com/argoproj-labs/argo-rollouts-manager v0.0.6-0.20250731075119-a100fc1d88b8 h1:6+eo7BKrNkSIhQ1nnyCUloSNrGzghlb8r8e7GokoeBo=
37+
github.com/argoproj-labs/argo-rollouts-manager v0.0.6-0.20250731075119-a100fc1d88b8/go.mod h1:yTwzKUV79YyI764hkXdVojGYBA9yKJk3qXx5mRuQ2Xc=
38+
>>>>>>> d1d88a79 (rebase and add environment variable to enable or disable optimization)
3439
github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251105033011-e979a3f5f471 h1:MGK8MTUgfRn3nfhXnw0K/RUPNrl5JZlFsBQugD9VAzU=
3540
github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251105033011-e979a3f5f471/go.mod h1:ABtgKWsvMlUp6Xys8BVi0CHKdT9ZoFP+rYCqRsY0wvg=
3641
github.com/argoproj/argo-cd/v3 v3.1.8 h1:NkLPiRI5qGkV+q1EN3O7/0Wb9O/MVl62vadKteZqMUw=

0 commit comments

Comments
 (0)