Skip to content

Commit

Permalink
added dns-port flag to have a custom DNS port for skydns to serve DNS…
Browse files Browse the repository at this point in the history
… requests on. updated imports
  • Loading branch information
ArtfulCoder committed May 23, 2016
1 parent 4215fe5 commit fcba7c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
3 changes: 3 additions & 0 deletions cmd/kube-dns/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type KubeDNSConfig struct {
KubeConfigFile string
KubeMasterURL string
HealthzPort int
DNSPort int
// Federations maps federation names to their registered domain names.
Federations map[string]string
}
Expand All @@ -43,6 +44,7 @@ func NewKubeDNSConfig() *KubeDNSConfig {
KubeConfigFile: "",
KubeMasterURL: "",
HealthzPort: 8081,
DNSPort: 53,
Federations: make(map[string]string),
}
}
Expand Down Expand Up @@ -140,5 +142,6 @@ func (s *KubeDNSConfig) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.KubeConfigFile, "kubecfg-file", s.KubeConfigFile, "Location of kubecfg file for access to kubernetes master service; --kube-master-url overrides the URL part of this; if neither this nor --kube-master-url are provided, defaults to service account tokens")
fs.Var(kubeMasterURLVar{&s.KubeMasterURL}, "kube-master-url", "URL to reach kubernetes master. Env variables in this flag will be expanded.")
fs.IntVar(&s.HealthzPort, "healthz-port", s.HealthzPort, "port on which to serve a kube-dns HTTP readiness probe.")
fs.IntVar(&s.DNSPort, "dns-port", s.DNSPort, "port on which to serve DNS requests.")
fs.Var(federationsVar{s.Federations}, "federations", "a comma separated list of the federation names and their corresponding domain names to which this cluster belongs. Example: \"myfederation1=example.com,myfederation2=example2.com,myfederation3=example.com\"")
}
7 changes: 5 additions & 2 deletions cmd/kube-dns/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/skynetservices/skydns/server"
"k8s.io/kubernetes/cmd/kube-dns/app/options"
"k8s.io/kubernetes/pkg/api/unversioned"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
kclientcmd "k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
kdns "k8s.io/kubernetes/pkg/dns"
Expand All @@ -38,6 +38,7 @@ type KubeDNSServer struct {
// DNS domain name.
domain string
healthzPort int
dnsPort int
kd *kdns.KubeDNS
}

Expand All @@ -51,6 +52,7 @@ func NewKubeDNSServerDefault(config *options.KubeDNSConfig) *KubeDNSServer {
glog.Fatalf("Failed to create a kubernetes client: %v", err)
}
ks.healthzPort = config.HealthzPort
ks.dnsPort = config.DNSPort
ks.kd = kdns.NewKubeDNS(kubeClient, config.ClusterDomain, config.Federations)
return &ks
}
Expand Down Expand Up @@ -124,7 +126,8 @@ func setupSignalHandlers() {
}

func (d *KubeDNSServer) startSkyDNSServer() {
skydnsConfig := &server.Config{Domain: d.domain, DnsAddr: "0.0.0.0:53"}
glog.Infof("Starting SkyDNS server. Listening on port:%d", d.dnsPort)
skydnsConfig := &server.Config{Domain: d.domain, DnsAddr: fmt.Sprintf("0.0.0.0:%d", d.dnsPort)}
server.SetDefaults(skydnsConfig)
s := server.New(d.kd, skydnsConfig)
if err := metrics.Metrics(); err != nil {
Expand Down
21 changes: 10 additions & 11 deletions pkg/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/endpoints"
"k8s.io/kubernetes/pkg/api/unversioned"
v1 "k8s.io/kubernetes/pkg/api/v1"
kcache "k8s.io/kubernetes/pkg/client/cache"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
kframework "k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/validation"
Expand Down Expand Up @@ -129,7 +128,7 @@ func (kd *KubeDNS) Start() {
kd.waitForKubernetesService()
}

func (kd *KubeDNS) waitForKubernetesService() (svc *v1.Service) {
func (kd *KubeDNS) waitForKubernetesService() (svc *kapi.Service) {
name := fmt.Sprintf("%v/%v", kapi.NamespaceDefault, kubernetesSvcName)
glog.Infof("Waiting for service: %v", name)
var err error
Expand Down Expand Up @@ -158,13 +157,13 @@ func (kd *KubeDNS) setServicesStore() {
kd.servicesStore, kd.serviceController = kframework.NewInformer(
&kcache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return kd.kubeClient.Core().Services(v1.NamespaceAll).List(options)
return kd.kubeClient.Core().Services(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return kd.kubeClient.Core().Services(v1.NamespaceAll).Watch(options)
return kd.kubeClient.Core().Services(kapi.NamespaceAll).Watch(options)
},
},
&v1.Service{},
&kapi.Service{},
resyncPeriod,
kframework.ResourceEventHandlerFuncs{
AddFunc: kd.newService,
Expand All @@ -179,13 +178,13 @@ func (kd *KubeDNS) setEndpointsStore() {
kd.endpointsStore, kd.endpointsController = kframework.NewInformer(
&kcache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return kd.kubeClient.Core().Endpoints(v1.NamespaceAll).List(options)
return kd.kubeClient.Core().Endpoints(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return kd.kubeClient.Core().Endpoints(v1.NamespaceAll).Watch(options)
return kd.kubeClient.Core().Endpoints(kapi.NamespaceAll).Watch(options)
},
},
&v1.Endpoints{},
&kapi.Endpoints{},
resyncPeriod,
kframework.ResourceEventHandlerFuncs{
AddFunc: kd.handleEndpointAdd,
Expand Down Expand Up @@ -565,12 +564,12 @@ func (kd *KubeDNS) federationRecords(queryPath []string) ([]skymsg.Service, erro
// simpler approach here.
// Also note that zone here means the zone in cloud provider terminology, not the DNS zone.
func (kd *KubeDNS) getClusterZone() (string, error) {
var node *v1.Node
var node *kapi.Node

objs := kd.nodesStore.List()
if len(objs) > 0 {
var ok bool
if node, ok = objs[0].(*v1.Node); !ok {
if node, ok = objs[0].(*kapi.Node); !ok {
return "", fmt.Errorf("expected node object, got: %T", objs[0])
}
} else {
Expand Down
13 changes: 6 additions & 7 deletions pkg/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import (
"github.com/stretchr/testify/require"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
v1 "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/cache"
fake "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3/fake"
fake "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
)

const (
Expand Down Expand Up @@ -276,17 +275,17 @@ func testInvalidFederationQueries(t *testing.T, kd *KubeDNS) {
}
}

func newNodes() *v1.NodeList {
return &v1.NodeList{
Items: []v1.Node{
func newNodes() *kapi.NodeList {
return &kapi.NodeList{
Items: []kapi.Node{
// Node without annotation.
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: kapi.ObjectMeta{
Name: "testnode-0",
},
},
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: kapi.ObjectMeta{
Name: "testnode-1",
Annotations: map[string]string{
// Note: The zone name here is an arbitrary string and doesn't exactly follow the
Expand Down

0 comments on commit fcba7c3

Please sign in to comment.