@@ -22,10 +22,8 @@ import (
22
22
23
23
csi "github.com/container-storage-interface/spec/lib/go/csi"
24
24
"github.com/golang/glog"
25
- "github.com/opensds/nbp/csi/server/plugin"
26
- "github.com/opensds/nbp/csi/server/plugin/opensds"
25
+ plugin "github.com/opensds/nbp/csi/server/plugin/opensds"
27
26
"github.com/opensds/nbp/csi/util"
28
- "github.com/spf13/cobra"
29
27
"google.golang.org/grpc"
30
28
"google.golang.org/grpc/reflection"
31
29
@@ -34,76 +32,45 @@ import (
34
32
_ "github.com/opensds/opensds/contrib/connector/rbd"
35
33
)
36
34
37
- var (
38
- csiEndpoint string
39
- opensdsEndpoint string
40
- opensdsAuthStrategy string
41
- )
42
-
43
- func init () {
44
- flag .Set ("alsologtostderr" , "true" )
45
- }
46
-
47
35
func main () {
48
-
49
- flag .CommandLine .Parse ([]string {})
36
+ flag .Set ("alsologtostderr" , "true" )
50
37
// Open OpenSDS dock service log file.
51
38
util .InitLogs ()
52
39
defer util .FlushLogs ()
53
40
54
- cmd := & cobra.Command {
55
- Use : "OpenSDS" ,
56
- Short : "CSI based OpenSDS driver" ,
57
- Run : func (cmd * cobra.Command , args []string ) {
58
- handle ()
59
- },
60
- }
41
+ var csiEndpoint , opensdsEndpoint , opensdsAuthStrategy string
42
+ // CSI endpoint
43
+ flag .StringVar (& csiEndpoint , "csiEndpoint" , util .CSIDefaultEndpoint , "CSI Endpoint" )
61
44
62
- // the endpoint variable priority is flag, ENV and default.
63
- cmd . Flags (). AddGoFlagSet ( flag . CommandLine )
45
+ // opensds endpoint
46
+ flag . StringVar ( & opensdsEndpoint , "opensdsEndpoint" , util . OpensdsDefaultEndpoint , "OpenSDS Endpoint" )
64
47
65
- csiEp := util .CSIDefaultEndpoint
66
- opensdsEp := util .OpensdsDefaultEndpoint
67
- if ep , ok := os .LookupEnv (util .CSIEndpoint ); ok {
68
- csiEp = ep
69
- }
70
- if ep , ok := os .LookupEnv (util .OpensdsEndpoint ); ok {
71
- opensdsEp = ep
72
- }
73
- cmd .PersistentFlags ().StringVar (& csiEndpoint , "csiEndpoint" , csiEp , "CSI Endpoint" )
74
- cmd .PersistentFlags ().StringVar (& opensdsEndpoint , "opensdsEndpoint" , opensdsEp , "OpenSDS Endpoint" )
75
- cmd .PersistentFlags ().StringVar (& opensdsAuthStrategy , "opensdsAuthStrategy" , "" , "OpenSDS Auth Strategy" )
48
+ // opensds auth strategy
49
+ flag .StringVar (& opensdsAuthStrategy , "opensdsAuthStrategy" , util .OpensdsDefaultAuthStrategy , "OpenSDS Auth Strategy" )
76
50
77
- cmd .ParseFlags (os .Args [1 :])
78
- if err := cmd .Execute (); err != nil {
79
- glog .Errorf ("failed to execute: %v" , err )
80
- os .Exit (1 )
81
- }
82
-
83
- os .Exit (0 )
84
- }
85
-
86
- func handle () {
87
-
88
- // Set Env
89
- os .Setenv (util .OpensdsEndpoint , opensdsEndpoint )
90
- os .Setenv (util .OpensdsAuthStrategy , opensdsAuthStrategy )
51
+ flag .Parse ()
91
52
92
53
// Get CSI Endpoint Listener
93
54
lis , err := util .GetCSIEndPointListener (csiEndpoint )
94
55
if err != nil {
95
56
glog .Errorf ("failed to listen: %v" , err )
57
+ os .Exit (1 )
58
+ }
59
+
60
+ // Initialize the driver
61
+ pluginServer , err := plugin .NewServer (opensdsEndpoint , opensdsAuthStrategy )
62
+ if err != nil {
63
+ glog .Errorf ("failed to initialize the driver: %v" , err )
64
+ os .Exit (1 )
96
65
}
97
66
98
67
// New Grpc Server
99
68
s := grpc .NewServer ()
100
69
101
70
// Register CSI Service
102
- var defaultplugin plugin.Service = & opensds.Plugin {}
103
- conServer := & server {plugin : defaultplugin }
104
- csi .RegisterIdentityServer (s , conServer )
105
- csi .RegisterControllerServer (s , conServer )
106
- csi .RegisterNodeServer (s , conServer )
71
+ csi .RegisterIdentityServer (s , pluginServer )
72
+ csi .RegisterControllerServer (s , pluginServer )
73
+ csi .RegisterNodeServer (s , pluginServer )
107
74
108
75
// Register reflection Service
109
76
reflection .Register (s )
0 commit comments