forked from alanbover/deathnode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (88 loc) · 3.62 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
113
package main
import (
"flag"
"time"
"github.com/alanbover/deathnode/aurora"
"github.com/alanbover/deathnode/aws"
"github.com/alanbover/deathnode/context"
"github.com/alanbover/deathnode/deathnode"
"github.com/alanbover/deathnode/mesos"
"github.com/benbjohnson/clock"
log "github.com/sirupsen/logrus"
)
var accessKey, secretKey, region, iamRole, iamSession, mesosURL string
var debug bool
var pollingSeconds int
func main() {
ctx := &context.ApplicationContext{Clock: clock.New()}
initFlags(ctx)
enforceFlags(ctx)
log.SetLevel(log.InfoLevel)
if debug {
log.SetLevel(log.DebugLevel)
}
// Create the monitors for autoscaling groups
if awsConn, err := aws.NewClient(accessKey, secretKey, region, iamRole, iamSession); err != nil {
log.Fatal("Error connecting to AWS: ", err)
} else {
ctx.AwsConn = awsConn
}
// Create the Mesos monitor
ctx.MesosConn = &mesos.Client{
MasterURL: mesosURL,
LeaderURL: mesosURL,
}
ctx.AuroraConn = &aurora.Client{
AuroraURL: ctx.Conf.AuroraURL,
}
// Create deathnoteWatcher
deathNodeWatcher := deathnode.NewWatcher(ctx)
ticker := time.NewTicker(time.Second * time.Duration(pollingSeconds))
for {
go deathNodeWatcher.Run()
<-ticker.C
}
}
func initFlags(context *context.ApplicationContext) {
flag.StringVar(&accessKey, "accessKey", "", "AWS_ACCESS_KEY_ID.")
flag.StringVar(&secretKey, "secretKey", "", "AWS_SECRET_ACCESS_KEY.")
flag.StringVar(®ion, "region", "eu-west-1", "AWS_REGION.")
flag.StringVar(&iamRole, "iamRole", "", "IAMROLE to assume.")
flag.StringVar(&iamSession, "iamSession", "", "Session for IAMROLE.")
flag.BoolVar(&debug, "debug", false, "Enable debug logging.")
flag.StringVar(&mesosURL, "mesosUrl", "", "The URL for Mesos master.")
flag.StringVar(&context.Conf.AuroraURL, "auroraUrl", "", "The URL to the Aurora json API (apibeta)")
flag.Var(&context.Conf.AutoscalingGroupPrefixes, "autoscalingGroupName", "An autoscalingGroup prefix for monitor.")
flag.Var(&context.Conf.ProtectedFrameworks, "protectedFrameworks", "The mesos frameworks to wait for kill the node.")
flag.Var(&context.Conf.ProtectedTasksLabels, "protectedTaskLabels", "The labels used for protected tasks.")
flag.Var(
&context.Conf.ConstraintsType, "constraintsType", "The constrainst implementation to use.")
flag.StringVar(
&context.Conf.RecommenderType, "recommenderType", "firstAvailableAgent", "The recommender implementation to use.")
flag.StringVar(
&context.Conf.DeathNodeMark, "deathNodeMark", "DEATH_NODE_MARK", "The tag to apply for instances to be deleted.")
flag.BoolVar(&context.Conf.ResetLifecycle, "resetLifecycle", false, "Reset lifecycle when it's close to expire.")
flag.IntVar(&pollingSeconds, "polling", 60, "Seconds between executions.")
flag.IntVar(&context.Conf.LifecycleTimeout, "lifecycleTimeout", 3600, "the Terminating:Wait lifecycle timeout period.")
flag.BoolVar(&context.Conf.ForceLifeCycleHook, "forceLifecycleHook", false, "force (overwrite) all lifecycle hooks (ensures they match desired timeouts)")
flag.IntVar(&context.Conf.DelayDeleteSeconds, "delayDelete", 0, "Time to wait between kill executions (in seconds).")
flag.Parse()
}
func enforceFlags(context *context.ApplicationContext) {
if mesosURL == "" {
flag.Usage()
log.Fatal("mesosUrl flag is required")
}
if len(context.Conf.AutoscalingGroupPrefixes) < 1 {
flag.Usage()
log.Fatal("at least one autoscalingGroupName flag is required")
}
if len(context.Conf.ProtectedFrameworks) < 1 {
flag.Usage()
log.Fatal("at least one protectedFrameworks flag is required")
}
if len(context.Conf.ConstraintsType) < 1 {
flag.Usage()
log.Fatal("at least one constraintsType flag is required")
}
}