From 0b370ac6baab099504bb8449ba9fe192a7638cc9 Mon Sep 17 00:00:00 2001 From: Artem Voronin Date: Thu, 20 May 2021 15:12:42 +0300 Subject: [PATCH 1/3] Fixed registry aws-sd nil labels --- registry/aws_sd_registry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/registry/aws_sd_registry.go b/registry/aws_sd_registry.go index e08537419c..453febfd3d 100644 --- a/registry/aws_sd_registry.go +++ b/registry/aws_sd_registry.go @@ -83,6 +83,9 @@ func (sdr *AWSSDRegistry) ApplyChanges(ctx context.Context, changes *plan.Change func (sdr *AWSSDRegistry) updateLabels(endpoints []*endpoint.Endpoint) { for _, ep := range endpoints { + if ep.Labels == nil { + ep.Labels = make(map[string]string) + } ep.Labels[endpoint.OwnerLabelKey] = sdr.ownerID ep.Labels[endpoint.AWSSDDescriptionLabel] = ep.Labels.Serialize(false) } From ea9158cbf2e5b3cc2c5f89e3e3f1da6046253443 Mon Sep 17 00:00:00 2001 From: Artem Voronin Date: Wed, 2 Jun 2021 18:47:20 +0300 Subject: [PATCH 2/3] Fixed node nil labels map with aws-sd registry --- source/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/source/node.go b/source/node.go index 0ac6ea493f..31f330043e 100644 --- a/source/node.go +++ b/source/node.go @@ -151,6 +151,7 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro } ep.Targets = endpoint.Targets(addrs) + ep.Labels = endpoint.NewLabels() log.Debugf("adding endpoint %s", ep) if _, ok := endpoints[ep.DNSName]; ok { From 0aae14288ccceec35905a983b8aa502bddd42f15 Mon Sep 17 00:00:00 2001 From: Artem Voronin Date: Wed, 23 Jun 2021 22:01:09 +0300 Subject: [PATCH 3/3] Added test for node with nil labels --- source/node_test.go | 13 +++++++++++++ source/shared_test.go | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/source/node_test.go b/source/node_test.go index d82425c47e..e6ce849c9c 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -307,6 +307,19 @@ func testNodeSourceEndpoints(t *testing.T) { }, false, }, + { + "node with nil Lables returns valid endpoint", + "", + "", + "node1", + []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, + nil, + map[string]string{}, + []*endpoint.Endpoint{ + {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, Labels: map[string]string{}}, + }, + false, + }, } { t.Run(tc.title, func(t *testing.T) { // Create a Kubernetes testing client diff --git a/source/shared_test.go b/source/shared_test.go index d7043a82b9..9f90608366 100644 --- a/source/shared_test.go +++ b/source/shared_test.go @@ -20,6 +20,7 @@ import ( "sort" "strings" "testing" + "reflect" "sigs.k8s.io/external-dns/endpoint" ) @@ -60,4 +61,9 @@ func validateEndpoint(t *testing.T, endpoint, expected *endpoint.Endpoint) { if expected.RecordType != "" && endpoint.RecordType != expected.RecordType { t.Errorf("expected %s, got %s", expected.RecordType, endpoint.RecordType) } + + // if non-empty labels are expected, check that they matches. + if expected.Labels != nil && !reflect.DeepEqual(endpoint.Labels,expected.Labels) { + t.Errorf("expected %s, got %s", expected.Labels, endpoint.Labels) + } }