Skip to content

Commit 0b1812d

Browse files
committed
UPSTREAM: 129052: test/e2e/apimachinery/watchlist: select only wellknown secrets
1 parent 34e9c87 commit 0b1812d

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

test/e2e/apimachinery/watchlist.go

+55-24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net/http"
23+
"net/url"
2324
"sort"
2425
"strings"
2526
"time"
@@ -53,12 +54,14 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
5354
featuregatetesting.SetFeatureGateDuringTest(ginkgo.GinkgoTB(), utilfeature.DefaultFeatureGate, featuregate.Feature(clientfeatures.WatchListClient), true)
5455
stopCh := make(chan struct{})
5556
defer close(stopCh)
57+
5658
secretInformer := cache.NewSharedIndexInformer(
5759
&cache.ListWatch{
5860
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
5961
return nil, fmt.Errorf("unexpected list call")
6062
},
6163
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
64+
options = withWellKnownListOptions(options)
6265
return f.ClientSet.CoreV1().Secrets(f.Namespace.Name).Watch(context.TODO(), options)
6366
},
6467
},
@@ -101,16 +104,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
101104
framework.ExpectNoError(err)
102105

103106
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{}))
105108
framework.ExpectNoError(err)
106109

107110
ginkgo.By("Verifying if the secret list was properly streamed")
108111
streamedSecrets := secretList.Items
109112
gomega.Expect(cmp.Equal(expectedSecrets, streamedSecrets)).To(gomega.BeTrueBecause("data received via watchlist must match the added data"))
110113

111114
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))
114117
})
115118
ginkgo.It("should be requested by dynamic client's List method when WatchListClient is enabled", func(ctx context.Context) {
116119
featuregatetesting.SetFeatureGateDuringTest(ginkgo.GinkgoTB(), utilfeature.DefaultFeatureGate, featuregate.Feature(clientfeatures.WatchListClient), true)
@@ -123,7 +126,7 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
123126
framework.ExpectNoError(err)
124127

125128
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{}))
127130
framework.ExpectNoError(err)
128131

129132
ginkgo.By("Verifying if the secret list was properly streamed")
@@ -132,8 +135,8 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
132135
gomega.Expect(secretList.GetObjectKind().GroupVersionKind()).To(gomega.Equal(v1.SchemeGroupVersion.WithKind("SecretList")))
133136

134137
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))
137140
})
138141
ginkgo.It("should be requested by metadata client's List method when WatchListClient is enabled", func(ctx context.Context) {
139142
featuregatetesting.SetFeatureGateDuringTest(ginkgo.GinkgoTB(), utilfeature.DefaultFeatureGate, featuregate.Feature(clientfeatures.WatchListClient), true)
@@ -152,16 +155,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
152155
framework.ExpectNoError(err)
153156

154157
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{}))
156159
framework.ExpectNoError(err)
157160

158161
ginkgo.By("Verifying if the secret meta list was properly streamed")
159162
streamedMetaSecrets := secretMetaList.Items
160163
gomega.Expect(cmp.Equal(expectedMetaSecrets, streamedMetaSecrets)).To(gomega.BeTrueBecause("data received via watchlist must match the added data"))
161164

162165
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))
165168
})
166169

167170
// Validates unsupported Accept headers in WatchList.
@@ -186,14 +189,14 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
186189
// note that the client in case of an error (406) will fall back
187190
// to a standard list request thus the overall call passes
188191
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{}))
190193
framework.ExpectNoError(err)
191194
gomega.Expect(secretTable.GetObjectKind().GroupVersionKind()).To(gomega.Equal(metav1.SchemeGroupVersion.WithKind("Table")))
192195

193196
ginkgo.By("Verifying if expected response was sent by the server")
194197
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))
197200

198201
})
199202

@@ -217,16 +220,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), fu
217220
wrappedDynamicClient := dynamic.New(restClient)
218221

219222
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{}))
221224
framework.ExpectNoError(err)
222225

223226
ginkgo.By("Verifying if the secret list was properly streamed")
224227
streamedSecrets := secretList.Items
225228
gomega.Expect(cmp.Equal(expectedSecrets, streamedSecrets)).To(gomega.BeTrueBecause("data received via watchlist must match the added data"))
226229

227230
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))
230233
})
231234
})
232235

@@ -274,28 +277,48 @@ func verifyStore(ctx context.Context, expectedSecrets []v1.Secret, store cache.S
274277
}
275278

276279
// 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+
}
278297

279-
func getExpectedRequestMadeByClientFor(rv string) []string {
298+
func getExpectedRequestsMadeByClientFor(rv string) []string {
280299
expectedRequestMadeByClient := []string{
281-
expectedStreamingRequestMadeByClient,
300+
getExpectedStreamingRequestMadeByClient(),
282301
}
283302
if consistencydetector.IsDataConsistencyDetectionForWatchListEnabled() {
284303
// 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))
286305
}
287306
return expectedRequestMadeByClient
288307
}
289308

290-
func getExpectedRequestMadeByClientWhenFallbackToListFor(rv string) []string {
309+
func getExpectedRequestsMadeByClientWhenFallbackToListFor(rv string) []string {
291310
expectedRequestMadeByClient := []string{
292-
expectedStreamingRequestMadeByClient,
311+
getExpectedStreamingRequestMadeByClient(),
293312
// 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+
}(),
295318
}
296319
if consistencydetector.IsDataConsistencyDetectionForListEnabled() {
297320
// 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))
299322
}
300323
return expectedRequestMadeByClient
301324
}
@@ -325,6 +348,11 @@ func addWellKnownUnstructuredSecrets(ctx context.Context, f *framework.Framework
325348
return secrets
326349
}
327350

351+
func withWellKnownListOptions(options metav1.ListOptions) metav1.ListOptions {
352+
options.LabelSelector = "watchlist=true"
353+
return options
354+
}
355+
328356
type byName []v1.Secret
329357

330358
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] }
333361

334362
func newSecret(name string) *v1.Secret {
335363
return &v1.Secret{
336-
ObjectMeta: metav1.ObjectMeta{Name: name},
364+
ObjectMeta: metav1.ObjectMeta{
365+
Name: name,
366+
Labels: map[string]string{"watchlist": "true"},
367+
},
337368
}
338369
}

0 commit comments

Comments
 (0)