@@ -17,19 +17,18 @@ limitations under the License.
1717// Package main is the main package.
1818package main
1919
20+ // Import packages including all Kubernetes client auth plugins: k8s.io/client-go/plugin/pkg/client/auth.
2021import (
2122 "flag"
2223 "os"
2324 "time"
2425
2526 githubclient "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client"
26- infrastructureclusterstackxk8siov1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
27+ apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
2728 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
2829 "k8s.io/apimachinery/pkg/runtime"
29- utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30- clientgoscheme "k8s.io/client-go/kubernetes/scheme"
31- // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
32- // to ensure that exec-entrypoint and run can make use of them.
30+ runtimeutils "k8s.io/apimachinery/pkg/util/runtime"
31+ "k8s.io/client-go/kubernetes/scheme"
3332 _ "k8s.io/client-go/plugin/pkg/client/auth"
3433 "sigs.k8s.io/cluster-api/util/record"
3534 ctrl "sigs.k8s.io/controller-runtime"
@@ -40,15 +39,13 @@ import (
4039)
4140
4241var (
43- scheme = runtime .NewScheme ()
44- setupLog = ctrl .Log .WithName ("setup" )
42+ k8sScheme = runtime .NewScheme ()
43+ setupLog = ctrl .Log .WithName ("clusterstack-provider-openstack- setup" )
4544)
4645
4746func init () {
48- utilruntime .Must (clientgoscheme .AddToScheme (scheme ))
49-
50- utilruntime .Must (infrastructureclusterstackxk8siov1alpha1 .AddToScheme (scheme ))
51- //+kubebuilder:scaffold:scheme
47+ runtimeutils .Must (scheme .AddToScheme (k8sScheme ))
48+ runtimeutils .Must (apiv1alpha1 .AddToScheme (k8sScheme ))
5249}
5350
5451var (
@@ -57,19 +54,27 @@ var (
5754)
5855
5956func main () {
60- var metricsAddr string
61- var enableLeaderElection bool
62- var probeAddr string
57+ var (
58+ metricsAddr string
59+ enableLeaderElection bool
60+ probeAddr string
61+ )
62+
6363 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
6464 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
65- flag .BoolVar (& enableLeaderElection , "leader-elect" , false ,
66- "Enable leader election for controller manager. " +
67- "Enabling this will ensure there is only one active controller manager." )
65+ flag .BoolVar (
66+ & enableLeaderElection ,
67+ "leader-elect" ,
68+ false ,
69+ "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." ,
70+ )
6871 flag .StringVar (& releaseDir , "release-dir" , "/tmp/downloads/" , "Specify release directory for cluster-stack releases" )
6972 flag .IntVar (& imageImportTimeout , "image-import-timeout" , 0 , "Maximum time in minutes that you allow cspo to import image. If image-import-timeout <= 0, cspo waits forever." )
73+
7074 opts := zap.Options {
7175 Development : true ,
7276 }
77+
7378 opts .BindFlags (flag .CommandLine )
7479 flag .Parse ()
7580
@@ -78,22 +83,11 @@ func main() {
7883 syncPeriod := 5 * time .Minute
7984
8085 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
81- Scheme : scheme ,
86+ Scheme : k8sScheme ,
8287 Metrics : metricsserver.Options {BindAddress : metricsAddr },
8388 HealthProbeBindAddress : probeAddr ,
8489 LeaderElection : enableLeaderElection ,
85- LeaderElectionID : "26a5dd7c.clusterstack.x-k8s.io" ,
86- // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
87- // when the Manager ends. This requires the binary to immediately end when the
88- // Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
89- // speeds up voluntary leader transitions as the new leader don't have to wait
90- // LeaseDuration time first.
91- //
92- // In the default scaffold provided, the program ends immediately after
93- // the manager stops, so would be fine to enable this option. However,
94- // if you are doing or is intended to do any operation such as perform cleanups
95- // after the manager stops then its usage might be unsafe.
96- // LeaderElectionReleaseOnCancel: true,
90+ LeaderElectionID : "openstack.provider.clusterstack.x-k8s.io" ,
9791 Cache : cache.Options {
9892 SyncPeriod : & syncPeriod ,
9993 },
@@ -125,7 +119,6 @@ func main() {
125119 setupLog .Error (err , "unable to create controller" , "controller" , "OpenStackNodeImageRelease" )
126120 os .Exit (1 )
127121 }
128- //+kubebuilder:scaffold:builder
129122
130123 if err := mgr .AddHealthzCheck ("healthz" , healthz .Ping ); err != nil {
131124 setupLog .Error (err , "unable to set up health check" )
0 commit comments