add labels to endpoints (#121)

* add labels to endpoints

* reset to first commit fix label key

* compare using sameendpoint, add map initializer to newendpoint

* fix(endpoint): drop superflous comment indicators
This commit is contained in:
Yerken 2017-04-04 21:41:13 +02:00 committed by Martin Linkhorst
parent cd5af1f4c9
commit 2eb97f6a83
3 changed files with 17 additions and 5 deletions

View File

@ -16,12 +16,19 @@ limitations under the License.
package endpoint
const (
// OwnerLabelKey is the name of the label that defines the owner of an Endpoint.
OwnerLabelKey = "owner"
)
// Endpoint is a high-level way of a connection between a service and an IP
type Endpoint struct {
// The hostname of the DNS record
DNSName string
// The target the DNS record points to
Target string
// Labels stores labels defined for the Endpoint
Labels map[string]string
}
// NewEndpoint initialization method to be used to create an endpoint
@ -29,5 +36,6 @@ func NewEndpoint(dnsName, target string) *Endpoint {
return &Endpoint{
DNSName: dnsName,
Target: target,
Labels: map[string]string{},
}
}

View File

@ -23,4 +23,7 @@ func TestNewEndpoint(t *testing.T) {
if e.DNSName != "example.org" || e.Target != "1.2.3.4" {
t.Error("endpoint is not initialized correctly")
}
if e.Labels == nil {
t.Error("Labels is not initialized")
}
}

View File

@ -21,6 +21,7 @@ import (
"testing"
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/internal/testutils"
)
// TestCalculate tests that a plan can calculate actions to move a list of
@ -123,13 +124,13 @@ func ExamplePlan() {
}
// Output:
// Create:
// &{baz.example.com 6.6.6.6}
// &{baz.example.com 6.6.6.6 map[]}
// UpdateOld:
// &{bar.example.com 8.8.8.8}
// &{bar.example.com 8.8.8.8 map[]}
// UpdateNew:
// &{bar.example.com 8.8.4.4}
// &{bar.example.com 8.8.4.4 map[]}
// Delete:
// &{foo.example.com 1.2.3.4}
// &{foo.example.com 1.2.3.4 map[]}
}
// validateEntries validates that the list of entries matches expected.
@ -139,7 +140,7 @@ func validateEntries(t *testing.T, entries, expected []*endpoint.Endpoint) {
}
for i := range entries {
if entries[i] != expected[i] {
if !testutils.SameEndpoint(entries[i], expected[i]) {
t.Fatalf("expected %q to match %q", entries, expected)
}
}