-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
74 lines (55 loc) · 1.48 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
package main
import (
"flag"
"strings"
_ "github.com/michaelkipper/istio-client-go/pkg/client/clientset/versioned/typed/networking/v1alpha3"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
"github.com/istio-ecosystem/dns-discovery/dns"
"github.com/istio-ecosystem/dns-discovery/istio"
)
type flags struct {
address string
zones string
forward string
loglevel string
}
func main() {
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGSTOP, syscall.SIGTERM)
flags := parseFlags()
var zones []string
for _, zone := range strings.Split(flags.zones, ",") {
log.Infof("skipping zone %s", zone)
zones = append(zones, zone)
}
server := dns.NewServer(dns.NewProxy(flags.forward), istio.New(), zones)
server.Start(flags.address, "udp", func() {
log.Infof("listening on %s", flags.address)
})
defer server.Stop()
<-sig
}
func parseFlags() *flags {
flags := flags{}
flag.StringVar(&flags.address, "address", "localhost:53", "Listen address (ip:port)")
flag.StringVar(&flags.zones, "zones", "", "Kubernetes authoritative zones")
flag.StringVar(&flags.forward, "forward", "", "DNS server address (required)")
flag.StringVar(&flags.loglevel, "loglevel", "info", "set log level")
flag.Parse()
if flags.zones == "" || flags.forward == "" {
flag.Usage()
os.Exit(1)
}
setLogLevel(flags.loglevel)
return &flags
}
func setLogLevel(levelname string) {
level, err := log.ParseLevel(levelname)
if err != nil {
log.Fatal(err)
}
log.SetLevel(level)
}