Skip to content

Commit

Permalink
change []string to []Target
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
  • Loading branch information
dongjiang1989 committed Apr 15, 2024
1 parent b57bc37 commit 80a3e4c
Show file tree
Hide file tree
Showing 123 changed files with 1,510 additions and 1,526 deletions.
124 changes: 62 additions & 62 deletions controller/controller_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ func NewTargets(target ...string) Targets {
func (t Targets) String() string {
vals := []string{}
for _, val := range t {
vals = append(vals, val.Raw)
vals = append(vals, val.String())
}
return strings.Join(vals, ";")
}

func (t Targets) Map() []string {
ret := make([]string, len(t))
for i, e := range t {
ret[i] = e.Raw
ret[i] = e.String()
}
return ret
}
Expand Down
14 changes: 7 additions & 7 deletions internal/testutils/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ func TestExampleSameEndpoints(t *testing.T) {
eps := []*endpoint.Endpoint{
{
DNSName: "example.org",
Targets: endpoint.Targets{"load-balancer.org"},
Targets: endpoint.NewTargets("load-balancer.org"),
},
{
DNSName: "example.org",
Targets: endpoint.Targets{"load-balancer.org"},
Targets: endpoint.NewTargets("load-balancer.org"),
RecordType: endpoint.RecordTypeTXT,
},
{
DNSName: "abc.com",
Targets: endpoint.Targets{"something"},
Targets: endpoint.NewTargets("something"),
RecordType: endpoint.RecordTypeTXT,
},
{
DNSName: "abc.com",
Targets: endpoint.Targets{"1.2.3.4"},
Targets: endpoint.NewTargets("1.2.3.4"),
RecordType: endpoint.RecordTypeA,
SetIdentifier: "test-set-1",
},
{
DNSName: "bbc.com",
Targets: endpoint.Targets{"foo.com"},
Targets: endpoint.NewTargets("foo.com"),
RecordType: endpoint.RecordTypeCNAME,
},
{
DNSName: "cbc.com",
Targets: endpoint.Targets{"foo.com"},
Targets: endpoint.NewTargets("foo.com"),
RecordType: "CNAME",
RecordTTL: endpoint.TTL(60),
},
{
DNSName: "example.org",
Targets: endpoint.Targets{"load-balancer.org"},
Targets: endpoint.NewTargets("load-balancer.org"),
ProviderSpecific: endpoint.ProviderSpecific{
endpoint.ProviderSpecificProperty{Name: "foo", Value: "bar"},
},
Expand Down
18 changes: 9 additions & 9 deletions plan/conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,71 +47,71 @@ func (suite *ResolverSuite) SetupTest() {
// initialize endpoints used in tests
suite.fooV1Cname = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v1"},
Targets: endpoint.NewTargets("v1"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v1",
},
}
suite.fooV2Cname = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v2"},
Targets: endpoint.NewTargets("v2"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v2",
},
}
suite.fooV2CnameDuplicate = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v2"},
Targets: endpoint.NewTargets("v2"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v2-duplicate",
},
}
suite.fooA5 = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"5.5.5.5"},
Targets: endpoint.NewTargets("5.5.5.5"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-5",
},
}
suite.fooAAAA5 = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"2001:DB8::1"},
Targets: endpoint.NewTargets("2001:DB8::1"),
RecordType: "AAAA",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-5",
},
}
suite.bar127A = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
}
suite.bar127AAnother = &endpoint.Endpoint{ // TODO: remove this once we move to multiple targets under same endpoint
DNSName: "bar",
Targets: endpoint.Targets{"8.8.8.8"},
Targets: endpoint.NewTargets("8.8.8.8"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
}
suite.bar192A = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"192.168.0.1"},
Targets: endpoint.NewTargets("192.168.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-192",
},
}
suite.legacyBar192A = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"192.168.0.1"},
Targets: endpoint.NewTargets("192.168.0.1"),
RecordType: "A",
}
}
Expand Down
44 changes: 22 additions & 22 deletions plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type PlanTestSuite struct {
func (suite *PlanTestSuite) SetupTest() {
suite.fooV1Cname = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v1"},
Targets: endpoint.NewTargets("v1"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v1",
Expand All @@ -66,7 +66,7 @@ func (suite *PlanTestSuite) SetupTest() {
// same resource as fooV1Cname, but target is different. It will never be picked because its target lexicographically bigger than "v1"
suite.fooV3CnameSameResource = &endpoint.Endpoint{ // TODO: remove this once endpoint can support multiple targets
DNSName: "foo",
Targets: endpoint.Targets{"v3"},
Targets: endpoint.NewTargets("v3"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v1",
Expand All @@ -75,15 +75,15 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.fooV2Cname = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v2"},
Targets: endpoint.NewTargets("v2"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v2",
},
}
suite.fooV2CnameUppercase = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"V2"},
Targets: endpoint.NewTargets("V2"),
RecordType: "CNAME",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-v2",
Expand All @@ -95,52 +95,52 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.fooV2CnameNoLabel = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"v2"},
Targets: endpoint.NewTargets("v2"),
RecordType: "CNAME",
}
suite.fooA5 = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"5.5.5.5"},
Targets: endpoint.NewTargets("5.5.5.5"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-5",
},
}
suite.fooAAAA = &endpoint.Endpoint{
DNSName: "foo",
Targets: endpoint.Targets{"2001:DB8::1"},
Targets: endpoint.NewTargets("2001:DB8::1"),
RecordType: "AAAA",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/foo-AAAA",
},
}
suite.dsA = &endpoint.Endpoint{
DNSName: "ds",
Targets: endpoint.Targets{"1.1.1.1"},
Targets: endpoint.NewTargets("1.1.1.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/ds",
},
}
suite.dsAAAA = &endpoint.Endpoint{
DNSName: "ds",
Targets: endpoint.Targets{"2001:DB8::1"},
Targets: endpoint.NewTargets("2001:DB8::1"),
RecordType: "AAAA",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/ds-AAAAA",
},
}
suite.bar127A = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
},
}
suite.bar127AWithTTL = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
RecordTTL: 300,
Labels: map[string]string{
Expand All @@ -149,7 +149,7 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.bar127AWithProviderSpecificTrue = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
Expand All @@ -167,7 +167,7 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.bar127AWithProviderSpecificFalse = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
Expand All @@ -185,7 +185,7 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.bar127AWithProviderSpecificUnset = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"127.0.0.1"},
Targets: endpoint.NewTargets("127.0.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-127",
Expand All @@ -199,48 +199,48 @@ func (suite *PlanTestSuite) SetupTest() {
}
suite.bar192A = &endpoint.Endpoint{
DNSName: "bar",
Targets: endpoint.Targets{"192.168.0.1"},
Targets: endpoint.NewTargets("192.168.0.1"),
RecordType: "A",
Labels: map[string]string{
endpoint.ResourceLabelKey: "ingress/default/bar-192",
},
}
suite.multiple1 = &endpoint.Endpoint{
DNSName: "multiple",
Targets: endpoint.Targets{"192.168.0.1"},
Targets: endpoint.NewTargets("192.168.0.1"),
RecordType: "A",
SetIdentifier: "test-set-1",
}
suite.multiple2 = &endpoint.Endpoint{
DNSName: "multiple",
Targets: endpoint.Targets{"192.168.0.2"},
Targets: endpoint.NewTargets("192.168.0.2"),
RecordType: "A",
SetIdentifier: "test-set-1",
}
suite.multiple3 = &endpoint.Endpoint{
DNSName: "multiple",
Targets: endpoint.Targets{"192.168.0.2"},
Targets: endpoint.NewTargets("192.168.0.2"),
RecordType: "A",
SetIdentifier: "test-set-2",
}
suite.domainFilterFiltered1 = &endpoint.Endpoint{
DNSName: "foo.domain.tld",
Targets: endpoint.Targets{"1.2.3.4"},
Targets: endpoint.NewTargets("1.2.3.4"),
RecordType: "A",
}
suite.domainFilterFiltered2 = &endpoint.Endpoint{
DNSName: "bar.domain.tld",
Targets: endpoint.Targets{"1.2.3.5"},
Targets: endpoint.NewTargets("1.2.3.5"),
RecordType: "A",
}
suite.domainFilterFiltered3 = &endpoint.Endpoint{
DNSName: "baz.domain.tld",
Targets: endpoint.Targets{"1.2.3.6"},
Targets: endpoint.NewTargets("1.2.3.6"),
RecordType: "A",
}
suite.domainFilterExcluded = &endpoint.Endpoint{
DNSName: "foo.ex.domain.tld",
Targets: endpoint.Targets{"1.1.1.1"},
Targets: endpoint.NewTargets("1.1.1.1"),
RecordType: "A",
}
}
Expand Down
8 changes: 4 additions & 4 deletions plan/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestApply(t *testing.T) {
// empty list of records
empty := []*endpoint.Endpoint{}
// a simple entry
fooV1 := []*endpoint.Endpoint{{DNSName: "foo", Targets: endpoint.Targets{"v1"}}}
fooV1 := []*endpoint.Endpoint{{DNSName: "foo", Targets: endpoint.NewTargets("v1")}}
// the same entry but with different target
fooV2 := []*endpoint.Endpoint{{DNSName: "foo", Targets: endpoint.Targets{"v2"}}}
fooV2 := []*endpoint.Endpoint{{DNSName: "foo", Targets: endpoint.NewTargets("v2")}}
// another two simple entries
bar := []*endpoint.Endpoint{{DNSName: "bar", Targets: endpoint.Targets{"v1"}}}
baz := []*endpoint.Endpoint{{DNSName: "baz", Targets: endpoint.Targets{"v1"}}}
bar := []*endpoint.Endpoint{{DNSName: "bar", Targets: endpoint.NewTargets("v1")}}
baz := []*endpoint.Endpoint{{DNSName: "baz", Targets: endpoint.NewTargets("v1")}}

for _, tc := range []struct {
policy Policy
Expand Down
4 changes: 2 additions & 2 deletions provider/akamai/akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (p AkamaiProvider) createRecordsets(zoneNameIDMapper provider.ZoneIDName, e
newrec := newAkamaiRecordset(endpoint.DNSName,
endpoint.RecordType,
ttlAsInt(endpoint.RecordTTL),
cleanTargets(endpoint.RecordType, endpoint.Targets...))
cleanTargets(endpoint.RecordType, endpoint.Targets.Map()...))
logfields := log.Fields{
"record": newrec.Name,
"type": newrec.Type,
Expand Down Expand Up @@ -461,7 +461,7 @@ func (p AkamaiProvider) updateNewRecordsets(zoneNameIDMapper provider.ZoneIDName
return err
}
rec.TTL = ttlAsInt(endpoint.RecordTTL)
rec.Target = cleanTargets(endpoint.RecordType, endpoint.Targets...)
rec.Target = cleanTargets(endpoint.RecordType, endpoint.Targets.Map()...)
if err := p.client.UpdateRecord(rec, zoneName, true); err != nil {
log.Errorf("Akamai Edge DNS recordset update failed. Error: %s", err.Error())
return err
Expand Down
20 changes: 10 additions & 10 deletions provider/akamai/akamai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,17 @@ func TestAkamaiApplyChanges(t *testing.T) {
stub.setOutput("zone", []interface{}{"example.com"})
changes := &plan.Changes{}
changes.Create = []*endpoint.Endpoint{
{DNSName: "www.example.com", RecordType: "A", Targets: endpoint.Targets{"target"}, RecordTTL: 300},
{DNSName: "test.example.com", RecordType: "A", Targets: endpoint.Targets{"target"}, RecordTTL: 300},
{DNSName: "test.this.example.com", RecordType: "A", Targets: endpoint.Targets{"127.0.0.1"}, RecordTTL: 300},
{DNSName: "www.example.com", RecordType: "TXT", Targets: endpoint.Targets{"heritage=external-dns,external-dns/owner=default"}, RecordTTL: 300},
{DNSName: "test.example.com", RecordType: "TXT", Targets: endpoint.Targets{"heritage=external-dns,external-dns/owner=default"}, RecordTTL: 300},
{DNSName: "test.this.example.com", RecordType: "TXT", Targets: endpoint.Targets{"heritage=external-dns,external-dns/owner=default"}, RecordTTL: 300},
{DNSName: "another.example.com", RecordType: "A", Targets: endpoint.Targets{"target"}},
{DNSName: "www.example.com", RecordType: "A", Targets: endpoint.NewTargets("target"), RecordTTL: 300},
{DNSName: "test.example.com", RecordType: "A", Targets: endpoint.NewTargets("target"), RecordTTL: 300},
{DNSName: "test.this.example.com", RecordType: "A", Targets: endpoint.NewTargets("127.0.0.1"), RecordTTL: 300},
{DNSName: "www.example.com", RecordType: "TXT", Targets: endpoint.NewTargets("heritage=external-dns,external-dns/owner=default"), RecordTTL: 300},
{DNSName: "test.example.com", RecordType: "TXT", Targets: endpoint.NewTargets("heritage=external-dns,external-dns/owner=default"), RecordTTL: 300},
{DNSName: "test.this.example.com", RecordType: "TXT", Targets: endpoint.NewTargets("heritage=external-dns,external-dns/owner=default"), RecordTTL: 300},
{DNSName: "another.example.com", RecordType: "A", Targets: endpoint.NewTargets("target")},
}
changes.Delete = []*endpoint.Endpoint{{DNSName: "delete.example.com", RecordType: "A", Targets: endpoint.Targets{"target"}, RecordTTL: 300}}
changes.UpdateOld = []*endpoint.Endpoint{{DNSName: "old.example.com", RecordType: "A", Targets: endpoint.Targets{"target-old"}, RecordTTL: 300}}
changes.UpdateNew = []*endpoint.Endpoint{{DNSName: "update.example.com", Targets: endpoint.Targets{"target-new"}, RecordType: "CNAME", RecordTTL: 300}}
changes.Delete = []*endpoint.Endpoint{{DNSName: "delete.example.com", RecordType: "A", Targets: endpoint.NewTargets("target"), RecordTTL: 300}}
changes.UpdateOld = []*endpoint.Endpoint{{DNSName: "old.example.com", RecordType: "A", Targets: endpoint.NewTargets("target-old"), RecordTTL: 300}}
changes.UpdateNew = []*endpoint.Endpoint{{DNSName: "update.example.com", Targets: endpoint.NewTargets("target-new"), RecordType: "CNAME", RecordTTL: 300}}
apply := c.ApplyChanges(context.Background(), changes)
assert.Nil(t, apply)
}
Loading

0 comments on commit 80a3e4c

Please sign in to comment.