From c1af8a40ecc1ce327d0015c62057e63cafffae04 Mon Sep 17 00:00:00 2001 From: Marlene Date: Sun, 29 Aug 2021 16:25:55 +1000 Subject: [PATCH] do not merge endpoints with different set identifier --- source/service.go | 1 + source/service_test.go | 63 +++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/source/service.go b/source/service.go index 31c4f26a5..4600b6cdb 100644 --- a/source/service.go +++ b/source/service.go @@ -221,6 +221,7 @@ func (sc *serviceSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e lastMergedEndpoint := len(mergedEndpoints) - 1 if mergedEndpoints[lastMergedEndpoint].DNSName == endpoints[i].DNSName && mergedEndpoints[lastMergedEndpoint].RecordType == endpoints[i].RecordType && + mergedEndpoints[lastMergedEndpoint].SetIdentifier == endpoints[i].SetIdentifier && mergedEndpoints[lastMergedEndpoint].RecordTTL == endpoints[i].RecordTTL { mergedEndpoints[lastMergedEndpoint].Targets = append(mergedEndpoints[lastMergedEndpoint].Targets, endpoints[i].Targets[0]) } else { diff --git a/source/service_test.go b/source/service_test.go index 9cf6d8f49..d9f7040d8 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -1324,7 +1324,7 @@ func testMultipleServicesEndpoints(t *testing.T) { ignoreHostnameAnnotation bool labels map[string]string clusterIP string - hostnames map[string]string + hostnames map[string][]string serviceTypesFilter []string expected []*endpoint.Endpoint expectError bool @@ -1342,8 +1342,8 @@ func testMultipleServicesEndpoints(t *testing.T) { false, map[string]string{}, "", - map[string]string{ - "1.2.3.4": "foo.example.org", + map[string][]string{ + "1.2.3.4": {"foo.example.org", ""}, }, []string{}, []*endpoint.Endpoint{ @@ -1364,10 +1364,10 @@ func testMultipleServicesEndpoints(t *testing.T) { false, map[string]string{}, "", - map[string]string{ - "1.2.3.4": "foo.example.org", - "1.2.3.5": "foo.example.org", - "1.2.3.6": "foo.example.org", + map[string][]string{ + "1.2.3.4": {"foo.example.org", ""}, + "1.2.3.5": {"foo.example.org", ""}, + "1.2.3.6": {"foo.example.org", ""}, }, []string{}, []*endpoint.Endpoint{ @@ -1388,14 +1388,14 @@ func testMultipleServicesEndpoints(t *testing.T) { false, map[string]string{}, "", - map[string]string{ - "1.2.3.5": "foo.example.org", - "10.1.1.3": "bar.example.org", - "10.1.1.1": "bar.example.org", - "1.2.3.4": "foo.example.org", - "10.1.1.2": "bar.example.org", - "20.1.1.1": "foobar.example.org", - "1.2.3.6": "foo.example.org", + map[string][]string{ + "1.2.3.5": {"foo.example.org", ""}, + "10.1.1.3": {"bar.example.org", ""}, + "10.1.1.1": {"bar.example.org", ""}, + "1.2.3.4": {"foo.example.org", ""}, + "10.1.1.2": {"bar.example.org", ""}, + "20.1.1.1": {"foobar.example.org", ""}, + "1.2.3.6": {"foo.example.org", ""}, }, []string{}, []*endpoint.Endpoint{ @@ -1405,6 +1405,30 @@ func testMultipleServicesEndpoints(t *testing.T) { }, false, }, + { + "test that services with different set-identifier do not get merged together", + "", + "", + "testing", + "foo", + v1.ServiceTypeLoadBalancer, + "", + "", + false, + false, + map[string]string{}, + "", + map[string][]string{ + "a.elb.com": {"foo.example.org", "a"}, + "b.elb.com": {"foo.example.org", "b"}, + }, + []string{}, + []*endpoint.Endpoint{ + {DNSName: "foo.example.org", Targets: endpoint.Targets{"a.elb.com"}, Labels: map[string]string{endpoint.ResourceLabelKey: "service/testing/fooa.elb.com"}, SetIdentifier: "a"}, + {DNSName: "foo.example.org", Targets: endpoint.Targets{"b.elb.com"}, Labels: map[string]string{endpoint.ResourceLabelKey: "service/testing/foob.elb.com"}, SetIdentifier: "b"}, + }, + false, + }, } { tc := tc t.Run(tc.title, func(t *testing.T) { @@ -1414,12 +1438,13 @@ func testMultipleServicesEndpoints(t *testing.T) { kubernetes := fake.NewSimpleClientset() // Create services to test against - for serviceip, hostname := range tc.hostnames { + for lb, hostname := range tc.hostnames { ingresses := []v1.LoadBalancerIngress{} - ingresses = append(ingresses, v1.LoadBalancerIngress{IP: serviceip}) + ingresses = append(ingresses, v1.LoadBalancerIngress{IP: lb}) annotations := make(map[string]string) - annotations[hostnameAnnotationKey] = hostname + annotations[hostnameAnnotationKey] = hostname[0] + annotations[SetIdentifierKey] = hostname[1] service := &v1.Service{ Spec: v1.ServiceSpec{ @@ -1428,7 +1453,7 @@ func testMultipleServicesEndpoints(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ Namespace: tc.svcNamespace, - Name: tc.svcName + serviceip, + Name: tc.svcName + lb, Labels: tc.labels, Annotations: annotations, },