in cmd/node-cache/main.go [72:130]
func parseAndValidateFlags() (*app.ConfigParams, error) {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Runs CoreDNS v%s as a nodelocal cache listening on the specified ip:port\n\n", corednsmain.CoreVersion)
flag.PrintDefaults()
}
params := &app.ConfigParams{LocalPort: "53"}
flag.StringVar(¶ms.LocalIPStr, "localip", "", "comma-separated string of ip addresses to bind dnscache to")
flag.BoolVar(¶ms.SetupInterface, "setupinterface", true, "indicates whether network interface should be setup")
flag.StringVar(¶ms.InterfaceName, "interfacename", "nodelocaldns", "name of the interface to be created")
flag.DurationVar(¶ms.Interval, "syncinterval", 60, "interval(in seconds) to check for iptables rules")
flag.StringVar(¶ms.MetricsListenAddress, "metrics-listen-address", "0.0.0.0:9353", "address to serve metrics on")
flag.BoolVar(¶ms.SetupIptables, "setupiptables", true, "indicates whether iptables rules should be setup")
flag.StringVar(¶ms.BaseCoreFile, "basecorefile", "/etc/coredns/Corefile.base", "Path to the template Corefile for node-cache")
flag.StringVar(¶ms.CoreFile, "corefile", "/etc/Corefile", "Path to the Corefile to be used by node-cache")
flag.StringVar(¶ms.KubednsCMPath, "kubednscm", "", "Path where the kube-dns configmap will be mounted")
flag.StringVar(¶ms.UpstreamSvcName, "upstreamsvc", "kube-dns", "Service name whose cluster IP is upstream for node-cache")
flag.StringVar(¶ms.HealthPort, "health-port", "8080", "port used by health plugin")
flag.BoolVar(¶ms.SkipTeardown, "skipteardown", false, "indicates whether iptables rules should be torn down on exit")
flag.Parse()
for _, ipstr := range strings.Split(params.LocalIPStr, ",") {
newIP := net.ParseIP(ipstr)
if newIP == nil {
return params, fmt.Errorf("invalid localip specified - %q", ipstr)
}
params.LocalIPs = append(params.LocalIPs, newIP)
}
// validate all the IPs have the same IP family
for _, ip := range params.LocalIPs {
if utilnet.IsIPv6(params.LocalIPs[0]) != utilnet.IsIPv6(ip) {
return params, fmt.Errorf("unexpected IP Family for localIP - %q, want IPv6=%v", ip, utilnet.IsIPv6(params.LocalIPs[0]))
}
}
// lookup specified dns port
f := flag.Lookup("dns.port")
if f == nil {
return nil, fmt.Errorf("failed to lookup \"dns.port\" parameter")
}
params.LocalPort = f.Value.String()
if _, err := strconv.Atoi(params.LocalPort); err != nil {
return nil, fmt.Errorf("invalid port specified - %q", params.LocalPort)
}
if _, err := strconv.Atoi(params.HealthPort); err != nil {
return nil, fmt.Errorf("invalid healthcheck port specified - %q", params.HealthPort)
}
if f = flag.Lookup("conf"); f != nil {
params.CoreFile = f.Value.String()
clog.Infof("Using Corefile %s", params.CoreFile)
}
if f = flag.Lookup("pidfile"); f != nil {
params.Pidfile = f.Value.String()
clog.Infof("Using Pidfile %s", params.Pidfile)
}
return params, nil
}