-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
61 lines (48 loc) · 1.35 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
package main
import (
"context"
"flag"
"os"
"os/signal"
"strings"
"syscall"
"github.com/civo/civo-csi/pkg/driver"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var (
versionInfo = flag.Bool("version", false, "Print the driver version")
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
flag.Parse()
if *versionInfo {
log.Info().Str("version", driver.Version).Msg("CSI driver")
return
}
apiURL := strings.TrimSpace(os.Getenv("CIVO_API_URL"))
apiKey := strings.TrimSpace(os.Getenv("CIVO_API_KEY"))
region := strings.TrimSpace(os.Getenv("CIVO_REGION"))
ns := strings.TrimSpace(os.Getenv("CIVO_NAMESPACE"))
clusterID := strings.TrimSpace(os.Getenv("CIVO_CLUSTER_ID"))
d, err := driver.NewDriver(apiURL, apiKey, region, ns, clusterID)
if err != nil {
log.Fatal().Err(err)
}
log.Info().Interface("d", d).Msg("Created a new driver")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
log.Info().Msg("Running until SIGINT/SIGTERM received")
sig := <-c
log.Info().Interface("signal", sig).Msg("Received signal")
cancel()
}()
log.Info().Msg("Running the driver")
if err := d.Run(ctx); err != nil {
log.Fatal().Err(err)
}
}