mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
use pointer to endpoint via NewEndpoint initializer (#125)
* use pointer to endpoint via NewEndpoint initializer * return nil if record does not exist in plan * add test for NewEndpoint
This commit is contained in:
parent
facdea51dd
commit
f9402d7ed1
@ -28,13 +28,13 @@ import (
|
||||
|
||||
// mockProvider returns mock endpoints and validates changes.
|
||||
type mockProvider struct {
|
||||
RecordsStore []endpoint.Endpoint
|
||||
RecordsStore []*endpoint.Endpoint
|
||||
ExpectZone string
|
||||
ExpectChanges *plan.Changes
|
||||
}
|
||||
|
||||
// Records returns the desired mock endpoints.
|
||||
func (p *mockProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
func (p *mockProvider) Records(zone string) ([]*endpoint.Endpoint, error) {
|
||||
return p.RecordsStore, nil
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ func (p *mockProvider) ApplyChanges(zone string, changes *plan.Changes) error {
|
||||
}
|
||||
|
||||
// newMockProvider creates a new mockProvider returning the given endpoints and validating the desired changes.
|
||||
func newMockProvider(endpoints []endpoint.Endpoint, zone string, changes *plan.Changes) provider.Provider {
|
||||
func newMockProvider(endpoints []*endpoint.Endpoint, zone string, changes *plan.Changes) provider.Provider {
|
||||
dnsProvider := &mockProvider{
|
||||
RecordsStore: endpoints,
|
||||
ExpectZone: zone,
|
||||
@ -90,7 +90,7 @@ func newMockProvider(endpoints []endpoint.Endpoint, zone string, changes *plan.C
|
||||
func TestRunOnce(t *testing.T) {
|
||||
// Fake some desired endpoints coming from our source.
|
||||
source := source.NewMockSource(
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "create-record",
|
||||
Target: "1.2.3.4",
|
||||
@ -104,7 +104,7 @@ func TestRunOnce(t *testing.T) {
|
||||
|
||||
// Fake some existing records in our DNS provider and validate some desired changes.
|
||||
provider := newMockProvider(
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "update-record",
|
||||
Target: "8.8.8.8",
|
||||
@ -116,16 +116,16 @@ func TestRunOnce(t *testing.T) {
|
||||
},
|
||||
"test-zone",
|
||||
&plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{DNSName: "create-record", Target: "1.2.3.4"},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{DNSName: "update-record", Target: "8.8.4.4"},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{
|
||||
UpdateOld: []*endpoint.Endpoint{
|
||||
{DNSName: "update-record", Target: "8.8.8.8"},
|
||||
},
|
||||
Delete: []endpoint.Endpoint{
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{DNSName: "delete-record", Target: "4.3.2.1"},
|
||||
},
|
||||
},
|
||||
|
@ -23,3 +23,11 @@ type Endpoint struct {
|
||||
// The target the DNS record points to
|
||||
Target string
|
||||
}
|
||||
|
||||
// NewEndpoint initialization method to be used to create an endpoint
|
||||
func NewEndpoint(dnsName, target string) *Endpoint {
|
||||
return &Endpoint{
|
||||
DNSName: dnsName,
|
||||
Target: target,
|
||||
}
|
||||
}
|
||||
|
26
endpoint/endpoint_test.go
Normal file
26
endpoint/endpoint_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package endpoint
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewEndpoint(t *testing.T) {
|
||||
e := NewEndpoint("example.org", "1.2.3.4")
|
||||
if e.DNSName != "example.org" || e.Target != "1.2.3.4" {
|
||||
t.Error("endpoint is not initialized correctly")
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ import (
|
||||
// SameEndpoint returns true if two endpoint are same
|
||||
// considers example.org. and example.org DNSName/Target as different endpoints
|
||||
// TODO:might need reconsideration regarding trailing dot
|
||||
func SameEndpoint(a, b endpoint.Endpoint) bool {
|
||||
func SameEndpoint(a, b *endpoint.Endpoint) bool {
|
||||
return a.DNSName == b.DNSName && a.Target == b.Target
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func SameEndpoint(a, b endpoint.Endpoint) bool {
|
||||
// [x,x,z] == [x,z,x]
|
||||
// [x,y,y] != [x,x,y]
|
||||
// [x,x,x] != [x,x,z]
|
||||
func SameEndpoints(a, b []endpoint.Endpoint) bool {
|
||||
func SameEndpoints(a, b []*endpoint.Endpoint) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
16
plan/plan.go
16
plan/plan.go
@ -24,9 +24,9 @@ import (
|
||||
// update and delete actions.
|
||||
type Plan struct {
|
||||
// List of current records
|
||||
Current []endpoint.Endpoint
|
||||
Current []*endpoint.Endpoint
|
||||
// List of desired records
|
||||
Desired []endpoint.Endpoint
|
||||
Desired []*endpoint.Endpoint
|
||||
// List of changes necessary to move towards desired state
|
||||
// Populated after calling Calculate()
|
||||
Changes Changes
|
||||
@ -35,13 +35,13 @@ type Plan struct {
|
||||
// Changes holds lists of actions to be executed by dns providers
|
||||
type Changes struct {
|
||||
// Records that need to be created
|
||||
Create []endpoint.Endpoint
|
||||
Create []*endpoint.Endpoint
|
||||
// Records that need to be updated (current data)
|
||||
UpdateOld []endpoint.Endpoint
|
||||
UpdateOld []*endpoint.Endpoint
|
||||
// Records that need to be updated (desired data)
|
||||
UpdateNew []endpoint.Endpoint
|
||||
UpdateNew []*endpoint.Endpoint
|
||||
// Records that need to be deleted
|
||||
Delete []endpoint.Endpoint
|
||||
Delete []*endpoint.Endpoint
|
||||
}
|
||||
|
||||
// Calculate computes the actions needed to move current state towards desired
|
||||
@ -86,12 +86,12 @@ func (p *Plan) Calculate() *Plan {
|
||||
}
|
||||
|
||||
// recordExists checks whether a record can be found in a list of records.
|
||||
func recordExists(needle endpoint.Endpoint, haystack []endpoint.Endpoint) (endpoint.Endpoint, bool) {
|
||||
func recordExists(needle *endpoint.Endpoint, haystack []*endpoint.Endpoint) (*endpoint.Endpoint, bool) {
|
||||
for _, record := range haystack {
|
||||
if record.DNSName == needle.DNSName {
|
||||
return record, true
|
||||
}
|
||||
}
|
||||
|
||||
return endpoint.Endpoint{}, false
|
||||
return nil, false
|
||||
}
|
||||
|
@ -27,16 +27,16 @@ import (
|
||||
// current records to a list of desired records.
|
||||
func TestCalculate(t *testing.T) {
|
||||
// empty list of records
|
||||
empty := []endpoint.Endpoint{}
|
||||
empty := []*endpoint.Endpoint{}
|
||||
// a simple entry
|
||||
fooV1 := []endpoint.Endpoint{{DNSName: "foo", Target: "v1"}}
|
||||
fooV1 := []*endpoint.Endpoint{{DNSName: "foo", Target: "v1"}}
|
||||
// the same entry but with different target
|
||||
fooV2 := []endpoint.Endpoint{{DNSName: "foo", Target: "v2"}}
|
||||
fooV2 := []*endpoint.Endpoint{{DNSName: "foo", Target: "v2"}}
|
||||
// another simple entry
|
||||
bar := []endpoint.Endpoint{{DNSName: "bar", Target: "v1"}}
|
||||
bar := []*endpoint.Endpoint{{DNSName: "bar", Target: "v1"}}
|
||||
|
||||
for _, tc := range []struct {
|
||||
current, desired, create, updateOld, updateNew, delete []endpoint.Endpoint
|
||||
current, desired, create, updateOld, updateNew, delete []*endpoint.Endpoint
|
||||
}{
|
||||
// Nothing exists and nothing desired doesn't change anything.
|
||||
{empty, empty, empty, empty, empty, empty},
|
||||
@ -70,14 +70,14 @@ func TestCalculate(t *testing.T) {
|
||||
|
||||
// BenchmarkCalculate benchmarks the Calculate method.
|
||||
func BenchmarkCalculate(b *testing.B) {
|
||||
foo := endpoint.Endpoint{DNSName: "foo", Target: "v1"}
|
||||
barV1 := endpoint.Endpoint{DNSName: "bar", Target: "v1"}
|
||||
barV2 := endpoint.Endpoint{DNSName: "bar", Target: "v2"}
|
||||
baz := endpoint.Endpoint{DNSName: "baz", Target: "v1"}
|
||||
foo := endpoint.NewEndpoint("foo", "v1")
|
||||
barV1 := endpoint.NewEndpoint("bar", "v1")
|
||||
barV2 := endpoint.NewEndpoint("bar", "v2")
|
||||
baz := endpoint.NewEndpoint("baz", "v1")
|
||||
|
||||
plan := &Plan{
|
||||
Current: []endpoint.Endpoint{foo, barV1},
|
||||
Desired: []endpoint.Endpoint{barV2, baz},
|
||||
Current: []*endpoint.Endpoint{foo, barV1},
|
||||
Desired: []*endpoint.Endpoint{barV2, baz},
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -87,37 +87,53 @@ func BenchmarkCalculate(b *testing.B) {
|
||||
|
||||
// ExamplePlan shows how plan can be used.
|
||||
func ExamplePlan() {
|
||||
foo := endpoint.Endpoint{DNSName: "foo.example.com", Target: "1.2.3.4"}
|
||||
barV1 := endpoint.Endpoint{DNSName: "bar.example.com", Target: "8.8.8.8"}
|
||||
barV2 := endpoint.Endpoint{DNSName: "bar.example.com", Target: "8.8.4.4"}
|
||||
baz := endpoint.Endpoint{DNSName: "baz.example.com", Target: "6.6.6.6"}
|
||||
foo := endpoint.NewEndpoint("foo.example.com", "1.2.3.4")
|
||||
barV1 := endpoint.NewEndpoint("bar.example.com", "8.8.8.8")
|
||||
barV2 := endpoint.NewEndpoint("bar.example.com", "8.8.4.4")
|
||||
baz := endpoint.NewEndpoint("baz.example.com", "6.6.6.6")
|
||||
|
||||
// Plan where
|
||||
// * foo should be deleted
|
||||
// * bar should be updated from v1 to v2
|
||||
// * baz should be created
|
||||
plan := &Plan{
|
||||
Current: []endpoint.Endpoint{foo, barV1},
|
||||
Desired: []endpoint.Endpoint{barV2, baz},
|
||||
Current: []*endpoint.Endpoint{foo, barV1},
|
||||
Desired: []*endpoint.Endpoint{barV2, baz},
|
||||
}
|
||||
|
||||
// calculate actions
|
||||
plan = plan.Calculate()
|
||||
|
||||
// print actions
|
||||
fmt.Println("Create:", plan.Changes.Create)
|
||||
fmt.Println("UpdateOld:", plan.Changes.UpdateOld)
|
||||
fmt.Println("UpdateNew:", plan.Changes.UpdateNew)
|
||||
fmt.Println("Delete:", plan.Changes.Delete)
|
||||
fmt.Println("Create:")
|
||||
for _, ep := range plan.Changes.Create {
|
||||
fmt.Println(ep)
|
||||
}
|
||||
fmt.Println("UpdateOld:")
|
||||
for _, ep := range plan.Changes.UpdateOld {
|
||||
fmt.Println(ep)
|
||||
}
|
||||
fmt.Println("UpdateNew:")
|
||||
for _, ep := range plan.Changes.UpdateNew {
|
||||
fmt.Println(ep)
|
||||
}
|
||||
fmt.Println("Delete:")
|
||||
for _, ep := range plan.Changes.Delete {
|
||||
fmt.Println(ep)
|
||||
}
|
||||
// Output:
|
||||
// Create: [{baz.example.com 6.6.6.6}]
|
||||
// UpdateOld: [{bar.example.com 8.8.8.8}]
|
||||
// UpdateNew: [{bar.example.com 8.8.4.4}]
|
||||
// Delete: [{foo.example.com 1.2.3.4}]
|
||||
// Create:
|
||||
// &{baz.example.com 6.6.6.6}
|
||||
// UpdateOld:
|
||||
// &{bar.example.com 8.8.8.8}
|
||||
// UpdateNew:
|
||||
// &{bar.example.com 8.8.4.4}
|
||||
// Delete:
|
||||
// &{foo.example.com 1.2.3.4}
|
||||
}
|
||||
|
||||
// validateEntries validates that the list of entries matches expected.
|
||||
func validateEntries(t *testing.T, entries, expected []endpoint.Endpoint) {
|
||||
func validateEntries(t *testing.T, entries, expected []*endpoint.Endpoint) {
|
||||
if len(entries) != len(expected) {
|
||||
t.Fatalf("expected %q to match %q", entries, expected)
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func (p *AWSProvider) DeleteZone(name string) error {
|
||||
}
|
||||
|
||||
// Records returns the list of records in a given hosted zone.
|
||||
func (p *AWSProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
func (p *AWSProvider) Records(zone string) ([]*endpoint.Endpoint, error) {
|
||||
hostedZone, err := p.Zone(zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -145,7 +145,7 @@ func (p *AWSProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
HostedZoneId: hostedZone.Id,
|
||||
}
|
||||
|
||||
endpoints := []endpoint.Endpoint{}
|
||||
endpoints := []*endpoint.Endpoint{}
|
||||
|
||||
f := func(resp *route53.ListResourceRecordSetsOutput, lastPage bool) (shouldContinue bool) {
|
||||
for _, r := range resp.ResourceRecordSets {
|
||||
@ -154,10 +154,7 @@ func (p *AWSProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
}
|
||||
|
||||
for _, rr := range r.ResourceRecords {
|
||||
endpoints = append(endpoints, endpoint.Endpoint{
|
||||
DNSName: aws.StringValue(r.Name),
|
||||
Target: aws.StringValue(rr.Value),
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(aws.StringValue(r.Name), aws.StringValue(rr.Value)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,17 +170,17 @@ func (p *AWSProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
}
|
||||
|
||||
// CreateRecords creates a given set of DNS records in the given hosted zone.
|
||||
func (p *AWSProvider) CreateRecords(zone string, endpoints []endpoint.Endpoint) error {
|
||||
func (p *AWSProvider) CreateRecords(zone string, endpoints []*endpoint.Endpoint) error {
|
||||
return p.submitChanges(zone, newChanges(route53.ChangeActionCreate, endpoints))
|
||||
}
|
||||
|
||||
// UpdateRecords updates a given set of old records to a new set of records in a given hosted zone.
|
||||
func (p *AWSProvider) UpdateRecords(zone string, endpoints, _ []endpoint.Endpoint) error {
|
||||
func (p *AWSProvider) UpdateRecords(zone string, endpoints, _ []*endpoint.Endpoint) error {
|
||||
return p.submitChanges(zone, newChanges(route53.ChangeActionUpsert, endpoints))
|
||||
}
|
||||
|
||||
// DeleteRecords deletes a given set of DNS records in a given zone.
|
||||
func (p *AWSProvider) DeleteRecords(zone string, endpoints []endpoint.Endpoint) error {
|
||||
func (p *AWSProvider) DeleteRecords(zone string, endpoints []*endpoint.Endpoint) error {
|
||||
return p.submitChanges(zone, newChanges(route53.ChangeActionDelete, endpoints))
|
||||
}
|
||||
|
||||
@ -234,7 +231,7 @@ func (p *AWSProvider) submitChanges(zone string, changes []*route53.Change) erro
|
||||
}
|
||||
|
||||
// newChanges returns a collection of Changes based on the given records and action.
|
||||
func newChanges(action string, endpoints []endpoint.Endpoint) []*route53.Change {
|
||||
func newChanges(action string, endpoints []*endpoint.Endpoint) []*route53.Change {
|
||||
changes := make([]*route53.Change, 0, len(endpoints))
|
||||
|
||||
for _, endpoint := range endpoints {
|
||||
@ -247,7 +244,7 @@ func newChanges(action string, endpoints []endpoint.Endpoint) []*route53.Change
|
||||
// newChange returns a Change of the given record by the given action, e.g.
|
||||
// action=ChangeActionCreate returns a change for creation of the record and
|
||||
// action=ChangeActionDelete returns a change for deletion of the record.
|
||||
func newChange(action string, endpoint endpoint.Endpoint) *route53.Change {
|
||||
func newChange(action string, endpoint *endpoint.Endpoint) *route53.Change {
|
||||
change := &route53.Change{
|
||||
Action: aws.String(action),
|
||||
ResourceRecordSet: &route53.ResourceRecordSet{
|
||||
|
@ -252,7 +252,7 @@ func TestAWSRecords(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
records := []endpoint.Endpoint{{DNSName: "list-test.list-ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
records := []*endpoint.Endpoint{{DNSName: "list-test.list-ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("list-ext-dns-test.teapot.zalan.do.", records)
|
||||
if err != nil {
|
||||
@ -291,7 +291,7 @@ func TestAWSCreateRecords(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
records := []endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
records := []*endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", records)
|
||||
if err != nil {
|
||||
@ -326,14 +326,14 @@ func TestAWSUpdateRecords(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
oldRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", oldRecords)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
newRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
|
||||
err = provider.UpdateRecords("ext-dns-test.teapot.zalan.do.", newRecords, oldRecords)
|
||||
if err != nil {
|
||||
@ -368,7 +368,7 @@ func TestAWSDeleteRecords(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
records := []endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
records := []*endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", records)
|
||||
if err != nil {
|
||||
@ -406,22 +406,22 @@ func TestAWSApply(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
updateRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", updateRecords)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteRecords := []endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
deleteRecords := []*endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", deleteRecords)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
createRecords := []endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateNewRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
createRecords := []*endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateNewRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
|
||||
changes := &plan.Changes{
|
||||
Create: createRecords,
|
||||
@ -511,7 +511,7 @@ func TestAWSCreateRecordDryRun(t *testing.T) {
|
||||
|
||||
provider.DryRun = true
|
||||
|
||||
records := []endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
records := []*endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", records)
|
||||
if err != nil {
|
||||
@ -546,7 +546,7 @@ func TestAWSUpdateRecordDryRun(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
oldRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", oldRecords)
|
||||
if err != nil {
|
||||
@ -555,7 +555,7 @@ func TestAWSUpdateRecordDryRun(t *testing.T) {
|
||||
|
||||
provider.DryRun = true
|
||||
|
||||
newRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
newRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
|
||||
err = provider.UpdateRecords("ext-dns-test.teapot.zalan.do.", newRecords, oldRecords)
|
||||
if err != nil {
|
||||
@ -590,7 +590,7 @@ func TestAWSDeleteRecordDryRun(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
records := []endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
records := []*endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", records)
|
||||
if err != nil {
|
||||
@ -630,14 +630,14 @@ func TestAWSApplyDryRun(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
updateRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", updateRecords)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteRecords := []endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
deleteRecords := []*endpoint.Endpoint{{DNSName: "delete-test.ext-dns-test.teapot.zalan.do.", Target: "20.153.88.175"}}
|
||||
|
||||
err = provider.CreateRecords("ext-dns-test.teapot.zalan.do.", deleteRecords)
|
||||
if err != nil {
|
||||
@ -646,8 +646,8 @@ func TestAWSApplyDryRun(t *testing.T) {
|
||||
|
||||
provider.DryRun = true
|
||||
|
||||
createRecords := []endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateNewRecords := []endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
createRecords := []*endpoint.Endpoint{{DNSName: "create-test.ext-dns-test.teapot.zalan.do.", Target: "8.8.8.8"}}
|
||||
updateNewRecords := []*endpoint.Endpoint{{DNSName: "update-test.ext-dns-test.teapot.zalan.do.", Target: "1.2.3.4"}}
|
||||
|
||||
changes := &plan.Changes{
|
||||
Create: createRecords,
|
||||
|
@ -179,7 +179,7 @@ func (p *googleProvider) DeleteZone(name string) error {
|
||||
}
|
||||
|
||||
// Records returns the list of A records in a given hosted zone.
|
||||
func (p *googleProvider) Records(zone string) (endpoints []endpoint.Endpoint, _ error) {
|
||||
func (p *googleProvider) Records(zone string) (endpoints []*endpoint.Endpoint, _ error) {
|
||||
f := func(resp *dns.ResourceRecordSetsListResponse) error {
|
||||
for _, r := range resp.Rrsets {
|
||||
if r.Type != "A" {
|
||||
@ -188,10 +188,7 @@ func (p *googleProvider) Records(zone string) (endpoints []endpoint.Endpoint, _
|
||||
|
||||
for _, rr := range r.Rrdatas {
|
||||
// each page is processed sequentially, no need for a mutex here.
|
||||
endpoints = append(endpoints, endpoint.Endpoint{
|
||||
DNSName: r.Name,
|
||||
Target: rr,
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(r.Name, rr))
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +204,7 @@ func (p *googleProvider) Records(zone string) (endpoints []endpoint.Endpoint, _
|
||||
}
|
||||
|
||||
// CreateRecords creates a given set of DNS records in the given hosted zone.
|
||||
func (p *googleProvider) CreateRecords(zone string, endpoints []endpoint.Endpoint) error {
|
||||
func (p *googleProvider) CreateRecords(zone string, endpoints []*endpoint.Endpoint) error {
|
||||
change := &dns.Change{}
|
||||
|
||||
change.Additions = append(change.Additions, newRecords(endpoints)...)
|
||||
@ -216,7 +213,7 @@ func (p *googleProvider) CreateRecords(zone string, endpoints []endpoint.Endpoin
|
||||
}
|
||||
|
||||
// UpdateRecords updates a given set of old records to a new set of records in a given hosted zone.
|
||||
func (p *googleProvider) UpdateRecords(zone string, records, oldRecords []endpoint.Endpoint) error {
|
||||
func (p *googleProvider) UpdateRecords(zone string, records, oldRecords []*endpoint.Endpoint) error {
|
||||
change := &dns.Change{}
|
||||
|
||||
change.Additions = append(change.Additions, newRecords(records)...)
|
||||
@ -226,7 +223,7 @@ func (p *googleProvider) UpdateRecords(zone string, records, oldRecords []endpoi
|
||||
}
|
||||
|
||||
// DeleteRecords deletes a given set of DNS records in a given zone.
|
||||
func (p *googleProvider) DeleteRecords(zone string, endpoints []endpoint.Endpoint) error {
|
||||
func (p *googleProvider) DeleteRecords(zone string, endpoints []*endpoint.Endpoint) error {
|
||||
change := &dns.Change{}
|
||||
|
||||
change.Deletions = append(change.Deletions, newRecords(endpoints)...)
|
||||
@ -276,7 +273,7 @@ func (p *googleProvider) submitChange(zone string, change *dns.Change) error {
|
||||
}
|
||||
|
||||
// newRecords returns a collection of RecordSets based on the given endpoints.
|
||||
func newRecords(endpoints []endpoint.Endpoint) []*dns.ResourceRecordSet {
|
||||
func newRecords(endpoints []*endpoint.Endpoint) []*dns.ResourceRecordSet {
|
||||
records := make([]*dns.ResourceRecordSet, len(endpoints))
|
||||
|
||||
for i, endpoint := range endpoints {
|
||||
@ -287,7 +284,7 @@ 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(endpoint *endpoint.Endpoint) *dns.ResourceRecordSet {
|
||||
return &dns.ResourceRecordSet{
|
||||
Name: endpoint.DNSName,
|
||||
Rrdatas: []string{endpoint.Target},
|
||||
|
@ -247,7 +247,7 @@ func TestGoogleCreateRecords(t *testing.T) {
|
||||
changesClient: &mockChangesClient{},
|
||||
}
|
||||
|
||||
endpoints := []endpoint.Endpoint{
|
||||
endpoints := []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "dns-name",
|
||||
Target: "target",
|
||||
@ -273,14 +273,14 @@ func TestGoogleUpdateRecords(t *testing.T) {
|
||||
changesClient: &mockChangesClient{},
|
||||
}
|
||||
|
||||
records := []endpoint.Endpoint{
|
||||
records := []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "dns-name",
|
||||
Target: "target",
|
||||
},
|
||||
}
|
||||
|
||||
oldRecords := []endpoint.Endpoint{
|
||||
oldRecords := []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "dns-name",
|
||||
Target: "target",
|
||||
@ -311,7 +311,7 @@ func TestGoogleDeleteRecords(t *testing.T) {
|
||||
changesClient: &mockChangesClient{},
|
||||
}
|
||||
|
||||
endpoints := []endpoint.Endpoint{
|
||||
endpoints := []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "dns-name",
|
||||
Target: "target",
|
||||
|
@ -60,7 +60,7 @@ func NewInMemoryProvider() *InMemoryProvider {
|
||||
type InMemoryRecord struct {
|
||||
Type string
|
||||
Payload string
|
||||
endpoint.Endpoint
|
||||
*endpoint.Endpoint
|
||||
}
|
||||
|
||||
// CreateZone adds new zone if not present
|
||||
@ -73,7 +73,7 @@ func (im *InMemoryProvider) CreateZone(newZone string) error {
|
||||
}
|
||||
|
||||
// Records returns the list of endpoints
|
||||
func (im *InMemoryProvider) Records(zone string) ([]endpoint.Endpoint, error) {
|
||||
func (im *InMemoryProvider) Records(zone string) ([]*endpoint.Endpoint, error) {
|
||||
if _, exists := im.zones[zone]; !exists {
|
||||
return nil, ErrZoneNotFound
|
||||
}
|
||||
@ -163,8 +163,8 @@ func (im *InMemoryProvider) findByType(recordType string, records []*InMemoryRec
|
||||
return nil
|
||||
}
|
||||
|
||||
func (im *InMemoryProvider) endpoints(zone string) []endpoint.Endpoint {
|
||||
endpoints := make([]endpoint.Endpoint, 0)
|
||||
func (im *InMemoryProvider) endpoints(zone string) []*endpoint.Endpoint {
|
||||
endpoints := make([]*endpoint.Endpoint, 0)
|
||||
if zoneRecords, exists := im.zones[zone]; exists {
|
||||
for _, recordsPerName := range zoneRecords {
|
||||
for _, record := range recordsPerName {
|
||||
|
@ -25,6 +25,8 @@ import (
|
||||
"github.com/kubernetes-incubator/external-dns/plan"
|
||||
)
|
||||
|
||||
var _ Provider = &InMemoryProvider{}
|
||||
|
||||
func TestInMemoryProvider(t *testing.T) {
|
||||
t.Run("Records", testInMemoryRecords)
|
||||
t.Run("endpoints", testInMemoryEndpoints)
|
||||
@ -128,19 +130,19 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
title string
|
||||
zone string
|
||||
init map[string]zone
|
||||
expected []endpoint.Endpoint
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
title: "no records, no zone",
|
||||
zone: "",
|
||||
init: map[string]zone{},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "no records, zone",
|
||||
zone: "central",
|
||||
init: map[string]zone{},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "records, no zone",
|
||||
@ -163,7 +165,7 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "records, zone with no records",
|
||||
@ -186,7 +188,7 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "records, zone with records",
|
||||
@ -195,14 +197,14 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
Type: defaultType,
|
||||
},
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -210,7 +212,7 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -221,7 +223,7 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -230,7 +232,7 @@ func testInMemoryEndpoints(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -283,14 +285,14 @@ func testInMemoryRecords(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
Type: defaultType,
|
||||
},
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -298,7 +300,7 @@ func testInMemoryRecords(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -309,7 +311,7 @@ func testInMemoryRecords(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -345,14 +347,14 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
Type: defaultType,
|
||||
},
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -360,7 +362,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -369,7 +371,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
},
|
||||
"foo.bar.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
},
|
||||
@ -380,7 +382,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -403,10 +405,10 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "",
|
||||
init: map[string]zone{},
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrZoneNotFound,
|
||||
},
|
||||
@ -416,10 +418,10 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrZoneNotFound,
|
||||
},
|
||||
@ -429,10 +431,10 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "test",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrZoneNotFound,
|
||||
},
|
||||
@ -442,15 +444,15 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrRecordAlreadyExists,
|
||||
},
|
||||
@ -460,20 +462,20 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrRecordNotFound,
|
||||
},
|
||||
@ -483,20 +485,20 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrRecordNotFound,
|
||||
},
|
||||
@ -506,7 +508,7 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
@ -516,9 +518,9 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrInvalidBatchRequest,
|
||||
},
|
||||
@ -528,15 +530,15 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -551,8 +553,8 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -562,8 +564,8 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrInvalidBatchRequest,
|
||||
},
|
||||
@ -573,15 +575,15 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "new.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
errorType: ErrRecordNotFound,
|
||||
},
|
||||
@ -591,10 +593,10 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "new.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -609,10 +611,10 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
@ -626,25 +628,25 @@ func testInMemoryValidateChangeBatch(t *testing.T) {
|
||||
zone: "org",
|
||||
init: init,
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.new.org",
|
||||
Target: "4.8.8.9",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "4.8.8.4",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{
|
||||
UpdateOld: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
},
|
||||
},
|
||||
Delete: []endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{},
|
||||
},
|
||||
},
|
||||
} {
|
||||
@ -677,15 +679,15 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
expectError: true,
|
||||
zone: "org",
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -698,10 +700,10 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
expectError: false,
|
||||
zone: "org",
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{},
|
||||
UpdateNew: []endpoint.Endpoint{},
|
||||
UpdateOld: []endpoint.Endpoint{},
|
||||
Delete: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{},
|
||||
UpdateNew: []*endpoint.Endpoint{},
|
||||
UpdateOld: []*endpoint.Endpoint{},
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
@ -712,14 +714,14 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
Type: defaultType,
|
||||
},
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -727,7 +729,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -739,7 +741,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -754,25 +756,25 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
expectError: false,
|
||||
zone: "org",
|
||||
changes: &plan.Changes{
|
||||
Create: []endpoint.Endpoint{
|
||||
Create: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.new.org",
|
||||
Target: "4.8.8.9",
|
||||
},
|
||||
},
|
||||
UpdateNew: []endpoint.Endpoint{
|
||||
UpdateNew: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "4.8.8.4",
|
||||
},
|
||||
},
|
||||
UpdateOld: []endpoint.Endpoint{
|
||||
UpdateOld: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
},
|
||||
},
|
||||
Delete: []endpoint.Endpoint{
|
||||
Delete: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
@ -783,7 +785,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -791,7 +793,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -800,7 +802,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.bar.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "4.8.8.4",
|
||||
},
|
||||
@ -809,7 +811,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.bar.new.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.bar.new.org",
|
||||
Target: "4.8.8.9",
|
||||
},
|
||||
@ -820,7 +822,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -836,14 +838,14 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"org": {
|
||||
"example.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
Target: "8.8.8.8",
|
||||
},
|
||||
Type: defaultType,
|
||||
},
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.org",
|
||||
},
|
||||
Type: "TXT",
|
||||
@ -851,7 +853,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.org",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
@ -860,7 +862,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
},
|
||||
"foo.bar.org": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "foo.bar.org",
|
||||
Target: "5.5.5.5",
|
||||
},
|
||||
@ -871,7 +873,7 @@ func testInMemoryApplyChanges(t *testing.T) {
|
||||
"com": {
|
||||
"example.com": []*InMemoryRecord{
|
||||
{
|
||||
Endpoint: endpoint.Endpoint{
|
||||
Endpoint: &endpoint.Endpoint{
|
||||
DNSName: "example.com",
|
||||
Target: "4.4.4.4",
|
||||
},
|
||||
|
@ -23,6 +23,6 @@ import (
|
||||
|
||||
// Provider defines the interface DNS providers should implement.
|
||||
type Provider interface {
|
||||
Records(zone string) ([]endpoint.Endpoint, error)
|
||||
Records(zone string) ([]*endpoint.Endpoint, error)
|
||||
ApplyChanges(zone string, changes *plan.Changes) error
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ func NewIngressSource(client kubernetes.Interface, namespace string) Source {
|
||||
|
||||
// Endpoints returns endpoint objects for each host-target combination that should be processed.
|
||||
// Retrieves all ingress resources on all namespaces
|
||||
func (sc *ingressSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
func (sc *ingressSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
ingresses, err := sc.client.Extensions().Ingresses(sc.namespace).List(v1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
endpoints := []endpoint.Endpoint{}
|
||||
endpoints := []*endpoint.Endpoint{}
|
||||
|
||||
for _, ing := range ingresses.Items {
|
||||
ingEndpoints := endpointsFromIngress(&ing)
|
||||
@ -58,8 +58,8 @@ func (sc *ingressSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
}
|
||||
|
||||
// endpointsFromIngress extracts the endpoints from ingress object
|
||||
func endpointsFromIngress(ing *v1beta1.Ingress) []endpoint.Endpoint {
|
||||
var endpoints []endpoint.Endpoint
|
||||
func endpointsFromIngress(ing *v1beta1.Ingress) []*endpoint.Endpoint {
|
||||
var endpoints []*endpoint.Endpoint
|
||||
|
||||
// Check controller annotation to see if we are responsible.
|
||||
controller, exists := ing.Annotations[controllerAnnotationKey]
|
||||
@ -73,16 +73,10 @@ func endpointsFromIngress(ing *v1beta1.Ingress) []endpoint.Endpoint {
|
||||
}
|
||||
for _, lb := range ing.Status.LoadBalancer.Ingress {
|
||||
if lb.IP != "" {
|
||||
endpoints = append(endpoints, endpoint.Endpoint{
|
||||
DNSName: sanitizeHostname(rule.Host),
|
||||
Target: lb.IP,
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(sanitizeHostname(rule.Host), lb.IP))
|
||||
}
|
||||
if lb.Hostname != "" {
|
||||
endpoints = append(endpoints, endpoint.Endpoint{
|
||||
DNSName: sanitizeHostname(rule.Host),
|
||||
Target: lb.Hostname,
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(sanitizeHostname(rule.Host), lb.Hostname))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
for _, ti := range []struct {
|
||||
title string
|
||||
ingress fakeIngress
|
||||
expected []endpoint.Endpoint
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
title: "one rule.host one lb.hostname",
|
||||
@ -45,7 +45,7 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
dnsnames: []string{"foo.bar"},
|
||||
hostnames: []string{"lb.com"},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.",
|
||||
Target: "lb.com",
|
||||
@ -58,7 +58,7 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
dnsnames: []string{"foo.bar"},
|
||||
ips: []string{"8.8.8.8"},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.",
|
||||
Target: "8.8.8.8",
|
||||
@ -72,7 +72,7 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
ips: []string{"8.8.8.8", "127.0.0.1"},
|
||||
hostnames: []string{"elb.com", "alb.com"},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "foo.bar.",
|
||||
Target: "8.8.8.8",
|
||||
@ -97,7 +97,7 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
ips: []string{"8.8.8.8", "127.0.0.1"},
|
||||
hostnames: []string{"elb.com", "alb.com"},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "one empty rule.host",
|
||||
@ -106,14 +106,14 @@ func testEndpointsFromIngress(t *testing.T) {
|
||||
ips: []string{"8.8.8.8", "127.0.0.1"},
|
||||
hostnames: []string{"elb.com", "alb.com"},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "no targets",
|
||||
ingress: fakeIngress{
|
||||
dnsnames: []string{""},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
} {
|
||||
t.Run(ti.title, func(t *testing.T) {
|
||||
@ -129,7 +129,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
title string
|
||||
targetNamespace string
|
||||
ingressItems []fakeIngress
|
||||
expected []endpoint.Endpoint
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
title: "no ingress",
|
||||
@ -152,7 +152,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
hostnames: []string{"lb.com"},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org.",
|
||||
Target: "8.8.8.8",
|
||||
@ -180,7 +180,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
hostnames: []string{"lb.com"},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org.",
|
||||
Target: "8.8.8.8",
|
||||
@ -208,7 +208,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
hostnames: []string{"lb.com"},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org.",
|
||||
Target: "8.8.8.8",
|
||||
@ -229,7 +229,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
ips: []string{"8.8.8.8"},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{
|
||||
expected: []*endpoint.Endpoint{
|
||||
{
|
||||
DNSName: "example.org.",
|
||||
Target: "8.8.8.8",
|
||||
@ -250,7 +250,7 @@ func testIngressEndpoints(t *testing.T) {
|
||||
ips: []string{"8.8.8.8"},
|
||||
},
|
||||
},
|
||||
expected: []endpoint.Endpoint{},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
} {
|
||||
t.Run(ti.title, func(t *testing.T) {
|
||||
|
@ -20,15 +20,15 @@ import "github.com/kubernetes-incubator/external-dns/endpoint"
|
||||
|
||||
// mockSource returns mock endpoints.
|
||||
type mockSource struct {
|
||||
store []endpoint.Endpoint
|
||||
store []*endpoint.Endpoint
|
||||
}
|
||||
|
||||
// NewMockSource creates a new mockSource returning the given endpoints.
|
||||
func NewMockSource(endpoints []endpoint.Endpoint) Source {
|
||||
func NewMockSource(endpoints []*endpoint.Endpoint) Source {
|
||||
return &mockSource{store: endpoints}
|
||||
}
|
||||
|
||||
// Endpoints returns the desired mock endpoints.
|
||||
func (s *mockSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
func (s *mockSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
return s.store, nil
|
||||
}
|
||||
|
@ -33,15 +33,15 @@ func TestMockSource(t *testing.T) {
|
||||
func testMockSourceEndpoints(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
title string
|
||||
givenAndExpected []endpoint.Endpoint
|
||||
givenAndExpected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
"no endpoints given return no endpoints",
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"single endpoint given returns single endpoint",
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo", Target: "8.8.8.8"},
|
||||
},
|
||||
},
|
||||
|
@ -24,8 +24,8 @@ type multiSource struct {
|
||||
}
|
||||
|
||||
// Endpoints collects endpoints of all nested Sources and returns them in a single slice.
|
||||
func (ms *multiSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
result := []endpoint.Endpoint{}
|
||||
func (ms *multiSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
result := []*endpoint.Endpoint{}
|
||||
|
||||
for _, s := range ms.children {
|
||||
endpoints, err := s.Endpoints()
|
||||
|
@ -31,33 +31,33 @@ func TestMultiSource(t *testing.T) {
|
||||
|
||||
// testMultiSourceEndpoints tests merged endpoints from children are returned.
|
||||
func testMultiSourceEndpoints(t *testing.T) {
|
||||
foo := endpoint.Endpoint{DNSName: "foo", Target: "8.8.8.8"}
|
||||
bar := endpoint.Endpoint{DNSName: "bar", Target: "8.8.4.4"}
|
||||
foo := &endpoint.Endpoint{DNSName: "foo", Target: "8.8.8.8"}
|
||||
bar := &endpoint.Endpoint{DNSName: "bar", Target: "8.8.4.4"}
|
||||
|
||||
for _, tc := range []struct {
|
||||
title string
|
||||
nestedEndpoints [][]endpoint.Endpoint
|
||||
expected []endpoint.Endpoint
|
||||
nestedEndpoints [][]*endpoint.Endpoint
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
"no child sources return no endpoints",
|
||||
nil,
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"single empty child source returns no endpoints",
|
||||
[][]endpoint.Endpoint{{}},
|
||||
[]endpoint.Endpoint{},
|
||||
[][]*endpoint.Endpoint{{}},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"single non-empty child source returns child's endpoints",
|
||||
[][]endpoint.Endpoint{{foo}},
|
||||
[]endpoint.Endpoint{foo},
|
||||
[][]*endpoint.Endpoint{{foo}},
|
||||
[]*endpoint.Endpoint{foo},
|
||||
},
|
||||
{
|
||||
"multiple non-empty child sources returns merged children's endpoints",
|
||||
[][]endpoint.Endpoint{{foo}, {bar}},
|
||||
[]endpoint.Endpoint{foo, bar},
|
||||
[][]*endpoint.Endpoint{{foo}, {bar}},
|
||||
[]*endpoint.Endpoint{foo, bar},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.title, func(t *testing.T) {
|
||||
|
@ -39,13 +39,13 @@ func NewServiceSource(client kubernetes.Interface, namespace string) Source {
|
||||
}
|
||||
|
||||
// Endpoints returns endpoint objects for each service that should be processed.
|
||||
func (sc *serviceSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
func (sc *serviceSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
services, err := sc.client.CoreV1().Services(sc.namespace).List(v1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
endpoints := []endpoint.Endpoint{}
|
||||
endpoints := []*endpoint.Endpoint{}
|
||||
|
||||
for _, svc := range services.Items {
|
||||
svcEndpoints := endpointsFromService(&svc)
|
||||
@ -58,8 +58,8 @@ func (sc *serviceSource) Endpoints() ([]endpoint.Endpoint, error) {
|
||||
}
|
||||
|
||||
// endpointsFromService extracts the endpoints from a service object
|
||||
func endpointsFromService(svc *v1.Service) []endpoint.Endpoint {
|
||||
var endpoints []endpoint.Endpoint
|
||||
func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint {
|
||||
var endpoints []*endpoint.Endpoint
|
||||
|
||||
// Check controller annotation to see if we are responsible.
|
||||
controller, exists := svc.Annotations[controllerAnnotationKey]
|
||||
@ -76,16 +76,10 @@ func endpointsFromService(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.Endpoint{
|
||||
DNSName: hostname,
|
||||
Target: lb.IP,
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.IP))
|
||||
}
|
||||
if lb.Hostname != "" {
|
||||
endpoints = append(endpoints, endpoint.Endpoint{
|
||||
DNSName: hostname,
|
||||
Target: lb.Hostname,
|
||||
})
|
||||
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
svcName string
|
||||
annotations map[string]string
|
||||
lbs []string
|
||||
expected []endpoint.Endpoint
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
"no annotated services return no endpoints",
|
||||
@ -51,7 +51,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
"foo",
|
||||
map[string]string{},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"annotated services return an endpoint with target IP",
|
||||
@ -62,7 +62,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "1.2.3.4"},
|
||||
},
|
||||
},
|
||||
@ -75,7 +75,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"lb.example.com"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "lb.example.com"},
|
||||
},
|
||||
},
|
||||
@ -89,7 +89,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "1.2.3.4"},
|
||||
},
|
||||
},
|
||||
@ -103,7 +103,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"services are found in target namespace",
|
||||
@ -114,7 +114,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "1.2.3.4"},
|
||||
},
|
||||
},
|
||||
@ -127,7 +127,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"services are found in all namespaces",
|
||||
@ -138,7 +138,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "1.2.3.4"},
|
||||
},
|
||||
},
|
||||
@ -151,7 +151,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{},
|
||||
[]endpoint.Endpoint{},
|
||||
[]*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
"multiple external entrypoints return multiple endpoints",
|
||||
@ -162,7 +162,7 @@ func testServiceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "foo.example.org",
|
||||
},
|
||||
[]string{"1.2.3.4", "8.8.8.8"},
|
||||
[]endpoint.Endpoint{
|
||||
[]*endpoint.Endpoint{
|
||||
{DNSName: "foo.example.org", Target: "1.2.3.4"},
|
||||
{DNSName: "foo.example.org", Target: "8.8.8.8"},
|
||||
},
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
|
||||
// test helper functions
|
||||
|
||||
func validateEndpoints(t *testing.T, endpoints, expected []endpoint.Endpoint) {
|
||||
func validateEndpoints(t *testing.T, endpoints, expected []*endpoint.Endpoint) {
|
||||
if len(endpoints) != len(expected) {
|
||||
t.Fatalf("expected %d endpoints, got %d", len(expected), len(endpoints))
|
||||
}
|
||||
@ -34,7 +34,7 @@ func validateEndpoints(t *testing.T, endpoints, expected []endpoint.Endpoint) {
|
||||
}
|
||||
}
|
||||
|
||||
func validateEndpoint(t *testing.T, endpoint, expected endpoint.Endpoint) {
|
||||
func validateEndpoint(t *testing.T, endpoint, expected *endpoint.Endpoint) {
|
||||
if endpoint.DNSName != expected.DNSName {
|
||||
t.Errorf("expected %s, got %s", expected.DNSName, endpoint.DNSName)
|
||||
}
|
||||
|
@ -31,5 +31,5 @@ const (
|
||||
|
||||
// Source defines the interface Endpoint sources should implement.
|
||||
type Source interface {
|
||||
Endpoints() ([]endpoint.Endpoint, error)
|
||||
Endpoints() ([]*endpoint.Endpoint, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user