Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,11 @@ func (e *Endpoint) UniqueOrderedTargets() {
func FilterEndpointsByOwnerID(ownerID string, eps []*Endpoint) []*Endpoint {
filtered := []*Endpoint{}
for _, ep := range eps {
if endpointOwner, ok := ep.Labels[OwnerLabelKey]; !ok || endpointOwner != ownerID {
log.Debugf(`Skipping endpoint %v because owner id does not match, found: "%s", required: "%s"`, ep, endpointOwner, ownerID)
endpointOwner, ok := ep.Labels[OwnerLabelKey]
if !ok {
log.Debugf(`Skipping endpoint %v because of missing owner label (required: "%s")`, ep, ownerID)
Comment thread
bachorp marked this conversation as resolved.
} else if endpointOwner != ownerID {
log.Debugf(`Skipping endpoint %v because owner id does not match (found: "%s", required: "%s")`, ep, endpointOwner, ownerID)
} else {
filtered = append(filtered, ep)
}
Expand Down
62 changes: 62 additions & 0 deletions internal/testutils/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sort"
"testing"

log "github.com/sirupsen/logrus"

"github.com/stretchr/testify/assert"
"sigs.k8s.io/external-dns/endpoint"
)
Expand Down Expand Up @@ -489,3 +491,63 @@ func TestWithLabel(t *testing.T) {
assert.Equal(t, "orig", e.Labels["existing"])
assert.Equal(t, "val", e.Labels["new"])
}

func TestFilterEndpointsByOwnerIDLogging(t *testing.T) {
noOwner := &endpoint.Endpoint{}
ownedByFoo := &endpoint.Endpoint{
Labels: endpoint.Labels{
endpoint.OwnerLabelKey: "foo",
},
}
ownedByBar := &endpoint.Endpoint{
Labels: endpoint.Labels{
endpoint.OwnerLabelKey: "bar",
},
}
tests := []struct {
name string
ownerID string
endpoints []*endpoint.Endpoint
messages []string
messages_not []string
result []*endpoint.Endpoint
}{
{
name: "one_matches",
ownerID: "foo",
endpoints: []*endpoint.Endpoint{ownedByFoo},
messages: []string{},
messages_not: []string{""},
result: []*endpoint.Endpoint{ownedByFoo},
},
{
name: "wrong_owner",
ownerID: "foo",
endpoints: []*endpoint.Endpoint{ownedByFoo, ownedByBar},
messages: []string{"because owner id does not match"},
messages_not: []string{},
result: []*endpoint.Endpoint{ownedByFoo},
},
{
name: "no_owner",
ownerID: "bar",
endpoints: []*endpoint.Endpoint{noOwner, ownedByBar},
messages: []string{"because of missing owner label"},
messages_not: []string{"because owner id does not match"},
result: []*endpoint.Endpoint{ownedByBar},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
hook := LogsUnderTestWithLogLevel(log.DebugLevel, t)
endpoint.FilterEndpointsByOwnerID(tt.ownerID, tt.endpoints)
for _, m := range tt.messages {
TestHelperLogContains(m, hook, t)
}
for _, m := range tt.messages_not {
TestHelperLogNotContains(m, hook, t)
}
})
}
}
Loading