@@ -25,22 +25,26 @@ import (
2525 prommetrics "github.com/slok/go-http-metrics/metrics/prometheus"
2626 "github.com/slok/go-http-metrics/middleware"
2727 flag "github.com/spf13/pflag"
28+ corev1 "k8s.io/api/core/v1"
2829 "k8s.io/apimachinery/pkg/runtime"
2930 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3031 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3132 ctrl "sigs.k8s.io/controller-runtime"
33+ ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3234 crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
3335
3436 "github.com/fluxcd/pkg/runtime/acl"
3537 "github.com/fluxcd/pkg/runtime/client"
3638 helper "github.com/fluxcd/pkg/runtime/controller"
39+ feathelper "github.com/fluxcd/pkg/runtime/features"
3740 "github.com/fluxcd/pkg/runtime/leaderelection"
3841 "github.com/fluxcd/pkg/runtime/logger"
3942 "github.com/fluxcd/pkg/runtime/pprof"
4043 "github.com/fluxcd/pkg/runtime/probes"
4144
4245 apiv1 "github.com/fluxcd/notification-controller/api/v1beta2"
4346 "github.com/fluxcd/notification-controller/controllers"
47+ "github.com/fluxcd/notification-controller/internal/features"
4448 "github.com/fluxcd/notification-controller/internal/server"
4549 // +kubebuilder:scaffold:imports
4650)
@@ -73,6 +77,7 @@ func main() {
7377 leaderElectionOptions leaderelection.Options
7478 aclOptions acl.Options
7579 rateLimiterOptions helper.RateLimiterOptions
80+ featureGates feathelper.FeatureGates
7681 )
7782
7883 flag .StringVar (& metricsAddr , "metrics-addr" , ":8080" , "The address the metric endpoint binds to." )
@@ -83,13 +88,21 @@ func main() {
8388 flag .BoolVar (& watchAllNamespaces , "watch-all-namespaces" , true ,
8489 "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace." )
8590 flag .DurationVar (& rateLimitInterval , "rate-limit-interval" , 5 * time .Minute , "Interval in which rate limit has effect." )
91+
8692 clientOptions .BindFlags (flag .CommandLine )
8793 logOptions .BindFlags (flag .CommandLine )
8894 leaderElectionOptions .BindFlags (flag .CommandLine )
8995 aclOptions .BindFlags (flag .CommandLine )
9096 rateLimiterOptions .BindFlags (flag .CommandLine )
97+ featureGates .BindFlags (flag .CommandLine )
98+
9199 flag .Parse ()
92100
101+ if err := featureGates .WithLogger (setupLog ).SupportedFeatures (features .FeatureGates ()); err != nil {
102+ setupLog .Error (err , "unable to load feature gates" )
103+ os .Exit (1 )
104+ }
105+
93106 log := logger .NewLogger (logOptions )
94107 ctrl .SetLogger (log )
95108
@@ -98,6 +111,16 @@ func main() {
98111 watchNamespace = os .Getenv ("RUNTIME_NAMESPACE" )
99112 }
100113
114+ var disableCacheFor []ctrlclient.Object
115+ shouldCache , err := features .Enabled (features .CacheSecretsAndConfigMaps )
116+ if err != nil {
117+ setupLog .Error (err , "unable to check feature gate " + features .CacheSecretsAndConfigMaps )
118+ os .Exit (1 )
119+ }
120+ if ! shouldCache {
121+ disableCacheFor = append (disableCacheFor , & corev1.Secret {}, & corev1.ConfigMap {})
122+ }
123+
101124 restConfig := client .GetConfigOrDie (clientOptions )
102125 mgr , err := ctrl .NewManager (restConfig , ctrl.Options {
103126 Scheme : scheme ,
@@ -112,6 +135,7 @@ func main() {
112135 LeaderElectionID : fmt .Sprintf ("%s-leader-election" , controllerName ),
113136 Namespace : watchNamespace ,
114137 Logger : ctrl .Log ,
138+ ClientDisableCacheFor : disableCacheFor ,
115139 })
116140 if err != nil {
117141 setupLog .Error (err , "unable to start manager" )
0 commit comments