@@ -22,12 +22,15 @@ import (
2222 "os"
2323 "time"
2424
25+ "github.com/spf13/pflag"
2526 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2627 "k8s.io/apimachinery/pkg/runtime"
2728 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2829 "k8s.io/client-go/rest"
2930 "k8s.io/klog"
3031 "k8s.io/klog/klogr"
32+ _ "sigs.k8s.io/cluster-api/features"
33+ "sigs.k8s.io/cluster-api/util/featuregate"
3134 ctrl "sigs.k8s.io/controller-runtime"
3235 "sigs.k8s.io/controller-runtime/pkg/cache"
3336 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -69,44 +72,52 @@ func init() {
6972 // +kubebuilder:scaffold:scheme
7073}
7174
72- func main () {
73- flag .StringVar (& metricsAddr , "metrics-addr" , ":8080" ,
75+ // InitFlags initializes the flags.
76+ func InitFlags (fs * pflag.FlagSet ) {
77+ fs .StringVar (& metricsAddr , "metrics-addr" , ":8080" ,
7478 "The address the metric endpoint binds to." )
7579
76- flag .BoolVar (& enableLeaderElection , "enable-leader-election" , false ,
80+ fs .BoolVar (& enableLeaderElection , "enable-leader-election" , false ,
7781 "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
7882
79- flag .StringVar (& watchNamespace , "namespace" , "" ,
83+ fs .StringVar (& watchNamespace , "namespace" , "" ,
8084 "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces." )
8185
82- flag .StringVar (& profilerAddress , "profiler-address" , "" ,
86+ fs .StringVar (& profilerAddress , "profiler-address" , "" ,
8387 "Bind address to expose the pprof profiler (e.g. localhost:6060)" )
8488
85- flag .IntVar (& clusterConcurrency , "cluster-concurrency" , 10 ,
89+ fs .IntVar (& clusterConcurrency , "cluster-concurrency" , 10 ,
8690 "Number of clusters to process simultaneously" )
8791
88- flag .IntVar (& machineConcurrency , "machine-concurrency" , 10 ,
92+ fs .IntVar (& machineConcurrency , "machine-concurrency" , 10 ,
8993 "Number of machines to process simultaneously" )
9094
91- flag .IntVar (& machineSetConcurrency , "machineset-concurrency" , 10 ,
95+ fs .IntVar (& machineSetConcurrency , "machineset-concurrency" , 10 ,
9296 "Number of machine sets to process simultaneously" )
9397
94- flag .IntVar (& machineDeploymentConcurrency , "machinedeployment-concurrency" , 10 ,
98+ fs .IntVar (& machineDeploymentConcurrency , "machinedeployment-concurrency" , 10 ,
9599 "Number of machine deployments to process simultaneously" )
96100
97- flag .IntVar (& machinePoolConcurrency , "machinepool-concurrency" , 10 ,
101+ fs .IntVar (& machinePoolConcurrency , "machinepool-concurrency" , 10 ,
98102 "Number of machine pools to process simultaneously" )
99103
100- flag .DurationVar (& syncPeriod , "sync-period" , 10 * time .Minute ,
104+ fs .DurationVar (& syncPeriod , "sync-period" , 10 * time .Minute ,
101105 "The minimum interval at which watched resources are reconciled (e.g. 15m)" )
102106
103- flag .IntVar (& webhookPort , "webhook-port" , 0 ,
107+ fs .IntVar (& webhookPort , "webhook-port" , 0 ,
104108 "Webhook Server port, disabled by default. When enabled, the manager will only work as webhook server, no reconcilers are installed." )
105109
106- flag .StringVar (& healthAddr , "health-addr" , ":9440" ,
110+ fs .StringVar (& healthAddr , "health-addr" , ":9440" ,
107111 "The address the health endpoint binds to." )
108112
109- flag .Parse ()
113+ // Add --feature-gates flag
114+ featuregate .DefaultMutableFeatureGate .AddFlag (fs )
115+ }
116+
117+ func main () {
118+ InitFlags (pflag .CommandLine )
119+ pflag .CommandLine .AddGoFlagSet (flag .CommandLine )
120+ pflag .Parse ()
110121
111122 ctrl .SetLogger (klogr .New ())
112123
0 commit comments