@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"net/http"
23
+ "net/url"
23
24
"sort"
24
25
"strings"
25
26
"time"
@@ -53,12 +54,14 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
53
54
featuregatetesting .SetFeatureGateDuringTest (ginkgo .GinkgoTB (), utilfeature .DefaultFeatureGate , featuregate .Feature (clientfeatures .WatchListClient ), true )
54
55
stopCh := make (chan struct {})
55
56
defer close (stopCh )
57
+
56
58
secretInformer := cache .NewSharedIndexInformer (
57
59
& cache.ListWatch {
58
60
ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
59
61
return nil , fmt .Errorf ("unexpected list call" )
60
62
},
61
63
WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
64
+ options = withWellKnownListOptions (options )
62
65
return f .ClientSet .CoreV1 ().Secrets (f .Namespace .Name ).Watch (context .TODO (), options )
63
66
},
64
67
},
@@ -101,16 +104,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
101
104
framework .ExpectNoError (err )
102
105
103
106
ginkgo .By ("Streaming secrets from the server" )
104
- secretList , err := wrappedKubeClient .CoreV1 ().Secrets (f .Namespace .Name ).List (ctx , metav1.ListOptions {})
107
+ secretList , err := wrappedKubeClient .CoreV1 ().Secrets (f .Namespace .Name ).List (ctx , withWellKnownListOptions ( metav1.ListOptions {}) )
105
108
framework .ExpectNoError (err )
106
109
107
110
ginkgo .By ("Verifying if the secret list was properly streamed" )
108
111
streamedSecrets := secretList .Items
109
112
gomega .Expect (cmp .Equal (expectedSecrets , streamedSecrets )).To (gomega .BeTrueBecause ("data received via watchlist must match the added data" ))
110
113
111
114
ginkgo .By ("Verifying if expected requests were sent to the server" )
112
- expectedRequestMadeByKubeClient := getExpectedRequestMadeByClientFor (secretList .ResourceVersion )
113
- gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestMadeByKubeClient ))
115
+ expectedRequestsMadeByKubeClient := getExpectedRequestsMadeByClientFor (secretList .ResourceVersion )
116
+ gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestsMadeByKubeClient ))
114
117
})
115
118
ginkgo .It ("should be requested by dynamic client's List method when WatchListClient is enabled" , func (ctx context.Context ) {
116
119
featuregatetesting .SetFeatureGateDuringTest (ginkgo .GinkgoTB (), utilfeature .DefaultFeatureGate , featuregate .Feature (clientfeatures .WatchListClient ), true )
@@ -123,7 +126,7 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
123
126
framework .ExpectNoError (err )
124
127
125
128
ginkgo .By ("Streaming secrets from the server" )
126
- secretList , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , metav1.ListOptions {})
129
+ secretList , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , withWellKnownListOptions ( metav1.ListOptions {}) )
127
130
framework .ExpectNoError (err )
128
131
129
132
ginkgo .By ("Verifying if the secret list was properly streamed" )
@@ -132,8 +135,8 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
132
135
gomega .Expect (secretList .GetObjectKind ().GroupVersionKind ()).To (gomega .Equal (v1 .SchemeGroupVersion .WithKind ("SecretList" )))
133
136
134
137
ginkgo .By ("Verifying if expected requests were sent to the server" )
135
- expectedRequestMadeByDynamicClient := getExpectedRequestMadeByClientFor (secretList .GetResourceVersion ())
136
- gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestMadeByDynamicClient ))
138
+ expectedRequestsMadeByDynamicClient := getExpectedRequestsMadeByClientFor (secretList .GetResourceVersion ())
139
+ gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestsMadeByDynamicClient ))
137
140
})
138
141
ginkgo .It ("should be requested by metadata client's List method when WatchListClient is enabled" , func (ctx context.Context ) {
139
142
featuregatetesting .SetFeatureGateDuringTest (ginkgo .GinkgoTB (), utilfeature .DefaultFeatureGate , featuregate .Feature (clientfeatures .WatchListClient ), true )
@@ -152,16 +155,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
152
155
framework .ExpectNoError (err )
153
156
154
157
ginkgo .By ("Streaming secrets metadata from the server" )
155
- secretMetaList , err := wrappedMetaClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , metav1.ListOptions {})
158
+ secretMetaList , err := wrappedMetaClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , withWellKnownListOptions ( metav1.ListOptions {}) )
156
159
framework .ExpectNoError (err )
157
160
158
161
ginkgo .By ("Verifying if the secret meta list was properly streamed" )
159
162
streamedMetaSecrets := secretMetaList .Items
160
163
gomega .Expect (cmp .Equal (expectedMetaSecrets , streamedMetaSecrets )).To (gomega .BeTrueBecause ("data received via watchlist must match the added data" ))
161
164
162
165
ginkgo .By ("Verifying if expected requests were sent to the server" )
163
- expectedRequestMadeByMetaClient := getExpectedRequestMadeByClientFor (secretMetaList .GetResourceVersion ())
164
- gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestMadeByMetaClient ))
166
+ expectedRequestsMadeByMetaClient := getExpectedRequestsMadeByClientFor (secretMetaList .GetResourceVersion ())
167
+ gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestsMadeByMetaClient ))
165
168
})
166
169
167
170
// Validates unsupported Accept headers in WatchList.
@@ -186,14 +189,14 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
186
189
// note that the client in case of an error (406) will fall back
187
190
// to a standard list request thus the overall call passes
188
191
ginkgo .By ("Streaming secrets as Table from the server" )
189
- secretTable , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , metav1.ListOptions {})
192
+ secretTable , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , withWellKnownListOptions ( metav1.ListOptions {}) )
190
193
framework .ExpectNoError (err )
191
194
gomega .Expect (secretTable .GetObjectKind ().GroupVersionKind ()).To (gomega .Equal (metav1 .SchemeGroupVersion .WithKind ("Table" )))
192
195
193
196
ginkgo .By ("Verifying if expected response was sent by the server" )
194
197
gomega .Expect (rt .actualResponseStatuses [0 ]).To (gomega .Equal ("406 Not Acceptable" ))
195
- expectedRequestMadeByDynamicClient := getExpectedRequestMadeByClientWhenFallbackToListFor (secretTable .GetResourceVersion ())
196
- gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestMadeByDynamicClient ))
198
+ expectedRequestsMadeByDynamicClient := getExpectedRequestsMadeByClientWhenFallbackToListFor (secretTable .GetResourceVersion ())
199
+ gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestsMadeByDynamicClient ))
197
200
198
201
})
199
202
@@ -217,16 +220,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
217
220
wrappedDynamicClient := dynamic .New (restClient )
218
221
219
222
ginkgo .By ("Streaming secrets from the server" )
220
- secretList , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , metav1.ListOptions {})
223
+ secretList , err := wrappedDynamicClient .Resource (v1 .SchemeGroupVersion .WithResource ("secrets" )).Namespace (f .Namespace .Name ).List (ctx , withWellKnownListOptions ( metav1.ListOptions {}) )
221
224
framework .ExpectNoError (err )
222
225
223
226
ginkgo .By ("Verifying if the secret list was properly streamed" )
224
227
streamedSecrets := secretList .Items
225
228
gomega .Expect (cmp .Equal (expectedSecrets , streamedSecrets )).To (gomega .BeTrueBecause ("data received via watchlist must match the added data" ))
226
229
227
230
ginkgo .By ("Verifying if expected requests were sent to the server" )
228
- expectedRequestMadeByDynamicClient := getExpectedRequestMadeByClientFor (secretList .GetResourceVersion ())
229
- gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestMadeByDynamicClient ))
231
+ expectedRequestsMadeByDynamicClient := getExpectedRequestsMadeByClientFor (secretList .GetResourceVersion ())
232
+ gomega .Expect (rt .actualRequests ).To (gomega .Equal (expectedRequestsMadeByDynamicClient ))
230
233
})
231
234
})
232
235
@@ -274,28 +277,48 @@ func verifyStore(ctx context.Context, expectedSecrets []v1.Secret, store cache.S
274
277
}
275
278
276
279
// corresponds to a streaming request made by the client to stream the secrets
277
- const expectedStreamingRequestMadeByClient string = "allowWatchBookmarks=true&resourceVersionMatch=NotOlderThan&sendInitialEvents=true&watch=true"
280
+ func getExpectedStreamingRequestMadeByClient () string {
281
+ params := url.Values {}
282
+ params .Add ("allowWatchBookmarks" , "true" )
283
+ params .Add ("labelSelector" , "watchlist=true" )
284
+ params .Add ("resourceVersionMatch" , "NotOlderThan" )
285
+ params .Add ("sendInitialEvents" , "true" )
286
+ params .Add ("watch" , "true" )
287
+ return params .Encode ()
288
+ }
289
+
290
+ func getExpectedListRequestMadeByConsistencyDetectorFor (rv string ) string {
291
+ params := url.Values {}
292
+ params .Add ("labelSelector" , "watchlist=true" )
293
+ params .Add ("resourceVersion" , rv )
294
+ params .Add ("resourceVersionMatch" , "Exact" )
295
+ return params .Encode ()
296
+ }
278
297
279
- func getExpectedRequestMadeByClientFor (rv string ) []string {
298
+ func getExpectedRequestsMadeByClientFor (rv string ) []string {
280
299
expectedRequestMadeByClient := []string {
281
- expectedStreamingRequestMadeByClient ,
300
+ getExpectedStreamingRequestMadeByClient () ,
282
301
}
283
302
if consistencydetector .IsDataConsistencyDetectionForWatchListEnabled () {
284
303
// corresponds to a standard list request made by the consistency detector build in into the client
285
- expectedRequestMadeByClient = append (expectedRequestMadeByClient , fmt . Sprintf ( "resourceVersion=%s&resourceVersionMatch=Exact" , rv ))
304
+ expectedRequestMadeByClient = append (expectedRequestMadeByClient , getExpectedListRequestMadeByConsistencyDetectorFor ( rv ))
286
305
}
287
306
return expectedRequestMadeByClient
288
307
}
289
308
290
- func getExpectedRequestMadeByClientWhenFallbackToListFor (rv string ) []string {
309
+ func getExpectedRequestsMadeByClientWhenFallbackToListFor (rv string ) []string {
291
310
expectedRequestMadeByClient := []string {
292
- expectedStreamingRequestMadeByClient ,
311
+ getExpectedStreamingRequestMadeByClient () ,
293
312
// corresponds to a list request made by the client
294
- "" ,
313
+ func () string {
314
+ params := url.Values {}
315
+ params .Add ("labelSelector" , "watchlist=true" )
316
+ return params .Encode ()
317
+ }(),
295
318
}
296
319
if consistencydetector .IsDataConsistencyDetectionForListEnabled () {
297
320
// corresponds to a standard list request made by the consistency detector build in into the client
298
- expectedRequestMadeByClient = append (expectedRequestMadeByClient , fmt . Sprintf ( "resourceVersion=%s&resourceVersionMatch=Exact" , rv ))
321
+ expectedRequestMadeByClient = append (expectedRequestMadeByClient , getExpectedListRequestMadeByConsistencyDetectorFor ( rv ))
299
322
}
300
323
return expectedRequestMadeByClient
301
324
}
@@ -325,6 +348,11 @@ func addWellKnownUnstructuredSecrets(ctx context.Context, f *framework.Framework
325
348
return secrets
326
349
}
327
350
351
+ func withWellKnownListOptions (options metav1.ListOptions ) metav1.ListOptions {
352
+ options .LabelSelector = "watchlist=true"
353
+ return options
354
+ }
355
+
328
356
type byName []v1.Secret
329
357
330
358
func (a byName ) Len () int { return len (a ) }
@@ -333,6 +361,9 @@ func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
333
361
334
362
func newSecret (name string ) * v1.Secret {
335
363
return & v1.Secret {
336
- ObjectMeta : metav1.ObjectMeta {Name : name },
364
+ ObjectMeta : metav1.ObjectMeta {
365
+ Name : name ,
366
+ Labels : map [string ]string {"watchlist" : "true" },
367
+ },
337
368
}
338
369
}
0 commit comments