mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-12-16 09:11:34 +01:00
Support for multiple hostnames in hostname annotation (#256)
* service source: support for multiple hostnames per annotation * go fmt * Make parseHostnameAnnontations inline * Update CHANGELOG.md * Update Changelog
This commit is contained in:
parent
4d48cef482
commit
bcb4972d4c
@ -1,3 +1,4 @@
|
|||||||
|
- 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.`.
|
- 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.
|
- A trailing period is not required anymore for `--domain-filter` when AWS (or any other) provider is used.
|
||||||
|
|
||||||
|
|||||||
@ -140,11 +140,16 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint {
|
|||||||
var endpoints []*endpoint.Endpoint
|
var endpoints []*endpoint.Endpoint
|
||||||
|
|
||||||
// Get the desired hostname of the service from the annotation.
|
// Get the desired hostname of the service from the annotation.
|
||||||
hostname, exists := svc.Annotations[hostnameAnnotationKey]
|
hostnameAnnotation, exists := svc.Annotations[hostnameAnnotationKey]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// splits the hostname annotation and removes the trailing periods
|
||||||
|
hostnameList := strings.Split(strings.Replace(hostnameAnnotation, " ", "", -1), ",")
|
||||||
|
|
||||||
|
for _, hostname := range hostnameList {
|
||||||
|
hostname = strings.TrimSuffix(hostname, ".")
|
||||||
// Create a corresponding endpoint for each configured external entrypoint.
|
// Create a corresponding endpoint for each configured external entrypoint.
|
||||||
for _, lb := range svc.Status.LoadBalancer.Ingress {
|
for _, lb := range svc.Status.LoadBalancer.Ingress {
|
||||||
if lb.IP != "" {
|
if lb.IP != "" {
|
||||||
@ -155,6 +160,7 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint {
|
|||||||
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
|
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return endpoints
|
return endpoints
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,6 +125,42 @@ func testServiceSourceEndpoints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
false,
|
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",
|
"annotated services return an endpoint with target hostname",
|
||||||
"",
|
"",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user