@@ -20,17 +20,17 @@ limitations under the License.
20
20
package main
21
21
22
22
import (
23
- goflag "flag"
24
- "fmt"
25
23
"math/rand"
26
24
"os"
27
25
"time"
28
26
29
27
"github.com/spf13/pflag"
28
+ "k8s.io/apimachinery/pkg/util/wait"
30
29
"k8s.io/cloud-provider"
31
30
"k8s.io/cloud-provider/app"
31
+ "k8s.io/cloud-provider/app/config"
32
32
"k8s.io/cloud-provider/options"
33
- "k8s.io/component-base/cli/flag"
33
+ cliflag "k8s.io/component-base/cli/flag"
34
34
"k8s.io/component-base/logs"
35
35
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
36
36
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
@@ -42,74 +42,41 @@ import (
42
42
func main () {
43
43
rand .Seed (time .Now ().UnixNano ())
44
44
45
- s , err := options .NewCloudControllerManagerOptions ()
45
+ ccmOptions , err := options .NewCloudControllerManagerOptions ()
46
46
if err != nil {
47
47
klog .Fatalf ("unable to initialize command options: %v" , err )
48
48
}
49
49
50
- fs := pflag .NewFlagSet ("scaleway-cloud-controller-manager" , pflag .ContinueOnError )
51
- klogFlags := goflag .NewFlagSet ("klog" , goflag .ContinueOnError )
52
- klog .InitFlags (klogFlags )
53
- fs .AddGoFlagSet (klogFlags )
54
- fs .SetNormalizeFunc (flag .WordSepNormalizeFunc )
55
- for _ , f := range s .Flags ([]string {"cloud-node" , "cloud-node-lifecycle" , "service" , "route" }, app .ControllersDisabledByDefault .List ()).FlagSets {
56
- fs .AddFlagSet (f )
57
- }
50
+ fss := cliflag.NamedFlagSets {}
58
51
59
- err = fs .Parse (os .Args [1 :])
60
- if err != nil {
61
- if err != pflag .ErrHelp {
62
- klog .Errorf ("could not parse arguments: %v" , err )
63
- }
64
- os .Exit (1 )
65
- }
52
+ command := app .NewCloudControllerManagerCommand (ccmOptions , cloudInitializer , app .DefaultInitFuncConstructors , fss , wait .NeverStop )
53
+ command .Use = "scaleway-cloud-controller-manager"
66
54
67
- c , err := s .Config ([]string {}, app .ControllersDisabledByDefault .List ())
68
- if err != nil {
69
- fmt .Fprintf (os .Stderr , "%v\n " , err )
55
+ pflag .CommandLine .SetNormalizeFunc (cliflag .WordSepNormalizeFunc )
56
+
57
+ logs .InitLogs ()
58
+ defer logs .FlushLogs ()
59
+
60
+ if err := command .Execute (); err != nil {
70
61
os .Exit (1 )
71
62
}
63
+ }
72
64
73
- // initialize cloud provider with the cloud provider name and config file provided
65
+ func cloudInitializer ( config * config. CompletedConfig ) cloudprovider. Interface {
74
66
cloud , err := cloudprovider .InitCloudProvider (scaleway .ProviderName , "" )
75
67
if err != nil {
76
68
klog .Fatalf ("Cloud provider could not be initialized: %v" , err )
77
69
}
78
70
if cloud == nil {
79
- klog .Fatalf ("cloud provider is nil" )
71
+ klog .Fatalf ("Cloud provider is nil" )
80
72
}
81
73
82
74
if ! cloud .HasClusterID () {
83
- if c .ComponentConfig .KubeCloudShared .AllowUntaggedCloud {
75
+ if config .ComponentConfig .KubeCloudShared .AllowUntaggedCloud {
84
76
klog .Warning ("detected a cluster without a ClusterID. A ClusterID will be required in the future. Please tag your cluster to avoid any future issues" )
85
77
} else {
86
78
klog .Fatalf ("no ClusterID found. A ClusterID is required for the cloud provider to function properly. This check can be bypassed by setting the allow-untagged-cloud option" )
87
79
}
88
80
}
89
-
90
- // Initialize the cloud provider with a reference to the clientBuilder
91
- cloud .Initialize (c .ClientBuilder , make (chan struct {}))
92
- // Set the informer on the user cloud object
93
- if informerUserCloud , ok := cloud .(cloudprovider.InformerUser ); ok {
94
- informerUserCloud .SetInformers (c .SharedInformers )
95
- }
96
-
97
- controllerInitializers := app .DefaultControllerInitializers (c .Complete (), cloud )
98
- command := app .NewCloudControllerManagerCommand (s , c , controllerInitializers )
99
-
100
- // utilflag.InitFlags()
101
- logs .InitLogs ()
102
- defer logs .FlushLogs ()
103
-
104
- // the flags could be set before execute
105
- command .Flags ().VisitAll (func (flag * pflag.Flag ) {
106
- if flag .Name == "cloud-provider" {
107
- flag .Value .Set (scaleway .ProviderName )
108
- return
109
- }
110
- })
111
- if err := command .Execute (); err != nil {
112
- fmt .Fprintf (os .Stderr , "error: %v\n " , err )
113
- os .Exit (1 )
114
- }
81
+ return cloud
115
82
}
0 commit comments