-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
81 lines (71 loc) · 1.75 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
_ "net/http/pprof"
"os"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/harvester/harvester-csi-driver/pkg/config"
"github.com/harvester/harvester-csi-driver/pkg/csi"
"github.com/harvester/harvester-csi-driver/pkg/version"
)
var (
cfg config.Config
)
func main() {
flags := []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Value: "unix:///csi/csi.sock",
Usage: "CSI endpoint",
Destination: &cfg.Endpoint,
},
cli.StringFlag{
Name: "nodeid",
Usage: "Node ID",
Destination: &cfg.NodeID,
},
cli.StringFlag{
Name: "kubeconfig",
Value: "",
Usage: "kubeconfig to access host Harvester cluster",
Destination: &cfg.KubeConfig,
},
cli.BoolFlag{
Name: "debug",
EnvVar: "DEBUG",
Usage: "enable debug loggging",
Destination: &cfg.Debug,
},
cli.StringFlag{
Name: "host-storage-class",
Value: "",
EnvVar: "HOST_STORAGE_CLASS",
Usage: "storage class of volumes created in the host cluster",
Destination: &cfg.HostStorageClass,
},
}
app := cli.NewApp()
app.Name = "harvester CSI driver"
app.Version = version.FriendlyVersion()
app.Flags = flags
app.Action = func(c *cli.Context) {
adjustLogs(&cfg)
if err := runCSI(c); err != nil {
logrus.Fatalf("Error running CSI driver: %v", err)
}
}
if err := app.Run(os.Args); err != nil {
logrus.Fatalf("Error running CSI driver: %v", err)
}
}
func runCSI(*cli.Context) error {
manager := csi.GetCSIManager()
return manager.Run(&cfg)
}
func adjustLogs(cfg *config.Config) {
logrus.SetOutput(os.Stdout)
if cfg.Debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Loglevel set to %v", logrus.DebugLevel)
}
}