diff --git a/source/compatibility.go b/source/compatibility.go index b37348a896..25c0e1fc88 100644 --- a/source/compatibility.go +++ b/source/compatibility.go @@ -17,6 +17,8 @@ limitations under the License. package source import ( + "strings" + "k8s.io/client-go/pkg/api/v1" "github.com/kubernetes-incubator/external-dns/endpoint" @@ -75,18 +77,22 @@ func legacyEndpointsFromMoleculeService(svc *v1.Service) []*endpoint.Endpoint { } // Get the desired hostname of the service from the annotation. - hostname, exists := svc.Annotations[moleculeAnnotationKey] + hostnameAnnotation, exists := svc.Annotations[moleculeAnnotationKey] if !exists { return nil } - // Create a corresponding endpoint for each configured external entrypoint. - for _, lb := range svc.Status.LoadBalancer.Ingress { - if lb.IP != "" { - endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, "")) - } - if lb.Hostname != "" { - endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, "")) + hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",") + + for _, hostname := range hostnameList { + // Create a corresponding endpoint for each configured external entrypoint. + for _, lb := range svc.Status.LoadBalancer.Ingress { + if lb.IP != "" { + endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, "")) + } + if lb.Hostname != "" { + endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, "")) + } } } diff --git a/source/service_test.go b/source/service_test.go index 1e21bd7821..0d63716de4 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -355,11 +355,12 @@ func testServiceSourceEndpoints(t *testing.T) { "dns": "route53", }, map[string]string{ - "domainName": "foo.example.org.", + "domainName": "foo.example.org., bar.example.org", }, []string{"1.2.3.4"}, []*endpoint.Endpoint{ {DNSName: "foo.example.org", Target: "1.2.3.4"}, + {DNSName: "bar.example.org", Target: "1.2.3.4"}, }, false, },