From fcba7c3e5fc39f3ad5d91372f68b43ca1c5b0a72 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Mon, 23 May 2016 14:54:00 -0700 Subject: [PATCH] added dns-port flag to have a custom DNS port for skydns to serve DNS requests on. updated imports --- cmd/kube-dns/app/options/options.go | 3 +++ cmd/kube-dns/app/server.go | 7 +++++-- pkg/dns/dns.go | 21 ++++++++++----------- pkg/dns/dns_test.go | 13 ++++++------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/cmd/kube-dns/app/options/options.go b/cmd/kube-dns/app/options/options.go index 7a56138e796fa..8f57124645e4a 100644 --- a/cmd/kube-dns/app/options/options.go +++ b/cmd/kube-dns/app/options/options.go @@ -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 } @@ -43,6 +44,7 @@ func NewKubeDNSConfig() *KubeDNSConfig { KubeConfigFile: "", KubeMasterURL: "", HealthzPort: 8081, + DNSPort: 53, Federations: make(map[string]string), } } @@ -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\"") } diff --git a/cmd/kube-dns/app/server.go b/cmd/kube-dns/app/server.go index 9cfcb49b5c8de..e16439ff9dcda 100644 --- a/cmd/kube-dns/app/server.go +++ b/cmd/kube-dns/app/server.go @@ -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" @@ -38,6 +38,7 @@ type KubeDNSServer struct { // DNS domain name. domain string healthzPort int + dnsPort int kd *kdns.KubeDNS } @@ -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 } @@ -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 { diff --git a/pkg/dns/dns.go b/pkg/dns/dns.go index ad42a330c479e..9c0ab0de33218 100644 --- a/pkg/dns/dns.go +++ b/pkg/dns/dns.go @@ -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" @@ -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 @@ -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, @@ -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, @@ -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 { diff --git a/pkg/dns/dns_test.go b/pkg/dns/dns_test.go index 4b4fcdcee8131..86c0594797ca2 100644 --- a/pkg/dns/dns_test.go +++ b/pkg/dns/dns_test.go @@ -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 ( @@ -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