Skip to content

Commit

Permalink
fix pod hostname to be podname for dns srv records
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank Kumar committed May 18, 2018
1 parent 71f9bf5 commit f090793
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/dns/dns.go
Expand Up @@ -567,6 +567,12 @@ func (kd *KubeDNS) generateRecordsForHeadlessService(e *v1.Endpoints, svc *v1.Se
}

func getHostname(address *v1.EndpointAddress) (string, bool) {
// if targetRef is a POD we will always use the pod name
if address.TargetRef != nil {
if address.TargetRef.Kind == "Pod" {
return address.TargetRef.Name, true
}
}
if len(address.Hostname) > 0 {
return address.Hostname, true
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/dns/dns_test.go
Expand Up @@ -1016,3 +1016,18 @@ func getPodsFQDN(kd *KubeDNS, e *v1.Endpoints, podHostName string) string {
func getSRVFQDN(kd *KubeDNS, s *v1.Service, portName string) string {
return fmt.Sprintf("_%s._tcp.%s.%s.svc.%s", portName, s.Name, s.Namespace, kd.domain)
}

func TestgetHostName(t *testing.T) {
endpointAddress := v1.EndpointAddress{
IP: "10.0.0.1",
TargetRef: &v1.ObjectReference{
Kind: "Pod",
Name: "foo-bar-zah",
Namespace: testNamespace,
},
Hostname: "foo",
}
hostname, found := getHostname(&endpointAddress)
assert.True(t, found)
assert.Equal(t, hostname, "foo-bar-zah")
}

0 comments on commit f090793

Please sign in to comment.