@@ -23,53 +23,58 @@ 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"
2627
2728 "k8s.io/apimachinery/pkg/runtime"
2829 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2930 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
31+ cliflag "k8s.io/component-base/cli/flag"
32+ "k8s.io/component-base/logs"
33+ logsv1 "k8s.io/component-base/logs/api/v1"
3034 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3135 ctrl "sigs.k8s.io/controller-runtime"
3236 "sigs.k8s.io/controller-runtime/pkg/healthz"
33- "sigs.k8s.io/controller-runtime/pkg/log/zap"
3437
3538 infrastructurev1beta1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
3639 "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler"
3740 controller "github.com/sp-yduck/cluster-api-provider-proxmox/controllers"
41+ "github.com/spf13/pflag"
3842 //+kubebuilder:scaffold:imports
3943)
4044
4145var (
4246 scheme = runtime .NewScheme ()
4347 setupLog = ctrl .Log .WithName ("setup" )
48+
49+ // flags
50+ metricsAddr string
51+ enableLeaderElection bool
52+ probeAddr string
53+ pluginConfig string
54+ logOptions = logs .NewOptions ()
4455)
4556
4657func init () {
4758 utilruntime .Must (clientgoscheme .AddToScheme (scheme ))
4859
4960 utilruntime .Must (infrastructurev1beta1 .AddToScheme (scheme ))
50- utilruntime .Must (infrastructurev1beta1 .AddToScheme (scheme ))
51- _ = clusterv1 . AddToScheme ( scheme )
61+ utilruntime .Must (clusterv1 .AddToScheme (scheme ))
62+
5263 //+kubebuilder:scaffold:scheme
5364}
5465
5566func main () {
56- var metricsAddr string
57- var enableLeaderElection bool
58- var probeAddr string
59- var pluginConfig string
60- flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
61- flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
62- flag .BoolVar (& enableLeaderElection , "leader-elect" , false ,
63- "Enable leader election for controller manager. " +
64- "Enabling this will ensure there is only one active controller manager." )
65- flag .StringVar (& pluginConfig , "scheduler-plugin-config" , "" , "The config file path for qemu-scheduler plugins" )
66- opts := zap.Options {
67- Development : true ,
68- }
69- opts .BindFlags (flag .CommandLine )
70- flag .Parse ()
71-
72- ctrl .SetLogger (zap .New (zap .UseFlagOptions (& opts )))
67+ InitFlags (pflag .CommandLine )
68+ pflag .CommandLine .SetNormalizeFunc (cliflag .WordSepNormalizeFunc )
69+ pflag .CommandLine .AddGoFlagSet (flag .CommandLine )
70+ // Set log level 2 as default.
71+ // if err := pflag.CommandLine.Set("v", "2"); err != nil {
72+ // setupLog.Error(err, "failed to set log level: %v")
73+ // os.Exit(1)
74+ // }
75+ pflag .Parse ()
76+
77+ ctrl .SetLogger (klog .Background ())
7378
7479 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
7580 Scheme : scheme ,
@@ -96,7 +101,7 @@ func main() {
96101 }
97102 schedManager , err := scheduler .NewManager (
98103 scheduler.SchedulerParams {
99- Logger : zap . New ( zap . UseFlagOptions ( & opts ) ),
104+ Logger : klog . Background ( ),
100105 PluginConfigFile : pluginConfig ,
101106 },
102107 )
@@ -137,3 +142,14 @@ func main() {
137142 os .Exit (1 )
138143 }
139144}
145+
146+ func InitFlags (fs * pflag.FlagSet ) {
147+ logsv1 .AddFlags (logOptions , fs )
148+
149+ fs .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
150+ fs .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
151+ fs .BoolVar (& enableLeaderElection , "leader-elect" , false ,
152+ "Enable leader election for controller manager. " +
153+ "Enabling this will ensure there is only one active controller manager." )
154+ fs .StringVar (& pluginConfig , "scheduler-plugin-config" , "" , "The config file path for qemu-scheduler plugins" )
155+ }
0 commit comments