Kops Compatibility #1: Set RecordType at source (#248)

* set RecordType at source

* add comments for linting
This commit is contained in:
Seth Pollack 2017-08-25 08:41:40 -04:00 committed by Martin Linkhorst
parent a7a1cbc179
commit f14a953b5f
24 changed files with 467 additions and 468 deletions

View File

@ -24,6 +24,12 @@ import (
const (
// OwnerLabelKey is the name of the label that defines the owner of an Endpoint.
OwnerLabelKey = "owner"
// RecordTypeA is a RecordType enum value
RecordTypeA = "A"
// RecordTypeCNAME is a RecordType enum value
RecordTypeCNAME = "CNAME"
// RecordTypeTXT is a RecordType enum value
RecordTypeTXT = "TXT"
)
// Endpoint is a high-level way of a connection between a service and an IP

View File

@ -32,22 +32,22 @@ func ExampleSameEndpoints() {
{
DNSName: "example.org",
Target: "load-balancer.org",
RecordType: "TXT",
RecordType: endpoint.RecordTypeTXT,
},
{
DNSName: "abc.com",
Target: "something",
RecordType: "TXT",
RecordType: endpoint.RecordTypeTXT,
},
{
DNSName: "abc.com",
Target: "1.2.3.4",
RecordType: "A",
RecordType: endpoint.RecordTypeA,
},
{
DNSName: "bbc.com",
Target: "foo.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
},
}
sort.Sort(byAllFields(eps))

View File

@ -30,21 +30,21 @@ func TestCalculate(t *testing.T) {
// empty list of records
empty := []*endpoint.Endpoint{}
// a simple entry
fooV1 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v1", "CNAME")}
fooV1 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v1", endpoint.RecordTypeCNAME)}
// the same entry but with different target
fooV2 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", "CNAME")}
fooV2 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", endpoint.RecordTypeCNAME)}
// another simple entry
bar := []*endpoint.Endpoint{endpoint.NewEndpoint("bar", "v1", "CNAME")}
bar := []*endpoint.Endpoint{endpoint.NewEndpoint("bar", "v1", endpoint.RecordTypeCNAME)}
// test case with labels
noLabels := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", "CNAME")}
noLabels := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", endpoint.RecordTypeCNAME)}
labeledV2 := []*endpoint.Endpoint{newEndpointWithOwner("foo", "v2", "123")}
labeledV1 := []*endpoint.Endpoint{newEndpointWithOwner("foo", "v1", "123")}
// test case with type inheritance
noType := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", "")}
typedV2 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", "A")}
typedV1 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v1", "A")}
typedV2 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v2", endpoint.RecordTypeA)}
typedV1 := []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "v1", endpoint.RecordTypeA)}
for _, tc := range []struct {
policies []Policy
@ -165,7 +165,7 @@ func validateEntries(t *testing.T, entries, expected []*endpoint.Endpoint) {
}
func newEndpointWithOwner(dnsName, target, ownerID string) *endpoint.Endpoint {
e := endpoint.NewEndpoint(dnsName, target, "CNAME")
e := endpoint.NewEndpoint(dnsName, target, endpoint.RecordTypeCNAME)
e.Labels[endpoint.OwnerLabelKey] = ownerID
return e
}

View File

@ -157,7 +157,7 @@ func (p *AWSProvider) Records() (endpoints []*endpoint.Endpoint, _ error) {
}
if r.AliasTarget != nil {
endpoints = append(endpoints, endpoint.NewEndpoint(wildcardUnescape(aws.StringValue(r.Name)), aws.StringValue(r.AliasTarget.DNSName), "ALIAS"))
endpoints = append(endpoints, endpoint.NewEndpoint(wildcardUnescape(aws.StringValue(r.Name)), aws.StringValue(r.AliasTarget.DNSName), endpoint.RecordTypeCNAME))
}
}
@ -301,7 +301,7 @@ func newChange(action string, endpoint *endpoint.Endpoint) *route53.Change {
EvaluateTargetHealth: aws.Bool(evaluateTargetHealth),
}
} else {
change.ResourceRecordSet.Type = aws.String(suitableType(endpoint))
change.ResourceRecordSet.Type = aws.String(endpoint.RecordType)
change.ResourceRecordSet.TTL = aws.Int64(recordTTL)
change.ResourceRecordSet.ResourceRecords = []*route53.ResourceRecord{
{
@ -330,11 +330,11 @@ func suitableZone(hostname string, zones map[string]*route53.HostedZone) *route5
// isAWSLoadBalancer determines if a given hostname belongs to an AWS load balancer.
func isAWSLoadBalancer(ep *endpoint.Endpoint) bool {
if ep.RecordType == "" {
if ep.RecordType == endpoint.RecordTypeCNAME {
return canonicalHostedZone(ep.Target) != ""
}
return ep.RecordType == "ALIAS"
return false
}
// canonicalHostedZone returns the matching canonical zone for a given hostname.

View File

@ -176,22 +176,22 @@ func TestAWSZones(t *testing.T) {
func TestAWSRecords(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("*.wildcard-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("*.wildcard-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("*.wildcard-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("*.wildcard-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
records, err := provider.Records()
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("*.wildcard-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("*.wildcard-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("*.wildcard-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("*.wildcard-test-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
@ -199,9 +199,9 @@ func TestAWSCreateRecords(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{})
records := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", ""),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", ""),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
require.NoError(t, provider.CreateRecords(records))
@ -210,28 +210,28 @@ func TestAWSCreateRecords(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestAWSUpdateRecords(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
require.NoError(t, provider.UpdateRecords(updatedRecords, currentRecords))
@ -240,19 +240,19 @@ func TestAWSUpdateRecords(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestAWSDeleteRecords(t *testing.T) {
originalEndpoints := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, originalEndpoints)
@ -260,6 +260,7 @@ func TestAWSDeleteRecords(t *testing.T) {
require.NoError(t, provider.DeleteRecords(originalEndpoints))
records, err := provider.Records()
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{})
@ -267,41 +268,41 @@ func TestAWSDeleteRecords(t *testing.T) {
func TestAWSApplyChanges(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
createRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", ""),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", ""),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", ""),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", ""),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", ""),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
deleteRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", ""),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
changes := &plan.Changes{
@ -317,56 +318,56 @@ func TestAWSApplyChanges(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestAWSApplyChangesDryRun(t *testing.T) {
originalEndpoints := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), true, originalEndpoints)
createRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", ""),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("create-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", ""),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", ""),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", ""),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", ""),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.teapot.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.teapot.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
deleteRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", ""),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", ""),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", "ALIAS"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.teapot.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.teapot.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname-alias.zone-1.ext-dns-test-2.teapot.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
changes := &plan.Changes{
@ -495,7 +496,7 @@ func TestAWSCreateRecordsWithCNAME(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{})
records := []*endpoint.Endpoint{
{DNSName: "create-test.zone-1.ext-dns-test-2.teapot.zalan.do", Target: "foo.example.org"},
{DNSName: "create-test.zone-1.ext-dns-test-2.teapot.zalan.do", Target: "foo.example.org", RecordType: endpoint.RecordTypeCNAME},
}
require.NoError(t, provider.CreateRecords(records))
@ -505,7 +506,7 @@ func TestAWSCreateRecordsWithCNAME(t *testing.T) {
validateRecords(t, recordSets, []*route53.ResourceRecordSet{
{
Name: aws.String("create-test.zone-1.ext-dns-test-2.teapot.zalan.do."),
Type: aws.String("CNAME"),
Type: aws.String(endpoint.RecordTypeCNAME),
TTL: aws.Int64(300),
ResourceRecords: []*route53.ResourceRecord{
{
@ -520,7 +521,7 @@ func TestAWSCreateRecordsWithALIAS(t *testing.T) {
provider := newAWSProvider(t, NewDomainFilter([]string{"ext-dns-test-2.teapot.zalan.do."}), false, []*endpoint.Endpoint{})
records := []*endpoint.Endpoint{
{DNSName: "create-test.zone-1.ext-dns-test-2.teapot.zalan.do", Target: "foo.eu-central-1.elb.amazonaws.com"},
{DNSName: "create-test.zone-1.ext-dns-test-2.teapot.zalan.do", Target: "foo.eu-central-1.elb.amazonaws.com", RecordType: endpoint.RecordTypeCNAME},
}
require.NoError(t, provider.CreateRecords(records))
@ -535,7 +536,7 @@ func TestAWSCreateRecordsWithALIAS(t *testing.T) {
HostedZoneId: aws.String("Z215JYRZR1TBD5"),
},
Name: aws.String("create-test.zone-1.ext-dns-test-2.teapot.zalan.do."),
Type: aws.String("A"),
Type: aws.String(endpoint.RecordTypeA),
},
})
}
@ -546,12 +547,8 @@ func TestAWSisLoadBalancer(t *testing.T) {
recordType string
expected bool
}{
{"bar.eu-central-1.elb.amazonaws.com", "", true},
{"bar.eu-central-1.elb.amazonaws.com", "ALIAS", true},
{"bar.eu-central-1.elb.amazonaws.com", "CNAME", false},
{"foo.example.org", "", false},
{"foo.example.org", "ALIAS", true},
{"foo.example.org", "CNAME", false},
{"bar.eu-central-1.elb.amazonaws.com", endpoint.RecordTypeCNAME, true},
{"foo.example.org", endpoint.RecordTypeCNAME, false},
} {
ep := &endpoint.Endpoint{
Target: tc.target,
@ -642,7 +639,7 @@ func listAWSRecords(t *testing.T, client Route53API, zone string) []*route53.Res
}, func(resp *route53.ListResourceRecordSetsOutput, _ bool) bool {
for _, recordSet := range resp.ResourceRecordSets {
switch aws.StringValue(recordSet.Type) {
case "A", "CNAME":
case endpoint.RecordTypeA, endpoint.RecordTypeCNAME:
recordSets = append(recordSets, recordSet)
}
}

View File

@ -21,10 +21,10 @@ import (
"io/ioutil"
"strings"
"gopkg.in/yaml.v2"
log "github.com/Sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
"github.com/Azure/azure-sdk-for-go/arm/dns"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
@ -249,7 +249,6 @@ func (p *AzureProvider) mapChanges(zones []dns.Zone, changes *plan.Changes) (azu
return
}
// Ensure the record type is suitable
change.RecordType = suitableType(change)
changeMap[zone] = append(changeMap[zone], change)
}

View File

@ -89,11 +89,11 @@ func createMockRecordSet(name, recordType, value string) dns.RecordSet {
var getterFunc func(value string) *dns.RecordSetProperties
switch recordType {
case "A":
case endpoint.RecordTypeA:
getterFunc = aRecordSetPropertiesGetter
case "CNAME":
case endpoint.RecordTypeCNAME:
getterFunc = cNameRecordSetPropertiesGetter
case "TXT":
case endpoint.RecordTypeTXT:
getterFunc = txtRecordSetPropertiesGetter
default:
getterFunc = othersRecordSetPropertiesGetter
@ -161,11 +161,11 @@ func TestAzureRecord(t *testing.T) {
mockRecordSet: &[]dns.RecordSet{
createMockRecordSet("@", "NS", "ns1-03.azure-dns.com."),
createMockRecordSet("@", "SOA", "Email: azuredns-hostmaster.microsoft.com"),
createMockRecordSet("@", "A", "123.123.123.122"),
createMockRecordSet("@", "TXT", "heritage=external-dns,external-dns/owner=default"),
createMockRecordSet("nginx", "A", "123.123.123.123"),
createMockRecordSet("nginx", "TXT", "heritage=external-dns,external-dns/owner=default"),
createMockRecordSet("hack", "CNAME", "hack.azurewebsites.net"),
createMockRecordSet("@", endpoint.RecordTypeA, "123.123.123.122"),
createMockRecordSet("@", endpoint.RecordTypeTXT, "heritage=external-dns,external-dns/owner=default"),
createMockRecordSet("nginx", endpoint.RecordTypeA, "123.123.123.123"),
createMockRecordSet("nginx", endpoint.RecordTypeTXT, "heritage=external-dns,external-dns/owner=default"),
createMockRecordSet("hack", endpoint.RecordTypeCNAME, "hack.azurewebsites.net"),
},
}
@ -176,11 +176,11 @@ func TestAzureRecord(t *testing.T) {
t.Fatal(err)
}
expected := []*endpoint.Endpoint{
endpoint.NewEndpoint("example.com", "123.123.123.122", "A"),
endpoint.NewEndpoint("example.com", "heritage=external-dns,external-dns/owner=default", "TXT"),
endpoint.NewEndpoint("nginx.example.com", "123.123.123.123", "A"),
endpoint.NewEndpoint("nginx.example.com", "heritage=external-dns,external-dns/owner=default", "TXT"),
endpoint.NewEndpoint("hack.example.com", "hack.azurewebsites.net", "CNAME"),
endpoint.NewEndpoint("example.com", "123.123.123.122", endpoint.RecordTypeA),
endpoint.NewEndpoint("example.com", "heritage=external-dns,external-dns/owner=default", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("nginx.example.com", "123.123.123.123", endpoint.RecordTypeA),
endpoint.NewEndpoint("nginx.example.com", "heritage=external-dns,external-dns/owner=default", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("hack.example.com", "hack.azurewebsites.net", endpoint.RecordTypeCNAME),
}
validateEndpoints(t, actual, expected)
@ -192,23 +192,23 @@ func TestAzureApplyChanges(t *testing.T) {
testAzureApplyChangesInternal(t, false, &recordsClient)
validateEndpoints(t, recordsClient.deletedEndpoints, []*endpoint.Endpoint{
endpoint.NewEndpoint("old.example.com", "", "A"),
endpoint.NewEndpoint("oldcname.example.com", "", "CNAME"),
endpoint.NewEndpoint("deleted.example.com", "", "A"),
endpoint.NewEndpoint("deletedcname.example.com", "", "CNAME"),
endpoint.NewEndpoint("old.example.com", "", endpoint.RecordTypeA),
endpoint.NewEndpoint("oldcname.example.com", "", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("deleted.example.com", "", endpoint.RecordTypeA),
endpoint.NewEndpoint("deletedcname.example.com", "", endpoint.RecordTypeCNAME),
})
validateEndpoints(t, recordsClient.updatedEndpoints, []*endpoint.Endpoint{
endpoint.NewEndpoint("example.com", "1.2.3.4", "A"),
endpoint.NewEndpoint("example.com", "tag", "TXT"),
endpoint.NewEndpoint("foo.example.com", "1.2.3.4", "A"),
endpoint.NewEndpoint("foo.example.com", "tag", "TXT"),
endpoint.NewEndpoint("bar.example.com", "other.com", "CNAME"),
endpoint.NewEndpoint("bar.example.com", "tag", "TXT"),
endpoint.NewEndpoint("other.com", "5.6.7.8", "A"),
endpoint.NewEndpoint("other.com", "tag", "TXT"),
endpoint.NewEndpoint("new.example.com", "111.222.111.222", "A"),
endpoint.NewEndpoint("newcname.example.com", "other.com", "CNAME"),
endpoint.NewEndpoint("example.com", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("foo.example.com", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("foo.example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("bar.example.com", "other.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("bar.example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("other.com", "5.6.7.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("other.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("new.example.com", "111.222.111.222", endpoint.RecordTypeA),
endpoint.NewEndpoint("newcname.example.com", "other.com", endpoint.RecordTypeCNAME),
})
}
@ -239,33 +239,33 @@ func testAzureApplyChangesInternal(t *testing.T, dryRun bool, client RecordsClie
)
createRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("example.com", "1.2.3.4", "A"),
endpoint.NewEndpoint("example.com", "tag", "TXT"),
endpoint.NewEndpoint("foo.example.com", "1.2.3.4", ""),
endpoint.NewEndpoint("foo.example.com", "tag", "TXT"),
endpoint.NewEndpoint("bar.example.com", "other.com", ""),
endpoint.NewEndpoint("bar.example.com", "tag", "TXT"),
endpoint.NewEndpoint("other.com", "5.6.7.8", "A"),
endpoint.NewEndpoint("other.com", "tag", "TXT"),
endpoint.NewEndpoint("nope.com", "4.4.4.4", ""),
endpoint.NewEndpoint("nope.com", "tag", "TXT"),
endpoint.NewEndpoint("example.com", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("foo.example.com", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("foo.example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("bar.example.com", "other.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("bar.example.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("other.com", "5.6.7.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("other.com", "tag", endpoint.RecordTypeTXT),
endpoint.NewEndpoint("nope.com", "4.4.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("nope.com", "tag", endpoint.RecordTypeTXT),
}
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("old.example.com", "121.212.121.212", "A"),
endpoint.NewEndpoint("oldcname.example.com", "other.com", ""),
endpoint.NewEndpoint("old.nope.com", "121.212.121.212", ""),
endpoint.NewEndpoint("old.example.com", "121.212.121.212", endpoint.RecordTypeA),
endpoint.NewEndpoint("oldcname.example.com", "other.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("old.nope.com", "121.212.121.212", endpoint.RecordTypeA),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("new.example.com", "111.222.111.222", ""),
endpoint.NewEndpoint("newcname.example.com", "other.com", ""),
endpoint.NewEndpoint("new.nope.com", "222.111.222.111", "A"),
endpoint.NewEndpoint("new.example.com", "111.222.111.222", endpoint.RecordTypeA),
endpoint.NewEndpoint("newcname.example.com", "other.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("new.nope.com", "222.111.222.111", endpoint.RecordTypeA),
}
deleteRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("deleted.example.com", "111.222.111.222", ""),
endpoint.NewEndpoint("deletedcname.example.com", "other.com", ""),
endpoint.NewEndpoint("deleted.nope.com", "222.111.222.111", "A"),
endpoint.NewEndpoint("deleted.example.com", "111.222.111.222", endpoint.RecordTypeA),
endpoint.NewEndpoint("deletedcname.example.com", "other.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("deleted.nope.com", "222.111.222.111", endpoint.RecordTypeA),
}
changes := &plan.Changes{

View File

@ -21,9 +21,9 @@ import (
"os"
"strings"
log "github.com/Sirupsen/logrus"
cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go"
log "github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/plan"
@ -143,7 +143,7 @@ func (p *CloudFlareProvider) Records() ([]*endpoint.Endpoint, error) {
for _, r := range records {
switch r.Type {
case "A", "CNAME", "TXT":
case endpoint.RecordTypeA, endpoint.RecordTypeCNAME, endpoint.RecordTypeTXT:
break
default:
continue
@ -277,8 +277,6 @@ func newCloudFlareChanges(action string, endpoints []*endpoint.Endpoint) []*clou
}
func newCloudFlareChange(action string, endpoint *endpoint.Endpoint) *cloudFlareChange {
typ := suitableType(endpoint)
return &cloudFlareChange{
Action: action,
ResourceRecordSet: cloudflare.DNSRecord{
@ -286,7 +284,7 @@ func newCloudFlareChange(action string, endpoint *endpoint.Endpoint) *cloudFlare
// TTL Value of 1 is 'automatic'
TTL: 1,
Proxied: false,
Type: typ,
Type: endpoint.RecordType,
Content: endpoint.Target,
},
}

View File

@ -39,7 +39,7 @@ func (m *mockCloudFlareClient) CreateDNSRecord(zoneID string, rr cloudflare.DNSR
func (m *mockCloudFlareClient) DNSRecords(zoneID string, rr cloudflare.DNSRecord) ([]cloudflare.DNSRecord, error) {
if zoneID == "1234567890" {
return []cloudflare.DNSRecord{
{ID: "1234567890", Name: "foobar.ext-dns-test.zalando.to.", Type: "A"},
{ID: "1234567890", Name: "foobar.ext-dns-test.zalando.to.", Type: endpoint.RecordTypeA},
{ID: "1231231233", Name: "foo.bar.com"}},
nil
}
@ -425,23 +425,23 @@ func TestCloudFlareGetRecordID(t *testing.T) {
records := []cloudflare.DNSRecord{
{
Name: "foo.com",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
ID: "1",
},
{
Name: "bar.de",
Type: "A",
Type: endpoint.RecordTypeA,
ID: "2",
},
}
assert.Equal(t, "", p.getRecordID(records, cloudflare.DNSRecord{
Name: "foo.com",
Type: "A",
Type: endpoint.RecordTypeA,
}))
assert.Equal(t, "2", p.getRecordID(records, cloudflare.DNSRecord{
Name: "bar.de",
Type: "A",
Type: endpoint.RecordTypeA,
}))
}

View File

@ -256,7 +256,7 @@ func newDigitalOceanChange(action string, endpoint *endpoint.Endpoint) *DigitalO
Action: action,
ResourceRecordSet: godo.DomainRecord{
Name: endpoint.DNSName,
Type: suitableType(endpoint),
Type: endpoint.RecordType,
Data: endpoint.Target,
},
}

View File

@ -459,22 +459,22 @@ func TestDigitalOceanGetRecordID(t *testing.T) {
{
ID: 1,
Name: "foo.com",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
{
ID: 2,
Name: "baz.de",
Type: "A",
Type: endpoint.RecordTypeA,
},
}
assert.Equal(t, 1, p.getRecordID(records, godo.DomainRecord{
Name: "foo.com",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
}))
assert.Equal(t, 0, p.getRecordID(records, godo.DomainRecord{
Name: "foo.com",
Type: "A",
Type: endpoint.RecordTypeA,
}))
}

View File

@ -22,10 +22,11 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/linki/instrumented_http"
dns "google.golang.org/api/dns/v1"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/dns/v1"
googleapi "google.golang.org/api/googleapi"
"github.com/kubernetes-incubator/external-dns/endpoint"
@ -169,7 +170,7 @@ func (p *GoogleProvider) Records() (endpoints []*endpoint.Endpoint, _ error) {
// TODO(linki, ownership): Remove once ownership system is in place.
// See: https://github.com/kubernetes-incubator/external-dns/pull/122/files/74e2c3d3e237411e619aefc5aab694742001cdec#r109863370
switch r.Type {
case "A", "CNAME", "TXT":
case endpoint.RecordTypeA, endpoint.RecordTypeCNAME, endpoint.RecordTypeTXT:
break
default:
continue
@ -330,19 +331,19 @@ func newRecords(endpoints []*endpoint.Endpoint) []*dns.ResourceRecordSet {
}
// newRecord returns a RecordSet based on the given endpoint.
func newRecord(endpoint *endpoint.Endpoint) *dns.ResourceRecordSet {
func newRecord(ep *endpoint.Endpoint) *dns.ResourceRecordSet {
// TODO(linki): works around appending a trailing dot to TXT records. I think
// we should go back to storing DNS names with a trailing dot internally. This
// way we can use it has is here and trim it off if it exists when necessary.
target := endpoint.Target
if suitableType(endpoint) == "CNAME" {
target := ep.Target
if ep.RecordType == endpoint.RecordTypeCNAME {
target = ensureTrailingDot(target)
}
return &dns.ResourceRecordSet{
Name: ensureTrailingDot(endpoint.DNSName),
Name: ensureTrailingDot(ep.DNSName),
Rrdatas: []string{target},
Ttl: 300,
Type: suitableType(endpoint),
Type: ep.RecordType,
}
}

View File

@ -22,12 +22,13 @@ import (
"strings"
"testing"
dns "google.golang.org/api/dns/v1"
"golang.org/x/net/context"
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/plan"
"google.golang.org/api/dns/v1"
"google.golang.org/api/googleapi"
"github.com/stretchr/testify/assert"
@ -168,13 +169,13 @@ func isValidRecordSet(recordSet *dns.ResourceRecordSet) bool {
}
switch recordSet.Type {
case "CNAME":
case endpoint.RecordTypeCNAME:
for _, rrd := range recordSet.Rrdatas {
if !hasTrailingDot(rrd) {
return false
}
}
case "A", "TXT":
case endpoint.RecordTypeA, endpoint.RecordTypeTXT:
for _, rrd := range recordSet.Rrdatas {
if hasTrailingDot(rrd) {
return false
@ -206,9 +207,9 @@ func TestGoogleZones(t *testing.T) {
func TestGoogleRecords(t *testing.T) {
originalEndpoints := []*endpoint.Endpoint{
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("list-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("list-test-alias.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), false, originalEndpoints)
@ -223,9 +224,9 @@ func TestGoogleCreateRecords(t *testing.T) {
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), false, []*endpoint.Endpoint{})
records := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", ""),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", ""),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", ""),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
require.NoError(t, provider.CreateRecords(records))
@ -234,28 +235,28 @@ func TestGoogleCreateRecords(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestGoogleUpdateRecords(t *testing.T) {
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), false, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
require.NoError(t, provider.UpdateRecords(updatedRecords, currentRecords))
@ -264,17 +265,17 @@ func TestGoogleUpdateRecords(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestGoogleDeleteRecords(t *testing.T) {
originalEndpoints := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), false, originalEndpoints)
@ -289,35 +290,35 @@ func TestGoogleDeleteRecords(t *testing.T) {
func TestGoogleApplyChanges(t *testing.T) {
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), false, []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
createRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
deleteRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
changes := &plan.Changes{
@ -333,48 +334,48 @@ func TestGoogleApplyChanges(t *testing.T) {
require.NoError(t, err)
validateEndpoints(t, records, []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
})
}
func TestGoogleApplyChangesDryRun(t *testing.T) {
originalEndpoints := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
provider := newGoogleProvider(t, NewDomainFilter([]string{"ext-dns-test-2.gcp.zalan.do."}), true, originalEndpoints)
createRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("create-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("create-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "foo.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
currentRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "bar.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
updatedRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", "A"),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", "A"),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("update-test.zone-1.ext-dns-test-2.gcp.zalan.do", "1.2.3.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test.zone-2.ext-dns-test-2.gcp.zalan.do", "4.3.2.1", endpoint.RecordTypeA),
endpoint.NewEndpoint("update-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "baz.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
deleteRecords := []*endpoint.Endpoint{
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", "A"),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", "A"),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", "CNAME"),
endpoint.NewEndpoint("delete-test.zone-1.ext-dns-test-2.gcp.zalan.do", "8.8.8.8", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test.zone-2.ext-dns-test-2.gcp.zalan.do", "8.8.4.4", endpoint.RecordTypeA),
endpoint.NewEndpoint("delete-test-cname.zone-1.ext-dns-test-2.gcp.zalan.do", "qux.elb.amazonaws.com", endpoint.RecordTypeCNAME),
}
changes := &plan.Changes{
@ -560,7 +561,7 @@ func clearGoogleRecords(t *testing.T, provider *GoogleProvider, zone string) {
require.NoError(t, provider.resourceRecordSetsClient.List(provider.project, zone).Pages(context.TODO(), func(resp *dns.ResourceRecordSetsListResponse) error {
for _, r := range resp.Rrsets {
switch r.Type {
case "A", "CNAME":
case endpoint.RecordTypeA, endpoint.RecordTypeCNAME:
recordSets = append(recordSets, r)
}
}

View File

@ -178,7 +178,7 @@ func convertToInMemoryRecord(endpoints []*endpoint.Endpoint) []*inMemoryRecord {
records := []*inMemoryRecord{}
for _, ep := range endpoints {
records = append(records, &inMemoryRecord{
Type: suitableType(ep),
Type: ep.RecordType,
Name: ep.DNSName,
Target: ep.Target,
})

View File

@ -57,7 +57,7 @@ func testInMemoryFindByType(t *testing.T) {
},
{
title: "no records, non-empty type",
findType: "A",
findType: endpoint.RecordTypeA,
records: nil,
expected: nil,
expectedEmpty: true,
@ -67,7 +67,7 @@ func testInMemoryFindByType(t *testing.T) {
findType: "",
records: []*inMemoryRecord{
{
Type: "A",
Type: endpoint.RecordTypeA,
},
},
expected: nil,
@ -75,10 +75,10 @@ func testInMemoryFindByType(t *testing.T) {
},
{
title: "one record, wrong type",
findType: "CNAME",
findType: endpoint.RecordTypeCNAME,
records: []*inMemoryRecord{
{
Type: "A",
Type: endpoint.RecordTypeA,
},
},
expected: nil,
@ -86,29 +86,29 @@ func testInMemoryFindByType(t *testing.T) {
},
{
title: "one record, right type",
findType: "A",
findType: endpoint.RecordTypeA,
records: []*inMemoryRecord{
{
Type: "A",
Type: endpoint.RecordTypeA,
},
},
expected: &inMemoryRecord{
Type: "A",
Type: endpoint.RecordTypeA,
},
},
{
title: "multiple records, right type",
findType: "A",
findType: endpoint.RecordTypeA,
records: []*inMemoryRecord{
{
Type: "A",
Type: endpoint.RecordTypeA,
},
{
Type: "TXT",
Type: endpoint.RecordTypeTXT,
},
},
expected: &inMemoryRecord{
Type: "A",
Type: endpoint.RecordTypeA,
},
},
} {
@ -157,18 +157,18 @@ func testInMemoryRecords(t *testing.T) {
{
Name: "example.org",
Target: "8.8.8.8",
Type: "A",
Type: endpoint.RecordTypeA,
},
{
Name: "example.org",
Type: "TXT",
Type: endpoint.RecordTypeTXT,
},
},
"foo.org": []*inMemoryRecord{
{
Name: "foo.org",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},
@ -177,7 +177,7 @@ func testInMemoryRecords(t *testing.T) {
{
Name: "example.com",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},
@ -187,16 +187,16 @@ func testInMemoryRecords(t *testing.T) {
{
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: "A",
RecordType: endpoint.RecordTypeA,
},
{
DNSName: "example.org",
RecordType: "TXT",
RecordType: endpoint.RecordTypeTXT,
},
{
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
},
},
},
@ -227,7 +227,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
{
Name: "example.org",
Target: "8.8.8.8",
Type: "A",
Type: endpoint.RecordTypeA,
},
{
Name: "example.org",
@ -237,14 +237,14 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
{
Name: "foo.org",
Target: "bar.org",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
"foo.bar.org": []*inMemoryRecord{
{
Name: "foo.bar.org",
Target: "5.5.5.5",
Type: "A",
Type: endpoint.RecordTypeA,
},
},
},
@ -253,7 +253,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
{
Name: "example.com",
Target: "another-example.com",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},
@ -313,8 +313,9 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{},
@ -331,14 +332,16 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{},
@ -354,14 +357,16 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{},
@ -377,12 +382,14 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
{
DNSName: "foo.org",
Target: "4.4.4.4",
DNSName: "foo.org",
Target: "4.4.4.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{},
@ -400,15 +407,17 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
Create: []*endpoint.Endpoint{},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{},
Delete: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -423,12 +432,14 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
Create: []*endpoint.Endpoint{},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{},
@ -446,8 +457,9 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
UpdateNew: []*endpoint.Endpoint{},
UpdateOld: []*endpoint.Endpoint{
{
DNSName: "new.org",
Target: "8.8.8.8",
DNSName: "new.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
Delete: []*endpoint.Endpoint{},
@ -465,8 +477,9 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
UpdateOld: []*endpoint.Endpoint{},
Delete: []*endpoint.Endpoint{
{
DNSName: "new.org",
Target: "8.8.8.8",
DNSName: "new.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -483,8 +496,9 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
UpdateOld: []*endpoint.Endpoint{},
Delete: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "5.5.5.5",
DNSName: "foo.bar.org",
Target: "5.5.5.5",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -497,20 +511,23 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "foo.bar.new.org",
Target: "4.8.8.9",
DNSName: "foo.bar.new.org",
Target: "4.8.8.9",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "4.8.8.4",
DNSName: "foo.bar.org",
Target: "4.8.8.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "5.5.5.5",
DNSName: "foo.bar.org",
Target: "5.5.5.5",
RecordType: endpoint.RecordTypeA,
},
},
Delete: []*endpoint.Endpoint{},
@ -553,15 +570,17 @@ func testInMemoryApplyChanges(t *testing.T) {
Create: []*endpoint.Endpoint{},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{},
Delete: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -576,8 +595,9 @@ func testInMemoryApplyChanges(t *testing.T) {
UpdateOld: []*endpoint.Endpoint{},
Delete: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "5.5.5.5",
DNSName: "foo.bar.org",
Target: "5.5.5.5",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -588,12 +608,12 @@ func testInMemoryApplyChanges(t *testing.T) {
Name: "example.org",
Target: "8.8.8.8",
Type: "A",
Type: endpoint.RecordTypeA,
},
{
Name: "example.org",
Type: "TXT",
Type: endpoint.RecordTypeTXT,
},
},
"foo.org": []*inMemoryRecord{
@ -601,7 +621,7 @@ func testInMemoryApplyChanges(t *testing.T) {
Name: "foo.org",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
"foo.bar.org": []*inMemoryRecord{},
@ -611,7 +631,7 @@ func testInMemoryApplyChanges(t *testing.T) {
{
Name: "example.com",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},
@ -624,26 +644,30 @@ func testInMemoryApplyChanges(t *testing.T) {
changes: &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "foo.bar.new.org",
Target: "4.8.8.9",
DNSName: "foo.bar.new.org",
Target: "4.8.8.9",
RecordType: endpoint.RecordTypeA,
},
},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "4.8.8.4",
DNSName: "foo.bar.org",
Target: "4.8.8.4",
RecordType: endpoint.RecordTypeA,
},
},
UpdateOld: []*endpoint.Endpoint{
{
DNSName: "foo.bar.org",
Target: "5.5.5.5",
DNSName: "foo.bar.org",
Target: "5.5.5.5",
RecordType: endpoint.RecordTypeA,
},
},
Delete: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "8.8.8.8",
DNSName: "example.org",
Target: "8.8.8.8",
RecordType: endpoint.RecordTypeA,
},
},
},
@ -652,28 +676,28 @@ func testInMemoryApplyChanges(t *testing.T) {
"example.org": []*inMemoryRecord{
{
Name: "example.org",
Type: "TXT",
Type: endpoint.RecordTypeTXT,
},
},
"foo.org": []*inMemoryRecord{
{
Name: "foo.org",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
"foo.bar.org": []*inMemoryRecord{
{
Name: "foo.bar.org",
Target: "4.8.8.4",
Type: "A",
Type: endpoint.RecordTypeA,
},
},
"foo.bar.new.org": []*inMemoryRecord{
{
Name: "foo.bar.new.org",
Target: "4.8.8.9",
Type: "A",
Type: endpoint.RecordTypeA,
},
},
},
@ -682,7 +706,7 @@ func testInMemoryApplyChanges(t *testing.T) {
{
Name: "example.com",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},
@ -696,25 +720,25 @@ func testInMemoryApplyChanges(t *testing.T) {
{
Name: "example.org",
Target: "8.8.8.8",
Type: "A",
Type: endpoint.RecordTypeA,
},
{
Name: "example.org",
Type: "TXT",
Type: endpoint.RecordTypeTXT,
},
},
"foo.org": []*inMemoryRecord{
{
Name: "foo.org",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
"foo.bar.org": []*inMemoryRecord{
{
Name: "foo.bar.org",
Target: "5.5.5.5",
Type: "A",
Type: endpoint.RecordTypeA,
},
},
},
@ -723,7 +747,7 @@ func testInMemoryApplyChanges(t *testing.T) {
{
Name: "example.com",
Target: "4.4.4.4",
Type: "CNAME",
Type: endpoint.RecordTypeCNAME,
},
},
},

View File

@ -30,18 +30,6 @@ type Provider interface {
ApplyChanges(changes *plan.Changes) error
}
// suitableType returns the DNS resource record type suitable for the target.
// In this case type A for IPs and type CNAME for everything else.
func suitableType(ep *endpoint.Endpoint) string {
if ep.RecordType != "" {
return ep.RecordType
}
if net.ParseIP(ep.Target) != nil {
return "A"
}
return "CNAME"
}
// ensureTrailingDot ensures that the hostname receives a trailing dot if it hasn't already.
func ensureTrailingDot(hostname string) string {
if net.ParseIP(hostname) != nil {

View File

@ -18,32 +18,8 @@ package provider
import (
"testing"
"github.com/kubernetes-incubator/external-dns/endpoint"
)
func TestSuitableType(t *testing.T) {
for _, tc := range []struct {
target, recordType, expected string
}{
{"8.8.8.8", "", "A"},
{"foo.example.org", "", "CNAME"},
{"foo.example.org", "ALIAS", "ALIAS"},
{"bar.eu-central-1.elb.amazonaws.com", "CNAME", "CNAME"},
} {
ep := &endpoint.Endpoint{
Target: tc.target,
RecordType: tc.recordType,
}
recordType := suitableType(ep)
if recordType != tc.expected {
t.Errorf("expected %s, got %s", tc.expected, recordType)
}
}
}
func TestEnsureTrailingDot(t *testing.T) {
for _, tc := range []struct {
input, expected string

View File

@ -50,7 +50,7 @@ func testNoopRecords(t *testing.T) {
{
DNSName: "example.org",
Target: "example-lb.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
},
}
p.ApplyChanges(&plan.Changes{
@ -70,20 +70,21 @@ func testNoopApplyChanges(t *testing.T) {
p.CreateZone("org")
providerRecords := []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "old-lb.com",
DNSName: "example.org",
Target: "old-lb.com",
RecordType: endpoint.RecordTypeCNAME,
},
}
expectedUpdate := []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "new-example-lb.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
},
{
DNSName: "new-record.org",
Target: "new-lb.org",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
},
}
@ -96,8 +97,9 @@ func testNoopApplyChanges(t *testing.T) {
err := r.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "lb.com",
DNSName: "example.org",
Target: "lb.com",
RecordType: endpoint.RecordTypeCNAME,
},
},
})
@ -107,20 +109,23 @@ func testNoopApplyChanges(t *testing.T) {
require.NoError(t, r.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "new-record.org",
Target: "new-lb.org",
DNSName: "new-record.org",
Target: "new-lb.org",
RecordType: endpoint.RecordTypeCNAME,
},
},
UpdateNew: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "new-example-lb.com",
DNSName: "example.org",
Target: "new-example-lb.com",
RecordType: endpoint.RecordTypeCNAME,
},
},
UpdateOld: []*endpoint.Endpoint{
{
DNSName: "example.org",
Target: "old-lb.com",
DNSName: "example.org",
Target: "old-lb.com",
RecordType: endpoint.RecordTypeCNAME,
},
},
}))

View File

@ -69,7 +69,7 @@ func (im *TXTRegistry) Records() ([]*endpoint.Endpoint, error) {
ownerMap := map[string]string{}
for _, record := range records {
if record.RecordType != "TXT" {
if record.RecordType != endpoint.RecordTypeTXT {
endpoints = append(endpoints, record)
continue
}
@ -102,13 +102,16 @@ func (im *TXTRegistry) ApplyChanges(changes *plan.Changes) error {
}
for _, r := range filteredChanges.Create {
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), im.getTXTLabel(), "TXT")
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), im.getTXTLabel(), endpoint.RecordTypeTXT)
filteredChanges.Create = append(filteredChanges.Create, txt)
}
for _, r := range filteredChanges.Delete {
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), im.getTXTLabel(), "TXT")
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), im.getTXTLabel(), endpoint.RecordTypeTXT)
filteredChanges.Delete = append(filteredChanges.Delete, txt)
}
return im.provider.ApplyChanges(filteredChanges)
}

View File

@ -68,22 +68,22 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
p.CreateZone(testZone)
p.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
{
DNSName: "foo.test-zone.example.org",
Target: "foo.loadbalancer.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -91,7 +91,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
{
DNSName: "bar.test-zone.example.org",
Target: "my-domain.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -99,7 +99,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
{
DNSName: "txt.bar.test-zone.example.org",
Target: "baz.test-zone.example.org",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -107,7 +107,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
{
DNSName: "qux.test-zone.example.org",
Target: "random",
RecordType: "TXT",
RecordType: endpoint.RecordTypeTXT,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -115,7 +115,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
{
DNSName: "tar.test-zone.example.org",
Target: "tar.loadbalancer.com",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner-2",
},
@ -123,7 +123,7 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
{
DNSName: "foobar.test-zone.example.org",
Target: "foobar.loadbalancer.com",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -140,22 +140,22 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
p.CreateZone(testZone)
p.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner-2\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
expectedRecords := []*endpoint.Endpoint{
{
DNSName: "foo.test-zone.example.org",
Target: "foo.loadbalancer.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -163,7 +163,7 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
{
DNSName: "bar.test-zone.example.org",
Target: "my-domain.com",
RecordType: "CNAME",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -171,7 +171,7 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
{
DNSName: "txt.bar.test-zone.example.org",
Target: "baz.test-zone.example.org",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -179,7 +179,7 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
{
DNSName: "qux.test-zone.example.org",
Target: "random",
RecordType: "TXT",
RecordType: endpoint.RecordTypeTXT,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -187,7 +187,7 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
{
DNSName: "tar.test-zone.example.org",
Target: "tar.loadbalancer.com",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "",
},
@ -195,7 +195,7 @@ func testTXTRegistryRecordsNoPrefix(t *testing.T) {
{
DNSName: "foobar.test-zone.example.org",
Target: "foobar.loadbalancer.com",
RecordType: "ALIAS",
RecordType: endpoint.RecordTypeCNAME,
Labels: map[string]string{
endpoint.OwnerLabelKey: "owner",
},
@ -218,15 +218,15 @@ func testTXTRegistryApplyChangesWithPrefix(t *testing.T) {
p.CreateZone(testZone)
p.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
r, _ := NewTXTRegistry(p, "txt.", "owner")
@ -236,29 +236,29 @@ func testTXTRegistryApplyChangesWithPrefix(t *testing.T) {
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
UpdateNew: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
UpdateOld: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
}
expected := &plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
newEndpointWithOwner("txt.new-record-1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("txt.new-record-1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
newEndpointWithOwner("txt.foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
UpdateNew: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
UpdateOld: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
}
p.OnApplyChanges = func(got *plan.Changes) {
@ -285,15 +285,15 @@ func testTXTRegistryApplyChangesNoPrefix(t *testing.T) {
p.CreateZone(testZone)
p.ApplyChanges(&plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", "CNAME", ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", "CNAME", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", "ALIAS", ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", "TXT", ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foo.test-zone.example.org", "foo.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("bar.test-zone.example.org", "my-domain.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("txt.bar.test-zone.example.org", "baz.test-zone.example.org", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("qux.test-zone.example.org", "random", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("txt.tar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, ""),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
})
r, _ := NewTXTRegistry(p, "", "owner")
@ -303,23 +303,23 @@ func testTXTRegistryApplyChangesNoPrefix(t *testing.T) {
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
},
UpdateNew: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", "ALIAS", "owner-2"),
newEndpointWithOwner("tar.test-zone.example.org", "new-tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner-2"),
},
UpdateOld: []*endpoint.Endpoint{
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", "ALIAS", "owner-2"),
newEndpointWithOwner("tar.test-zone.example.org", "tar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner-2"),
},
}
expected := &plan.Changes{
Create: []*endpoint.Endpoint{
newEndpointWithOwner("new-record-1.test-zone.example.org", "new-loadbalancer-1.lb.com", "", ""),
newEndpointWithOwner("new-record-1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("new-record-1.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
Delete: []*endpoint.Endpoint{
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", "ALIAS", "owner"),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", "TXT", ""),
newEndpointWithOwner("foobar.test-zone.example.org", "foobar.loadbalancer.com", endpoint.RecordTypeCNAME, "owner"),
newEndpointWithOwner("foobar.test-zone.example.org", "\"heritage=external-dns,external-dns/owner=owner\"", endpoint.RecordTypeTXT, ""),
},
UpdateNew: []*endpoint.Endpoint{},
UpdateOld: []*endpoint.Endpoint{},

View File

@ -56,10 +56,10 @@ func legacyEndpointsFromMateService(svc *v1.Service) []*endpoint.Endpoint {
// 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, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, endpoint.RecordTypeA))
}
if lb.Hostname != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, endpoint.RecordTypeCNAME))
}
}
@ -88,10 +88,10 @@ func legacyEndpointsFromMoleculeService(svc *v1.Service) []*endpoint.Endpoint {
// 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, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, endpoint.RecordTypeA))
}
if lb.Hostname != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, endpoint.RecordTypeCNAME))
}
}
}

View File

@ -69,7 +69,7 @@ func (sc *fakeSource) generateEndpoint() (*endpoint.Endpoint, error) {
endpoint := endpoint.NewEndpoint(
generateDNSName(4, sc.dnsName),
generateIPAddress(),
"A",
endpoint.RecordTypeA,
)
return endpoint, nil

View File

@ -141,10 +141,10 @@ func (sc *ingressSource) endpointsFromTemplate(ing *v1beta1.Ingress) ([]*endpoin
for _, lb := range ing.Status.LoadBalancer.Ingress {
if lb.IP != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, endpoint.RecordTypeA))
}
if lb.Hostname != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, endpoint.RecordTypeCNAME))
}
}
@ -169,10 +169,10 @@ func endpointsFromIngress(ing *v1beta1.Ingress) []*endpoint.Endpoint {
for _, lb := range ing.Status.LoadBalancer.Ingress {
if lb.IP != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(rule.Host, lb.IP, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(rule.Host, lb.IP, endpoint.RecordTypeA))
}
if lb.Hostname != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(rule.Host, lb.Hostname, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(rule.Host, lb.Hostname, endpoint.RecordTypeCNAME))
}
}
}

View File

@ -124,6 +124,7 @@ func (sc *serviceSource) endpointsFromTemplate(svc *v1.Service) ([]*endpoint.End
}
hostname := buf.String()
endpoints = sc.generateEndpoints(svc, hostname)
return endpoints, nil
@ -169,7 +170,7 @@ func extractServiceIps(svc *v1.Service, hostname string) []*endpoint.Endpoint {
return []*endpoint.Endpoint{}
}
return []*endpoint.Endpoint{endpoint.NewEndpoint(hostname, svc.Spec.ClusterIP, "")}
return []*endpoint.Endpoint{endpoint.NewEndpoint(hostname, svc.Spec.ClusterIP, endpoint.RecordTypeA)}
}
func extractLoadBalancerEndpoints(svc *v1.Service, hostname string) []*endpoint.Endpoint {
@ -179,10 +180,10 @@ func extractLoadBalancerEndpoints(svc *v1.Service, hostname string) []*endpoint.
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, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP, endpoint.RecordTypeA))
}
if lb.Hostname != "" {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, endpoint.RecordTypeCNAME))
}
}