do not merge endpoints with different set identifier

This commit is contained in:
Marlene 2021-08-29 16:25:55 +10:00
parent 2f1aff4fe4
commit c1af8a40ec
No known key found for this signature in database
GPG Key ID: 6152960070D6B64D
2 changed files with 45 additions and 19 deletions

View File

@ -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 {

View File

@ -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,
},