This repository has been archived by the owner on Sep 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
96 lines (81 loc) · 2.2 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
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/zalando-incubator/mate/consumers"
"github.com/zalando-incubator/mate/controller"
"github.com/zalando-incubator/mate/producers"
)
var version = "Unknown"
func main() {
cfg := newConfig(version)
cfg.parseFlags()
if err := cfg.validate(); err != nil {
log.Fatalf("Misconfiguration error: %v", err)
}
if cfg.debug {
log.SetLevel(log.DebugLevel)
}
p, err := newProducer(cfg)
if err != nil {
log.Fatalf("Error creating producer: %v", err)
}
c, err := newSynchronizedConsumer(cfg)
if err != nil {
log.Fatalf("Error creating consumer: %v", err)
}
opts := &controller.Options{
SyncOnly: cfg.syncOnly,
}
ctrl := controller.New(p, c, opts)
errors := ctrl.Run()
go func() {
for {
log.Error(<-errors)
}
}()
ctrl.Wait()
}
func newSynchronizedConsumer(cfg *mateConfig) (consumers.Consumer, error) {
var consumer consumers.Consumer
var err error
switch cfg.consumer {
case "google":
consumer, err = consumers.NewGoogleCloudDNSConsumer(cfg.googleProject, cfg.googleRecordGroupID)
case "aws":
consumer, err = consumers.NewAWSRoute53Consumer(cfg.awsRecordGroupID)
case "stdout":
consumer, err = consumers.NewStdoutConsumer()
default:
return nil, fmt.Errorf("Unknown consumer '%s'.", cfg.consumer)
}
if err != nil {
return nil, err
}
return consumers.NewSynchronizedConsumer(consumer)
}
func newProducer(cfg *mateConfig) (producers.Producer, error) {
switch cfg.producer {
case "kubernetes":
kubeConfig := &producers.KubernetesOptions{
Format: cfg.kubernetesFormat,
APIServer: cfg.kubernetesServer,
TrackNodePorts: cfg.kubernetesTrackNodePorts,
Filter: cfg.kubernetesFilter,
}
return producers.NewKubernetesProducer(kubeConfig)
case "fake":
fakeConfig := &producers.FakeProducerOptions{
DNSName: cfg.fakeDNSName,
FixedDNSName: cfg.fakeFixedDNSName,
FixedHostname: cfg.fakeFixedHostname,
FixedIP: cfg.fakeFixedIP,
Mode: cfg.fakeMode,
TargetDomain: cfg.fakeTargetDomain,
}
return producers.NewFakeProducer(fakeConfig)
case "null":
return producers.NewNullProducer()
}
return nil, fmt.Errorf("Unknown producer '%s'.", cfg.producer)
}