Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
133 lines (113 loc) · 4.21 KB
/
Copy pathmain.go
File metadata and controls
133 lines (113 loc) · 4.21 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright 2025 Gluesys FlexA Inc.
*/
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
"github.com/gluesys/flexa-csi/pkg/driver"
"github.com/gluesys/flexa-csi/pkg/flexa/common"
"github.com/gluesys/flexa-csi/pkg/flexa/service"
"github.com/gluesys/flexa-csi/pkg/logger"
"github.com/gluesys/flexa-csi/pkg/webhook"
)
var (
// CSI options
csiNodeID = "CSINode"
csiEndpoint = "unix:///var/lib/kubelet/plugins/" + driver.DriverName + "/csi.sock"
csiClientInfoPath = "/etc/flexa/client-info.yml"
// runMode: "csi" (default) or "webhook" (mutating admission HTTP server)
runMode = "csi"
tlsCertPath = ""
tlsKeyPath = ""
listenAddr = ":8443"
// Logging
logLevel = "info"
webapiDebug = false
multipathForUC = true
)
var rootCmd = &cobra.Command{
Use: "flexa-csi-driver",
Short: "Gluesys FlexA CSI Driver",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if webapiDebug {
logger.WebapiDebug = true
logLevel = "debug"
}
logger.Init(logLevel)
if runMode == "webhook" {
if tlsCertPath == "" || tlsKeyPath == "" {
return fmt.Errorf("webhook mode requires --tls-cert and --tls-key")
}
log.Infof("Webhook mode: listen=%s cert=%s key=%s", listenAddr, tlsCertPath, tlsKeyPath)
return webhook.StartWebhookServer(tlsCertPath, tlsKeyPath, listenAddr)
}
if !multipathForUC {
driver.MultipathEnabled = false
}
if csiEndpoint == "" {
return fmt.Errorf("CSI mode requires --endpoint")
}
if csiClientInfoPath == "" {
return fmt.Errorf("CSI mode requires --client-info")
}
err := driverStart()
if err != nil {
log.Errorf("Failed to driverStart(): %v", err)
return err
}
return nil
},
}
func driverStart() error {
log.Infof("CSI Options = {%s, %s, %s}", csiNodeID, csiEndpoint, csiClientInfoPath)
flxService := service.NewFlexAService()
cfg, err := common.LoadClientInfoConfig(csiClientInfoPath)
if err != nil {
log.Errorf("Failed to read client-info: %v", err)
return err
}
if cfg.Default != nil {
flxService.SetFep(cfg.Default)
}
// 2. Create and Run the Driver
drv, err := driver.NewControllerAndNodeDriver(csiNodeID, csiEndpoint, flxService)
if err != nil {
log.Errorf("Failed to create driver: %v", err)
return err
}
drv.SetClientInfoConfig(cfg)
drv.Activate()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
// Block until a signal is received.
<-c
log.Infof("Shutting down.")
return nil
}
func main() {
addFlags(rootCmd)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
os.Exit(0)
}
func addFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&runMode, "mode", runMode, "Run mode: csi (default) or webhook")
cmd.PersistentFlags().StringVar(&tlsCertPath, "tls-cert", tlsCertPath, "Path to TLS certificate (webhook mode)")
cmd.PersistentFlags().StringVar(&tlsKeyPath, "tls-key", tlsKeyPath, "Path to TLS private key (webhook mode)")
cmd.PersistentFlags().StringVar(&listenAddr, "listen-addr", listenAddr, "Listen address for webhook mode (e.g. :8443)")
cmd.PersistentFlags().StringVar(&csiNodeID, "nodeid", csiNodeID, "Node ID")
cmd.PersistentFlags().StringVarP(&csiEndpoint, "endpoint", "e", csiEndpoint, "CSI endpoint")
cmd.PersistentFlags().StringVarP(&csiClientInfoPath, "client-info", "f", csiClientInfoPath, "Path to Gluesys FlexA client-info YAML (proxy profiles)")
cmd.PersistentFlags().StringVar(&logLevel, "log-level", logLevel, "Log level (debug, info, warn, error, fatal)")
cmd.PersistentFlags().BoolVarP(&webapiDebug, "debug", "d", webapiDebug, "Enable webapi debugging logs")
cmd.PersistentFlags().BoolVar(&multipathForUC, "multipath", multipathForUC, "Set to 'false' to disable multipath for UC")
cmd.Flags().SortFlags = false
cmd.PersistentFlags().SortFlags = false
}