Skip to content

Commit 64a2c55

Browse files
committed
Only cache objects managed by operator
Configure controller-runtime cache to only cache objects that have the commonly used labels set by the operator. With that the operator will build up a cache for only the resources it manages. Normally controller-runtime would build up a cache for all resources the client interacts with. This is especially a problem for large cluster as then the operator would cache all Deployments and DaemonSets, which would then drastically increase memory usage. With this change we can keep memory usage relatively small and also stable regardless the size of the cluster Signed-off-by: Benjamin Isinger <[email protected]>
1 parent a00d372 commit 64a2c55

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ import (
2323

2424
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2525
// to ensure that exec-entrypoint and run can make use of them.
26+
"k8s.io/apimachinery/pkg/labels"
2627
"k8s.io/apimachinery/pkg/runtime"
2728
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2829
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2930
_ "k8s.io/client-go/plugin/pkg/client/auth"
3031
"k8s.io/client-go/rest"
3132
ctrl "sigs.k8s.io/controller-runtime"
33+
"sigs.k8s.io/controller-runtime/pkg/cache"
3234
"sigs.k8s.io/controller-runtime/pkg/healthz"
3335
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3436
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3537

3638
objectdriverv1alpha1 "github.com/IBM/ibm-object-csi-driver-operator/api/v1alpha1"
3739
"github.com/IBM/ibm-object-csi-driver-operator/controllers"
40+
"github.com/IBM/ibm-object-csi-driver-operator/controllers/constants"
3841
"github.com/IBM/ibm-object-csi-driver-operator/controllers/util/common"
3942
//+kubebuilder:scaffold:imports
4043
)
@@ -75,6 +78,9 @@ func main() {
7578
HealthProbeBindAddress: probeAddr,
7679
LeaderElection: enableLeaderElection,
7780
LeaderElectionID: "af88e983.csi.ibm.com",
81+
Cache: cache.Options{
82+
DefaultLabelSelector: labels.SelectorFromSet(constants.CommonCSIResourceLabels),
83+
},
7884

7985
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
8086
// when the Manager ends. This requires the binary to immediately end when the

0 commit comments

Comments
 (0)