@@ -27,11 +27,13 @@ import (
2727 "github.com/go-logr/logr"
2828 flag "github.com/spf13/pflag"
2929 "helm.sh/helm/v3/pkg/getter"
30+ corev1 "k8s.io/api/core/v1"
3031 "k8s.io/apimachinery/pkg/runtime"
3132 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3233 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3334 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3435 ctrl "sigs.k8s.io/controller-runtime"
36+ ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3537
3638 "github.com/fluxcd/pkg/git"
3739 "github.com/fluxcd/pkg/runtime/client"
@@ -167,6 +169,16 @@ func main() {
167169 watchNamespace = os .Getenv ("RUNTIME_NAMESPACE" )
168170 }
169171
172+ disableCacheFor := []ctrlclient.Object {}
173+ shouldCache , err := features .Enabled (features .CacheSecretsAndConfigMaps )
174+ if err != nil {
175+ setupLog .Error (err , "unable to check feature gate " + features .CacheSecretsAndConfigMaps )
176+ os .Exit (1 )
177+ }
178+ if ! shouldCache {
179+ disableCacheFor = append (disableCacheFor , & corev1.Secret {}, & corev1.ConfigMap {})
180+ }
181+
170182 restConfig := client .GetConfigOrDie (clientOptions )
171183 mgr , err := ctrl .NewManager (restConfig , ctrl.Options {
172184 Scheme : scheme ,
@@ -181,6 +193,7 @@ func main() {
181193 LeaderElectionID : fmt .Sprintf ("%s-leader-election" , controllerName ),
182194 Namespace : watchNamespace ,
183195 Logger : ctrl .Log ,
196+ ClientDisableCacheFor : disableCacheFor ,
184197 })
185198 if err != nil {
186199 setupLog .Error (err , "unable to start manager" )
0 commit comments