-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
59 lines (50 loc) · 1.21 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
package main
import (
"context"
"net/http"
"os"
modeutils "github.com/deis/steward/mode/utils"
"github.com/deis/steward/web/api"
"github.com/juju/loggo"
)
var (
logger = loggo.GetLogger("")
version = "dev"
)
func exitWithCode(cancelFn func(), exitCode int) {
cancelFn()
os.Exit(exitCode)
}
func main() {
logger.Infof("steward version %s started", version)
cfg, err := getRootConfig()
if err != nil {
logger.Criticalf("error getting config (%s)", err)
os.Exit(1)
}
logger.SetLogLevel(cfg.logLevel())
errCh := make(chan error)
rootCtx := context.Background()
httpCl := http.DefaultClient
ctx, cancelFn := context.WithCancel(rootCtx)
defer cancelFn()
cleanup, err := modeutils.Run(ctx, httpCl, cfg.Mode, cfg.BrokerName, errCh, cfg.WatchNamespaces)
if err != nil {
logger.Criticalf("Error starting %s mode: %s", cfg.Mode, err)
exitWithCode(cancelFn, 1)
}
defer cleanup()
// Start the API server
go api.Serve(errCh)
// TODO: listen for signal and delete all service catalog entries before quitting
select {
case err := <-errCh:
if err != nil {
logger.Criticalf("%s", err)
exitWithCode(cancelFn, 1)
} else {
logger.Criticalf("unknown error, crashing")
exitWithCode(cancelFn, 1)
}
}
}