Skip to content

Commit 04dfd7d

Browse files
authored
Merge pull request #140 from snapp-incubator/fix/scope-secret-configmap-cache
fix: scope Secret/ConfigMap caches to user-argocd (cut memory)
2 parents 3eb9453 + 42ec30c commit 04dfd7d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

cmd/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ import (
2424
// to ensure that exec-entrypoint and run can make use of them.
2525
_ "k8s.io/client-go/plugin/pkg/client/auth"
2626

27+
corev1 "k8s.io/api/core/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2930
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3031
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/cache"
33+
"sigs.k8s.io/controller-runtime/pkg/client"
3134
"sigs.k8s.io/controller-runtime/pkg/healthz"
3235
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3336

@@ -75,6 +78,22 @@ func main() {
7578
HealthProbeBindAddress: probeAddr,
7679
LeaderElection: enableLeaderElection,
7780
LeaderElectionID: "e9600511.snappcloud.io",
81+
// Scope the Secret/ConfigMap informer caches to the user-argocd
82+
// namespace. The operator only ever reads the argocd static-user
83+
// ConfigMap and Secret there, but the default cache would watch every
84+
// Secret/ConfigMap cluster-wide (tens of thousands on large clusters),
85+
// blowing up cold-start memory and OOMKilling the manager. Restricting
86+
// these two types keeps memory bounded regardless of cluster size.
87+
Cache: cache.Options{
88+
ByObject: map[client.Object]cache.ByObject{
89+
&corev1.Secret{}: {
90+
Namespaces: map[string]cache.Config{"user-argocd": {}},
91+
},
92+
&corev1.ConfigMap{}: {
93+
Namespaces: map[string]cache.Config{"user-argocd": {}},
94+
},
95+
},
96+
},
7897
})
7998
if err != nil {
8099
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)