-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (46 loc) · 1.37 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
package main
// TODO: improve comments and integrate with coveralls/goreport
import (
"os"
"os/signal"
"syscall"
"time"
"math/rand"
"github.com/ideahitme/cluster-autoscaler/cloudprovider"
"github.com/ideahitme/cluster-autoscaler/controller"
"github.com/ideahitme/cluster-autoscaler/kube"
"github.com/ideahitme/cluster-autoscaler/logger"
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
stopCh := make(chan struct{}, 1)
cfg := newConfig()
cfg.parse()
if err := cfg.validate(); err != nil {
logger.Log.Fatal("invalid configuration", zap.Error(err))
}
config, err := clientcmd.BuildConfigFromFlags("", cfg.kubeConfig)
if err != nil {
logger.Log.Fatal("failed to create k8s config", zap.Error(err))
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
logger.Log.Fatal("failed to create k8s client", zap.Error(err))
}
kubemanager := kube.NewManager(clientset)
cloudmanager, err := cloudprovider.NewAWSCloudProvider()
if err != nil {
logger.Log.Fatal("failed to create cloud provider manager", zap.Error(err))
}
go controller.Run(stopCh, cloudmanager, kubemanager)
handleSIGTERM(stopCh)
}
func handleSIGTERM(stopCh chan struct{}) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
<-signals
close(stopCh)
}