@@ -36,6 +36,7 @@ import (
3636
3737 "github.com/fluxcd/pkg/runtime/client"
3838 "github.com/fluxcd/pkg/runtime/events"
39+ "github.com/fluxcd/pkg/runtime/leaderelection"
3940 "github.com/fluxcd/pkg/runtime/logger"
4041 "github.com/fluxcd/pkg/runtime/metrics"
4142 "github.com/fluxcd/pkg/runtime/pprof"
@@ -66,27 +67,24 @@ func init() {
6667
6768func main () {
6869 var (
69- metricsAddr string
70- eventsAddr string
71- healthAddr string
72- enableLeaderElection bool
73- storagePath string
74- storageAddr string
75- storageAdvAddr string
76- concurrent int
77- watchAllNamespaces bool
78- clientOptions client .Options
79- logOptions logger .Options
70+ metricsAddr string
71+ eventsAddr string
72+ healthAddr string
73+ storagePath string
74+ storageAddr string
75+ storageAdvAddr string
76+ concurrent int
77+ watchAllNamespaces bool
78+ clientOptions client. Options
79+ logOptions logger .Options
80+ leaderElectionOptions leaderelection .Options
8081 )
8182
8283 flag .StringVar (& metricsAddr , "metrics-addr" , envOrDefault ("METRICS_ADDR" , ":8080" ),
8384 "The address the metric endpoint binds to." )
8485 flag .StringVar (& eventsAddr , "events-addr" , envOrDefault ("EVENTS_ADDR" , "" ),
8586 "The address of the events receiver." )
8687 flag .StringVar (& healthAddr , "health-addr" , ":9440" , "The address the health endpoint binds to." )
87- flag .BoolVar (& enableLeaderElection , "enable-leader-election" , false ,
88- "Enable leader election for controller manager. " +
89- "Enabling this will ensure there is only one active controller manager." )
9088 flag .StringVar (& storagePath , "storage-path" , envOrDefault ("STORAGE_PATH" , "" ),
9189 "The local storage path." )
9290 flag .StringVar (& storageAddr , "storage-addr" , envOrDefault ("STORAGE_ADDR" , ":9090" ),
@@ -96,10 +94,9 @@ func main() {
9694 flag .IntVar (& concurrent , "concurrent" , 2 , "The number of concurrent reconciles per controller." )
9795 flag .BoolVar (& watchAllNamespaces , "watch-all-namespaces" , true ,
9896 "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace." )
99- flag .Bool ("log-json" , false , "Set logging to JSON format." )
100- flag .CommandLine .MarkDeprecated ("log-json" , "Please use --log-encoding=json instead." )
10197 clientOptions .BindFlags (flag .CommandLine )
10298 logOptions .BindFlags (flag .CommandLine )
99+ leaderElectionOptions .BindFlags (flag .CommandLine )
103100 flag .Parse ()
104101
105102 ctrl .SetLogger (logger .NewLogger (logOptions ))
@@ -124,14 +121,18 @@ func main() {
124121
125122 restConfig := client .GetConfigOrDie (clientOptions )
126123 mgr , err := ctrl .NewManager (restConfig , ctrl.Options {
127- Scheme : scheme ,
128- MetricsBindAddress : metricsAddr ,
129- HealthProbeBindAddress : healthAddr ,
130- Port : 9443 ,
131- LeaderElection : enableLeaderElection ,
132- LeaderElectionID : "305740c0.fluxcd.io" ,
133- Namespace : watchNamespace ,
134- Logger : ctrl .Log ,
124+ Scheme : scheme ,
125+ MetricsBindAddress : metricsAddr ,
126+ HealthProbeBindAddress : healthAddr ,
127+ Port : 9443 ,
128+ LeaderElection : leaderElectionOptions .Enable ,
129+ LeaderElectionReleaseOnCancel : leaderElectionOptions .ReleaseOnCancel ,
130+ LeaseDuration : & leaderElectionOptions .LeaseDuration ,
131+ RenewDeadline : & leaderElectionOptions .RenewDeadline ,
132+ RetryPeriod : & leaderElectionOptions .RetryPeriod ,
133+ LeaderElectionID : "305740c0.fluxcd.io" ,
134+ Namespace : watchNamespace ,
135+ Logger : ctrl .Log ,
135136 })
136137 if err != nil {
137138 setupLog .Error (err , "unable to start manager" )
0 commit comments