@@ -22,18 +22,21 @@ import (
2222 "time"
2323
2424 flag "github.com/spf13/pflag"
25+ corev1 "k8s.io/api/core/v1"
2526 "k8s.io/apimachinery/pkg/runtime"
2627 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2728 _ "k8s.io/client-go/plugin/pkg/client/auth/azure"
2829 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
2930 "sigs.k8s.io/cli-utils/pkg/kstatus/polling"
3031 "sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
3132 ctrl "sigs.k8s.io/controller-runtime"
33+ ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3234
3335 "github.com/fluxcd/pkg/runtime/acl"
3436 runtimeClient "github.com/fluxcd/pkg/runtime/client"
3537 runtimeCtrl "github.com/fluxcd/pkg/runtime/controller"
3638 "github.com/fluxcd/pkg/runtime/events"
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"
@@ -42,6 +45,7 @@ import (
4245
4346 kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
4447 "github.com/fluxcd/kustomize-controller/controllers"
48+ "github.com/fluxcd/kustomize-controller/internal/features"
4549 "github.com/fluxcd/kustomize-controller/internal/statusreaders"
4650 // +kubebuilder:scaffold:imports
4751)
@@ -78,6 +82,7 @@ func main() {
7882 noRemoteBases bool
7983 httpRetry int
8084 defaultServiceAccount string
85+ featureGates feathelper.FeatureGates
8186 )
8287
8388 flag .StringVar (& metricsAddr , "metrics-addr" , ":8080" , "The address the metric endpoint binds to." )
@@ -91,21 +96,39 @@ func main() {
9196 "Disallow remote bases usage in Kustomize overlays. When this flag is enabled, all resources must refer to local files included in the source artifact." )
9297 flag .IntVar (& httpRetry , "http-retry" , 9 , "The maximum number of retries when failing to fetch artifacts over HTTP." )
9398 flag .StringVar (& defaultServiceAccount , "default-service-account" , "" , "Default service account used for impersonation." )
99+
94100 clientOptions .BindFlags (flag .CommandLine )
95101 logOptions .BindFlags (flag .CommandLine )
96102 leaderElectionOptions .BindFlags (flag .CommandLine )
97103 aclOptions .BindFlags (flag .CommandLine )
98104 kubeConfigOpts .BindFlags (flag .CommandLine )
99105 rateLimiterOptions .BindFlags (flag .CommandLine )
106+ featureGates .BindFlags (flag .CommandLine )
107+
100108 flag .Parse ()
101109
110+ if err := featureGates .WithLogger (setupLog ).SupportedFeatures (features .FeatureGates ()); err != nil {
111+ setupLog .Error (err , "unable to load feature gates" )
112+ os .Exit (1 )
113+ }
114+
102115 ctrl .SetLogger (logger .NewLogger (logOptions ))
103116
104117 watchNamespace := ""
105118 if ! watchAllNamespaces {
106119 watchNamespace = os .Getenv ("RUNTIME_NAMESPACE" )
107120 }
108121
122+ var disableCacheFor []ctrlclient.Object
123+ shouldCache , err := features .Enabled (features .CacheSecretsAndConfigMaps )
124+ if err != nil {
125+ setupLog .Error (err , "unable to check feature gate " + features .CacheSecretsAndConfigMaps )
126+ os .Exit (1 )
127+ }
128+ if ! shouldCache {
129+ disableCacheFor = append (disableCacheFor , & corev1.Secret {}, & corev1.ConfigMap {})
130+ }
131+
109132 restConfig := runtimeClient .GetConfigOrDie (clientOptions )
110133 mgr , err := ctrl .NewManager (restConfig , ctrl.Options {
111134 Scheme : scheme ,
@@ -120,6 +143,7 @@ func main() {
120143 LeaderElectionID : fmt .Sprintf ("%s-leader-election" , controllerName ),
121144 Namespace : watchNamespace ,
122145 Logger : ctrl .Log ,
146+ ClientDisableCacheFor : disableCacheFor ,
123147 })
124148 if err != nil {
125149 setupLog .Error (err , "unable to start manager" )
0 commit comments