From 0137231b7a3fdc4e0e84b1eb369e6b697ef71ce0 Mon Sep 17 00:00:00 2001 From: Jacobi Carter Date: Thu, 22 Mar 2018 01:03:49 -0700 Subject: [PATCH] Fixes for tblflp --- endpoint/endpoint.go | 9 ++++++++- provider/aws.go | 23 +++++++++++++++-------- source/service.go | 11 +++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 1fe002673b..c7a3ba230c 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -126,9 +126,16 @@ func NewEndpoint(dnsName, target, recordType string) *Endpoint { // NewEndpointWithTTL initialization method to be used to create an endpoint with a TTL struct func NewEndpointWithTTL(dnsName, target, recordType string, ttl TTL) *Endpoint { + return NewMultiTargetEndpointWithTTL(dnsName, Targets{target}, recordType, ttl) +} + +func NewMultiTargetEndpointWithTTL(dnsName string, targets Targets, recordType string, ttl TTL) *Endpoint { + for i, v := range targets { + targets[i] = strings.TrimSuffix(v, ".") + } return &Endpoint{ DNSName: strings.TrimSuffix(dnsName, "."), - Targets: Targets{strings.TrimSuffix(target, ".")}, + Targets: targets, RecordType: recordType, Labels: NewLabels(), RecordTTL: ttl, diff --git a/provider/aws.go b/provider/aws.go index 6204cf8d7b..ac10bef1a8 100644 --- a/provider/aws.go +++ b/provider/aws.go @@ -176,12 +176,18 @@ func (p *AWSProvider) Records() (endpoints []*endpoint.Endpoint, _ error) { ttl = endpoint.TTL(*r.TTL) } - for _, rr := range r.ResourceRecords { - endpoints = append(endpoints, endpoint.NewEndpointWithTTL(wildcardUnescape(aws.StringValue(r.Name)), aws.StringValue(rr.Value), aws.StringValue(r.Type), ttl)) - } - if r.AliasTarget != nil { endpoints = append(endpoints, endpoint.NewEndpointWithTTL(wildcardUnescape(aws.StringValue(r.Name)), aws.StringValue(r.AliasTarget.DNSName), endpoint.RecordTypeCNAME, ttl)) + } else if aws.StringValue(r.Type) == "TXT" { + for _, rr := range r.ResourceRecords { + endpoints = append(endpoints, endpoint.NewEndpointWithTTL(wildcardUnescape(aws.StringValue(r.Name)), aws.StringValue(rr.Value), aws.StringValue(r.Type), ttl)) + } + } else { + var endpointTargets = make([]string, len(r.ResourceRecords)) + for i, rr := range r.ResourceRecords { + endpointTargets[i] = aws.StringValue(rr.Value) + } + endpoints = append(endpoints, endpoint.NewMultiTargetEndpointWithTTL(wildcardUnescape(aws.StringValue(r.Name)), endpointTargets, aws.StringValue(r.Type), ttl)) } } @@ -389,10 +395,11 @@ func newChange(action string, endpoint *endpoint.Endpoint) *route53.Change { } else { change.ResourceRecordSet.TTL = aws.Int64(int64(endpoint.RecordTTL)) } - change.ResourceRecordSet.ResourceRecords = []*route53.ResourceRecord{ - { - Value: aws.String(endpoint.Targets[0]), - }, + change.ResourceRecordSet.ResourceRecords = make([]*route53.ResourceRecord, len(endpoint.Targets)) + for i, v := range endpoint.Targets { + change.ResourceRecordSet.ResourceRecords[i] = &route53.ResourceRecord{ + Value: aws.String(v), + } } } diff --git a/source/service.go b/source/service.go index ce71ecde0d..910cf26d09 100644 --- a/source/service.go +++ b/source/service.go @@ -263,6 +263,7 @@ func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string) []* if sc.publishInternal { targets = append(targets, extractServiceIps(svc)...) } + targets = append(targets, extractExternalIps(svc)...) if svc.Spec.ClusterIP == v1.ClusterIPNone { endpoints = append(endpoints, sc.extractHeadlessEndpoints(svc, hostname)...) } @@ -310,3 +311,13 @@ func extractLoadBalancerTargets(svc *v1.Service) endpoint.Targets { return targets } + +func extractExternalIps(svc *v1.Service) endpoint.Targets { + var targets = make(endpoint.Targets, len(svc.Spec.ExternalIPs)) + + for i, ip := range svc.Spec.ExternalIPs { + targets[i] = ip + } + + return targets +}