From 7464af5dcc2c27299142fbcb57235140805a2368 Mon Sep 17 00:00:00 2001 From: Nils Juenemann Date: Fri, 30 Jun 2017 01:07:22 +0200 Subject: [PATCH 1/5] service source: support for multiple hostnames per annotation --- source/service.go | 34 +++++++++++++++++++++++++--------- source/service_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/source/service.go b/source/service.go index e483a0e46d..6fbe8e5bd3 100644 --- a/source/service.go +++ b/source/service.go @@ -138,21 +138,37 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint { var endpoints []*endpoint.Endpoint // Get the desired hostname of the service from the annotation. - hostname, exists := svc.Annotations[hostnameAnnotationKey] + hostnameAnnotation, exists := svc.Annotations[hostnameAnnotationKey] if !exists { return nil } - // Create a corresponding endpoint for each configured external entrypoint. - for _, lb := range svc.Status.LoadBalancer.Ingress { - if lb.IP != "" { - //TODO(ideahitme): consider retrieving record type from resource annotation instead of empty - endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, "")) - } - if lb.Hostname != "" { - endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, "")) + hostnames := parseHostnameAnnotation(hostnameAnnotation) + + for _, hostname := range hostnames { + // Create a corresponding endpoint for each configured external entrypoint. + for _, lb := range svc.Status.LoadBalancer.Ingress { + if lb.IP != "" { + //TODO(ideahitme): consider retrieving record type from resource annotation instead of empty + endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, "")) + } + if lb.Hostname != "" { + endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, "")) + } } } return endpoints } + +// parseHostnameAnnotation splits the hostname annontation and removes the trailing periods +func parseHostnameAnnotation(hostnameAnnotation string) (hostnames []string) { + + hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",") + + for _, hostname := range hostnameList { + hostnames = append(hostnames, strings.TrimSuffix(hostname, ".")) + } + + return +} \ No newline at end of file diff --git a/source/service_test.go b/source/service_test.go index 3aa04c197d..0b5c73b677 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -120,6 +120,42 @@ func testServiceSourceEndpoints(t *testing.T) { }, false, }, + { + "annotated services with multiple hostnames return an endpoint with target IP", + "", + "testing", + "foo", + "", + "", + map[string]string{}, + map[string]string{ + hostnameAnnotationKey: "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, + }, + { + "annotated services with multiple hostnames and without trailing period return an endpoint with target IP", + "", + "testing", + "foo", + "", + "", + map[string]string{}, + map[string]string{ + hostnameAnnotationKey: "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, + }, { "annotated services return an endpoint with target hostname", "", From a111fecb1f541cbf7ea44916ae71016f051c1c27 Mon Sep 17 00:00:00 2001 From: Nils Juenemann Date: Fri, 30 Jun 2017 09:29:27 +0200 Subject: [PATCH 2/5] go fmt --- source/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/service.go b/source/service.go index 6fbe8e5bd3..a074862706 100644 --- a/source/service.go +++ b/source/service.go @@ -171,4 +171,4 @@ func parseHostnameAnnotation(hostnameAnnotation string) (hostnames []string) { } return -} \ No newline at end of file +} From bd1a126618e17e95f7ba987144e77dd2e1cd6b1a Mon Sep 17 00:00:00 2001 From: Nils Juenemann Date: Tue, 4 Jul 2017 16:34:19 +0200 Subject: [PATCH 3/5] Make parseHostnameAnnontations inline --- source/service.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/source/service.go b/source/service.go index a074862706..c3d6511e5d 100644 --- a/source/service.go +++ b/source/service.go @@ -143,9 +143,11 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint { return nil } - hostnames := parseHostnameAnnotation(hostnameAnnotation) + // splits the hostname annotation and removes the trailing periods + hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",") - for _, hostname := range hostnames { + for _, hostname := range hostnameList { + hostname = strings.TrimSuffix(hostname, ".") // Create a corresponding endpoint for each configured external entrypoint. for _, lb := range svc.Status.LoadBalancer.Ingress { if lb.IP != "" { @@ -160,15 +162,3 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint { return endpoints } - -// parseHostnameAnnotation splits the hostname annontation and removes the trailing periods -func parseHostnameAnnotation(hostnameAnnotation string) (hostnames []string) { - - hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",") - - for _, hostname := range hostnameList { - hostnames = append(hostnames, strings.TrimSuffix(hostname, ".")) - } - - return -} From c7c5eeaccea3f72e6c72a459ae4b143d8a650d3d Mon Sep 17 00:00:00 2001 From: Nils Juenemann Date: Tue, 4 Jul 2017 16:38:08 +0200 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e07ce1a0..73d4372ebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ - The flag `--domain-filter` can be repeated multiple times like `--domain-filter=example.com --domain-filter=company.org.`. - A trailing period is not required anymore for `--domain-filter` when AWS (or any other) provider is used. - + - The `external-dns.alpha.kubernetes.io/hostname` annotation accepts now a comma separated list of hostnames and a trailing period is not required anymore. + ## v0.3.0 - 2017-05-08 Features: From 927457edd876dd4b6de7cc6b61e57606e38fce47 Mon Sep 17 00:00:00 2001 From: Nils Juenemann Date: Tue, 4 Jul 2017 18:20:27 +0200 Subject: [PATCH 5/5] Update Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d4372ebc..4f04558f56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ + - The `external-dns.alpha.kubernetes.io/hostname` annotation accepts now a comma separated list of hostnames and a trailing period is not required anymore. - The flag `--domain-filter` can be repeated multiple times like `--domain-filter=example.com --domain-filter=company.org.`. - A trailing period is not required anymore for `--domain-filter` when AWS (or any other) provider is used. - - The `external-dns.alpha.kubernetes.io/hostname` annotation accepts now a comma separated list of hostnames and a trailing period is not required anymore. ## v0.3.0 - 2017-05-08