forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
64 lines (55 loc) · 1.67 KB
/
server.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
package dns
import (
"github.com/golang/glog"
"github.com/skynetservices/skydns/server"
client "k8s.io/kubernetes/pkg/client/unversioned"
)
// NewServerDefaults returns the default SkyDNS server configuration for a DNS server.
func NewServerDefaults() (*server.Config, error) {
config := &server.Config{
Domain: "cluster.local.",
Local: "openshift.default.svc.cluster.local.",
Verbose: bool(glog.V(4)),
}
return config, server.SetDefaults(config)
}
type Server struct {
Config *server.Config
Services ServiceAccessor
Endpoints client.EndpointsNamespacer
MetricsName string
Stop chan struct{}
}
// NewServer creates a server from the provided config and client.
func NewServer(config *server.Config, client *client.Client) *Server {
stop := make(chan struct{})
return &Server{
Config: config,
Services: NewCachedServiceAccessor(client, stop),
Endpoints: client,
Stop: stop,
}
}
// ListenAndServe starts a DNS server that exposes services and values stored in etcd (if etcdclient
// is not nil). It will block until the server exits.
func (s *Server) ListenAndServe() error {
resolver := NewServiceResolver(s.Config, s.Services, s.Endpoints, openshiftFallback)
resolvers := server.FirstBackend{resolver}
if len(s.MetricsName) > 0 {
server.RegisterMetrics(s.MetricsName, "")
}
dns := server.New(resolvers, s.Config)
if s.Stop != nil {
defer close(s.Stop)
}
return dns.Run()
}
func openshiftFallback(name string, exact bool) (string, bool) {
if name == "openshift.default.svc" {
return "kubernetes.default.svc.", true
}
if name == "_endpoints.openshift.default.svc" {
return "_endpoints.kubernetes.default.", true
}
return "", false
}