Skip to content

Commit 8e4bf8e

Browse files
chore(source): standardize sources with merge endpionts and deduplicate targets
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
1 parent d38daef commit 8e4bf8e

27 files changed

+171
-106
lines changed

endpoint/endpoint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ type EndpointKey struct {
222222
RecordType string
223223
SetIdentifier string
224224
RecordTTL TTL
225+
Target string
225226
}
226227

227228
type ObjectRef = events.ObjectReference

source/ambassador_host.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"sort"
2423
"strings"
2524

2625
ambassador "github.com/datawire/ambassador/pkg/api/getambassador.io/v2"
@@ -181,11 +180,7 @@ func (sc *ambassadorHostSource) Endpoints(ctx context.Context) ([]*endpoint.Endp
181180
endpoints = append(endpoints, hostEndpoints...)
182181
}
183182

184-
for _, ep := range endpoints {
185-
sort.Sort(ep.Targets)
186-
}
187-
188-
return endpoints, nil
183+
return MergeEndpoints(endpoints), nil
189184
}
190185

191186
// endpointsFromHost extracts the endpoints from a Host object

source/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (cs *connectorSource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, e
7171

7272
log.Debugf("Received endpoints: %#v", endpoints)
7373

74-
return endpoints, nil
74+
return MergeEndpoints(endpoints), nil
7575
}
7676

7777
func (cs *connectorSource) AddEventHandler(_ context.Context, _ func()) {}

source/contour_httpproxy.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"sort"
2423
"text/template"
2524

2625
projectcontour "github.com/projectcontour/contour/apis/projectcontour/v1"
@@ -167,11 +166,7 @@ func (sc *httpProxySource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, e
167166
endpoints = append(endpoints, hpEndpoints...)
168167
}
169168

170-
for _, ep := range endpoints {
171-
sort.Sort(ep.Targets)
172-
}
173-
174-
return endpoints, nil
169+
return MergeEndpoints(endpoints), nil
175170
}
176171

177172
func (sc *httpProxySource) endpointsFromTemplate(httpProxy *projectcontour.HTTPProxy) ([]*endpoint.Endpoint, error) {

source/crd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
230230
}
231231
}
232232

233-
return endpoints, nil
233+
return MergeEndpoints(endpoints), nil
234234
}
235235

236236
func (cs *crdSource) watch(ctx context.Context, opts *metav1.ListOptions) (watch.Interface, error) {

source/f5_transportserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (ts *f5TransportServerSource) Endpoints(_ context.Context) ([]*endpoint.End
131131
return nil, err
132132
}
133133

134-
return endpoints, nil
134+
return MergeEndpoints(endpoints), nil
135135
}
136136

137137
func (ts *f5TransportServerSource) AddEventHandler(_ context.Context, handler func()) {

source/f5_virtualserver.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"sort"
2423
"strings"
2524

2625
f5 "github.com/F5Networks/k8s-bigip-ctlr/v2/config/apis/cis/v1"
@@ -131,12 +130,7 @@ func (vs *f5VirtualServerSource) Endpoints(_ context.Context) ([]*endpoint.Endpo
131130
return nil, err
132131
}
133132

134-
// Sort endpoints
135-
for _, ep := range endpoints {
136-
sort.Sort(ep.Targets)
137-
}
138-
139-
return endpoints, nil
133+
return MergeEndpoints(endpoints), nil
140134
}
141135

142136
func (vs *f5VirtualServerSource) AddEventHandler(_ context.Context, handler func()) {

source/f5_virtualserver_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const defaultF5VirtualServerNamespace = "virtualserver"
3939

4040
func TestF5VirtualServerEndpoints(t *testing.T) {
4141
t.Parallel()
42-
4342
tests := []struct {
4443
name string
4544
annotationFilter string
@@ -349,7 +348,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
349348
},
350349
expected: []*endpoint.Endpoint{
351350
{
352-
DNSName: "www.example.com",
351+
DNSName: "alias1.example.com",
353352
Targets: []string{"192.168.1.100"},
354353
RecordType: endpoint.RecordTypeA,
355354
RecordTTL: 0,
@@ -358,7 +357,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
358357
},
359358
},
360359
{
361-
DNSName: "alias1.example.com",
360+
DNSName: "alias2.example.com",
362361
Targets: []string{"192.168.1.100"},
363362
RecordType: endpoint.RecordTypeA,
364363
RecordTTL: 0,
@@ -367,7 +366,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
367366
},
368367
},
369368
{
370-
DNSName: "alias2.example.com",
369+
DNSName: "www.example.com",
371370
Targets: []string{"192.168.1.100"},
372371
RecordType: endpoint.RecordTypeA,
373372
RecordTTL: 0,
@@ -600,7 +599,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
600599
endpoints, err := source.Endpoints(context.Background())
601600
require.NoError(t, err)
602601
assert.Len(t, endpoints, len(tc.expected))
603-
assert.Equal(t, tc.expected, endpoints)
602+
validateEndpoints(t, endpoints, tc.expected)
604603
})
605604
}
606605
}

source/fake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (sc *fakeSource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, error)
7575
endpoints[i] = sc.generateEndpoint()
7676
}
7777

78-
return endpoints, nil
78+
return MergeEndpoints(endpoints), nil
7979
}
8080

8181
func (sc *fakeSource) generateEndpoint() *endpoint.Endpoint {

source/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (src *gatewayRouteSource) Endpoints(_ context.Context) ([]*endpoint.Endpoin
291291

292292
endpoints = append(endpoints, routeEndpoints...)
293293
}
294-
return endpoints, nil
294+
return MergeEndpoints(endpoints), nil
295295
}
296296

297297
func namespacedName(namespace, name string) types.NamespacedName {

0 commit comments

Comments
 (0)