-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
61 lines (51 loc) · 1.44 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 (
"log"
"os"
"strings"
"time"
env "github.com/caarlos0/env/v6"
)
func main() {
configs := getConfigs()
// get a kube connection
readinessHandler, err := kubeGetReadinessHandler(configs.KubernetesEnabled, configs.IgnoreDaemonSets, configs.DeleteLocalData)
if err != nil {
log.Fatalf("Error getting kubernetes readiness handler when required: %v", err)
}
// get the AWS sessions
ec2Svc, asgSvc, err := awsGetServices()
if err != nil {
log.Fatalf("Unable to create an AWS session: %v", err)
}
// to keep track of original target sizes during rolling updates
originalDesired := map[string]int64{}
// infinite loop
for {
err := adjust(
configs.KubernetesEnabled, configs.ASGS, ec2Svc, asgSvc,
readinessHandler, originalDesired, configs.OriginalDesiredOnTag,
configs.IncreaseMax, configs.Verbose, configs.Drain, configs.DrainForce,
)
if err != nil {
log.Printf("Error adjusting AutoScaling Groups: %v", err)
}
// delay with each loop
log.Printf("Sleeping %v\n", configs.Interval)
time.Sleep(configs.Interval)
}
}
func getConfigs() (configs Configs) {
// Compat helper
val, ok := os.LookupEnv("ROLLER_CHECK_DELAY")
if ok {
// Use value from check delay to set an interval
if !strings.HasSuffix(val, "s") {
os.Setenv("ROLLER_INTERVAL", val+"s")
}
}
if err := env.Parse(&configs); err != nil {
log.Panicf("unexpected error while initializing the config: %v", err)
}
return configs
}