@@ -30,6 +30,7 @@ import (
30
30
"github.com/projectcontour/contour/internal/contour"
31
31
"github.com/projectcontour/contour/internal/dag"
32
32
"github.com/projectcontour/contour/internal/fixture"
33
+ "github.com/projectcontour/contour/internal/ref"
33
34
"github.com/projectcontour/contour/internal/xds"
34
35
contour_xds_v3 "github.com/projectcontour/contour/internal/xds/v3"
35
36
"github.com/projectcontour/contour/internal/xdscache"
@@ -39,6 +40,7 @@ import (
39
40
"google.golang.org/grpc/credentials/insecure"
40
41
"google.golang.org/grpc/status"
41
42
v1 "k8s.io/api/core/v1"
43
+ discoveryv1 "k8s.io/api/discovery/v1"
42
44
networking_v1 "k8s.io/api/networking/v1"
43
45
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
44
46
"k8s.io/apimachinery/pkg/util/intstr"
@@ -48,6 +50,7 @@ func TestGRPC(t *testing.T) {
48
50
// tr and et is recreated before the start of each test.
49
51
var et * EndpointsTranslator
50
52
var eh * contour.EventHandler
53
+ var est * EndpointSliceTranslator
51
54
52
55
tests := map [string ]func (* testing.T , * grpc.ClientConn ){
53
56
"StreamClusters" : func (t * testing.T , cc * grpc.ClientConn ) {
@@ -104,6 +107,39 @@ func TestGRPC(t *testing.T) {
104
107
checkrecv (t , stream ) // check we receive one notification
105
108
checktimeout (t , stream ) // check that the second receive times out
106
109
},
110
+ "StreamEndpointSlices" : func (t * testing.T , cc * grpc.ClientConn ) {
111
+ et .OnAdd (& discoveryv1.EndpointSlice {
112
+ ObjectMeta : metav1.ObjectMeta {
113
+ Name : "kube-scheduler" ,
114
+ Namespace : "kube-system" ,
115
+ },
116
+ AddressType : discoveryv1 .AddressTypeIPv4 ,
117
+ Endpoints : []discoveryv1.Endpoint {
118
+ {
119
+ Addresses : []string {
120
+ "130.211.139.167" ,
121
+ },
122
+ },
123
+ },
124
+ Ports : []discoveryv1.EndpointPort {
125
+ {
126
+ Port : ref.To [int32 ](80 ),
127
+ },
128
+ {
129
+ Port : ref.To [int32 ](80 ),
130
+ },
131
+ },
132
+ }, false )
133
+
134
+ eds := envoy_service_endpoint_v3 .NewEndpointDiscoveryServiceClient (cc )
135
+ ctx , cancel := context .WithTimeout (context .Background (), 100 * time .Millisecond )
136
+ defer cancel ()
137
+ stream , err := eds .StreamEndpoints (ctx )
138
+ require .NoError (t , err )
139
+ sendreq (t , stream , resource .EndpointType ) // send initial notification
140
+ checkrecv (t , stream ) // check we receive one notification
141
+ checktimeout (t , stream ) // check that the second receive times out
142
+ },
107
143
"StreamListeners" : func (t * testing.T , cc * grpc.ClientConn ) {
108
144
// add an ingress, which will create a non tls listener
109
145
eh .OnAdd (& networking_v1.Ingress {
@@ -200,12 +236,14 @@ func TestGRPC(t *testing.T) {
200
236
for name , fn := range tests {
201
237
t .Run (name , func (t * testing.T ) {
202
238
et = NewEndpointsTranslator (fixture .NewTestLogger (t ))
239
+ est = NewEndpointSliceTranslator (fixture .NewTestLogger (t ))
203
240
204
241
resources := []xdscache.ResourceCache {
205
242
& ListenerCache {},
206
243
& SecretCache {},
207
244
& RouteCache {},
208
245
& ClusterCache {},
246
+ est ,
209
247
et ,
210
248
& RuntimeCache {},
211
249
}
0 commit comments