forked from NetApp/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
112 lines (99 loc) · 3.4 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
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
// Copyright 2016 NetApp, Inc. All Rights Reserved.
package main
import (
"flag"
"os"
"os/signal"
"runtime"
"syscall"
log "github.com/Sirupsen/logrus"
"github.com/netapp/trident/config"
"github.com/netapp/trident/core"
"github.com/netapp/trident/frontend"
"github.com/netapp/trident/frontend/kubernetes"
"github.com/netapp/trident/frontend/rest"
"github.com/netapp/trident/persistent_store"
)
var (
debug = flag.Bool("debug", false, "Enable debugging output")
k8sAPIServer = flag.String("k8s_api_server", "", "Kubernetes API server "+
"address to enable dynamic storage provisioning for Kubernetes.")
k8sConfigPath = flag.String("k8s_config_path", "", "Path to KubeConfig file.")
k8sPod = flag.Bool("k8s_pod", false, "Enables dynamic storage provisioning "+
"for Kubernetes if running in a pod.")
etcdV2 = flag.String("etcd_v2", "", "etcd server (v2 API) for "+
"persisting orchestrator state (e.g., -etcd_v2=http://127.0.0.1:8001)")
address = flag.String("address", "localhost", "Storage orchestrator API address")
port = flag.String("port", "8000", "Storage orchestrator API port")
useInMemory = flag.Bool("no_persistence", false, "Does not persist "+
"any metadata. WILL LOSE TRACK OF VOLUMES ON REBOOT/CRASH.")
kubernetesVersion = "unknown"
storeClient persistent_store.Client
enableKubernetes bool
)
func processCmdLineArgs() {
var err error
if *debug {
log.SetLevel(log.DebugLevel)
}
// Don't bother validating the Kubernetes API server address; we'll know if
// it's invalid during start-up. Given that users can specify DNS names,
// validation would be more trouble than it's worth.
if *etcdV2 != "" {
storeClient, err = persistent_store.NewEtcdClient(*etcdV2)
if err != nil {
panic(err)
}
} else if *etcdV2 != "" && *useInMemory {
log.Fatal("Cannot skip persistence and use etcdV2.")
} else if *useInMemory {
storeClient = persistent_store.NewInMemoryClient()
} else {
log.Fatal("Must specify a valid persistent store (currently " +
"supporting etcdV2) or no persistence.")
}
enableKubernetes = *k8sPod || *k8sAPIServer != ""
}
func main() {
log.WithFields(log.Fields{
"version": config.OrchestratorVersion.String(),
"build_time": config.BuildTime,
}).Info("Running Trident storage orchestrator.")
frontends := make([]frontend.FrontendPlugin, 0)
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
processCmdLineArgs()
orchestrator := core.NewTridentOrchestrator(storeClient)
if enableKubernetes {
var (
kubernetesFrontend frontend.FrontendPlugin
err error
)
if *k8sAPIServer != "" {
kubernetesFrontend, err = kubernetes.NewPlugin(orchestrator, *k8sAPIServer, *k8sConfigPath)
} else {
kubernetesFrontend, err = kubernetes.NewPluginInCluster(orchestrator)
}
if err != nil {
log.Fatal("Unable to start the Kubernetes frontend: ", err)
}
orchestrator.AddFrontend(kubernetesFrontend)
frontends = append(frontends, kubernetesFrontend)
}
restServer := rest.NewAPIServer(orchestrator, *address, *port)
frontends = append(frontends, restServer)
// Bootstrapping the orchestrator
if err := orchestrator.Bootstrap(); err != nil {
log.Fatal(err.Error())
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
for _, frontend := range frontends {
frontend.Activate()
}
<-c
log.Info("Shutting down.")
for _, frontend := range frontends {
frontend.Deactivate()
}
}