-
Notifications
You must be signed in to change notification settings - Fork 3
/
runner.go
71 lines (62 loc) · 1.55 KB
/
runner.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
package runner
import (
"context"
"errors"
"time"
"github.com/deis/steward-framework"
"github.com/deis/steward-framework/k8s"
"github.com/deis/steward-framework/k8s/clients"
"github.com/deis/steward-framework/k8s/tprs"
"github.com/deis/steward-framework/web/api"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
// Run starts all event and control loops. Steward Framework implementations should invoke this
// function LAST in their main() function and can rely upon this function to block program
// their program from exiting until a fatal error is encountered.
func Run(
cataloger framework.Cataloger,
lifecycler framework.Lifecycler,
maxAsyncDuration time.Duration,
apiPort int,
) error {
config, err := rest.InClusterConfig()
if err != nil {
return errGettingK8sConfig{Original: err}
}
k8sClient, err := kubernetes.NewForConfig(config)
if err != nil {
return errGettingK8sClient{Original: err}
}
dynClient, err := clients.NewDynamic(*config)
if err != nil {
return errGettingDynamicClient{Original: err}
}
if err := tprs.Ensure3PRs(k8sClient); err != nil {
return err
}
rootCtx := context.Background()
ctx, cancelFn := context.WithCancel(rootCtx)
defer cancelFn()
errCh := make(chan error)
go k8s.StartControlLoops(
ctx,
k8sClient,
dynClient,
cataloger,
lifecycler,
k8s.GlobalNamespace,
errCh,
)
go api.Serve(apiPort, errCh)
select {
case err := <-errCh:
if err != nil {
logger.Criticalf(err.Error())
return err
}
msg := "unknown error, crashing"
logger.Criticalf(msg)
return errors.New(msg)
}
}