@@ -23,31 +23,32 @@ import (
2323 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2424 // to ensure that exec-entrypoint and run can make use of them.
2525 _ "k8s.io/client-go/plugin/pkg/client/auth"
26- "k8s.io/klog/v2"
2726
27+ "github.com/spf13/pflag"
2828 "k8s.io/apimachinery/pkg/runtime"
2929 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3030 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3131 cliflag "k8s.io/component-base/cli/flag"
3232 "k8s.io/component-base/logs"
3333 logsv1 "k8s.io/component-base/logs/api/v1"
34+ "k8s.io/klog/v2"
3435 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
36+ "sigs.k8s.io/cluster-api/util/flags"
3537 ctrl "sigs.k8s.io/controller-runtime"
3638 "sigs.k8s.io/controller-runtime/pkg/healthz"
3739
3840 infrastructurev1beta1 "github.com/k8s-proxmox/cluster-api-provider-proxmox/api/v1beta1"
3941 "github.com/k8s-proxmox/cluster-api-provider-proxmox/cloud/scheduler"
4042 controller "github.com/k8s-proxmox/cluster-api-provider-proxmox/controllers"
41- "github.com/spf13/pflag"
4243 //+kubebuilder:scaffold:imports
4344)
4445
4546var (
46- scheme = runtime .NewScheme ()
47- setupLog = ctrl .Log .WithName ("setup" )
47+ scheme = runtime .NewScheme ()
48+ setupLog = ctrl .Log .WithName ("setup" )
49+ managerOptions = flags.ManagerOptions {}
4850
4951 // flags
50- metricsAddr string
5152 enableLeaderElection bool
5253 probeAddr string
5354 pluginConfig string
@@ -74,12 +75,16 @@ func main() {
7475 // }
7576 pflag .Parse ()
7677
78+ _ , metricsOptions , err := flags .GetManagerOptions (managerOptions )
79+ if err != nil {
80+ setupLog .Error (err , "Unable to start manager: invalid flags" )
81+ }
82+
7783 ctrl .SetLogger (klog .Background ())
7884
7985 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
8086 Scheme : scheme ,
81- MetricsBindAddress : metricsAddr ,
82- Port : 9443 ,
87+ Metrics : * metricsOptions ,
8388 HealthProbeBindAddress : probeAddr ,
8489 LeaderElection : enableLeaderElection ,
8590 LeaderElectionID : "36404136.cluster.x-k8s.io" ,
@@ -146,10 +151,11 @@ func main() {
146151func InitFlags (fs * pflag.FlagSet ) {
147152 logsv1 .AddFlags (logOptions , fs )
148153
149- fs .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
150154 fs .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
151155 fs .BoolVar (& enableLeaderElection , "leader-elect" , false ,
152156 "Enable leader election for controller manager. " +
153157 "Enabling this will ensure there is only one active controller manager." )
154158 fs .StringVar (& pluginConfig , "scheduler-plugin-config" , "" , "The config file path for qemu-scheduler plugins" )
159+
160+ flags .AddManagerOptions (fs , & managerOptions )
155161}
0 commit comments