forked from jtblin/kube2iam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (52 loc) · 2.28 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
package main
import (
"runtime"
"time"
log "github.com/Sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/jtblin/kube2iam/cmd"
"github.com/jtblin/kube2iam/iptables"
"github.com/jtblin/kube2iam/version"
)
const (
defaultMaxInterval = 1 * time.Second
defaultMaxElapsedTime = 2 * time.Second
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
s := cmd.NewServer()
addFlags(s, pflag.CommandLine)
pflag.Parse()
if s.Verbose {
log.SetLevel(log.DebugLevel)
}
if s.Version {
version.PrintVersionAndExit()
}
if s.AddIPTablesRule {
if err := iptables.AddRule(s.AppPort, s.MetadataAddress, s.HostInterface, s.HostIP); err != nil {
log.Fatal(err)
}
}
if err := s.Run(s.APIServer, s.APIToken, s.Insecure); err != nil {
log.Fatal(err)
}
}
// addFlags adds the command line flags.
func addFlags(s *cmd.Server, fs *pflag.FlagSet) {
fs.StringVar(&s.APIServer, "api-server", s.APIServer, "Endpoint for the api server")
fs.StringVar(&s.APIToken, "api-token", s.APIToken, "Token to authenticate with the api server")
fs.StringVar(&s.AppPort, "app-port", s.AppPort, "Http port")
fs.StringVar(&s.BaseRoleARN, "base-role-arn", s.BaseRoleARN, "Base role ARN")
fs.StringVar(&s.DefaultIAMRole, "default-role", s.DefaultIAMRole, "Fallback role to use when annotation is not set")
fs.StringVar(&s.IAMRoleKey, "iam-role-key", s.IAMRoleKey, "Pod annotation key used to retrieve the IAM role")
fs.BoolVar(&s.Insecure, "insecure", false, "Kubernetes server should be accessed without verifying the TLS. Testing only")
fs.StringVar(&s.MetadataAddress, "metadata-addr", s.MetadataAddress, "Address for the ec2 metadata")
fs.BoolVar(&s.AddIPTablesRule, "iptables", false, "Add iptables rule (also requires --host-ip)")
fs.StringVar(&s.HostInterface, "host-interface", "docker0", "Host interface for proxying AWS metadata")
fs.StringVar(&s.HostIP, "host-ip", s.HostIP, "IP address of host")
fs.DurationVar(&s.BackoffMaxInterval, "backoff-max-interval", defaultMaxInterval, "Max interval for backoff when querying for role.")
fs.DurationVar(&s.BackoffMaxElapsedTime, "backoff-max-elapsed-time", defaultMaxElapsedTime, "Max elapsed time for backoff when querying for role.")
fs.BoolVar(&s.Verbose, "verbose", false, "Verbose")
fs.BoolVar(&s.Version, "version", false, "Print the version and exits")
}