@@ -157,6 +157,14 @@ var _ = SIGDescribe("Deployment", func() {
157
157
testDeploymentLabelSelectors := metav1.LabelSelector {
158
158
MatchLabels : testDeploymentLabels ,
159
159
}
160
+ w := & cache.ListWatch {
161
+ WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
162
+ options .LabelSelector = testDeploymentLabelsFlat
163
+ return f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Watch (context .TODO (), options )
164
+ },
165
+ }
166
+ deploymentsList , err := f .ClientSet .AppsV1 ().Deployments ("" ).List (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
167
+ framework .ExpectNoError (err , "failed to list Endpoints" )
160
168
161
169
ginkgo .By ("creating a Deployment" )
162
170
testDeployment := appsv1.Deployment {
@@ -180,36 +188,41 @@ var _ = SIGDescribe("Deployment", func() {
180
188
},
181
189
},
182
190
}
183
- _ , err : = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Create (context .TODO (), & testDeployment , metav1.CreateOptions {})
191
+ _ , err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Create (context .TODO (), & testDeployment , metav1.CreateOptions {})
184
192
framework .ExpectNoError (err , "failed to create Deployment %v in namespace %v" , testDeploymentName , testNamespaceName )
185
193
186
- ginkgo .By ("watching for the Deployment to be added" )
187
- dplmtWatchTimeoutSeconds := int64 (180 )
188
- dplmtWatch , err := f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Watch (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat , TimeoutSeconds : & dplmtWatchTimeoutSeconds })
189
- framework .ExpectNoError (err , "Failed to setup watch on newly created Deployment" )
190
-
191
- foundEvent := false
192
- dplmtWatchChan := dplmtWatch .ResultChan ()
193
- for event := range dplmtWatchChan {
194
- if event .Type == watch .Added {
195
- foundEvent = true
196
- break
194
+ ginkgo .By ("waiting for Deployment to be created" )
195
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
196
+ defer cancel ()
197
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
198
+ switch event .Type {
199
+ case watch .Added :
200
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
201
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
202
+ deployment .Labels ["test-deployment-static" ] == "true"
203
+ return found , nil
204
+ }
205
+ default :
206
+ framework .Logf ("observed event type %v" , event .Type )
197
207
}
198
- }
199
- framework .ExpectEqual (foundEvent , true , "failed to find watch event %v" , watch .Added )
208
+ return false , nil
209
+ })
210
+ framework .ExpectNoError (err , "failed to see %v event" , watch .Added )
200
211
201
212
ginkgo .By ("waiting for all Replicas to be Ready" )
202
- foundEvent = false
203
- for event := range dplmtWatchChan {
204
- deployment , ok := event .Object .(* appsv1.Deployment )
205
- framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
206
- if deployment .Status .AvailableReplicas == testDeploymentDefaultReplicas &&
207
- deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
208
- foundEvent = true
209
- break
213
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
214
+ defer cancel ()
215
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
216
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
217
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
218
+ deployment .Labels ["test-deployment-static" ] == "true" &&
219
+ deployment .Status .AvailableReplicas == testDeploymentDefaultReplicas &&
220
+ deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas
221
+ return found , nil
210
222
}
211
- }
212
- framework .ExpectEqual (foundEvent , true , "failed to see scale of replicas" )
223
+ return false , nil
224
+ })
225
+ framework .ExpectNoError (err , "failed to see replicas of %v in namespace %v scale to requested amount of %v" , testDeployment .Name , testNamespaceName , testDeploymentDefaultReplicas )
213
226
214
227
ginkgo .By ("patching the Deployment" )
215
228
deploymentPatch , err := json .Marshal (map [string ]interface {}{
@@ -233,30 +246,23 @@ var _ = SIGDescribe("Deployment", func() {
233
246
_ , err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Patch (context .TODO (), testDeploymentName , types .StrategicMergePatchType , []byte (deploymentPatch ), metav1.PatchOptions {})
234
247
framework .ExpectNoError (err , "failed to patch Deployment" )
235
248
236
- foundEvent = false
237
- for event := range dplmtWatchChan {
238
- if event .Type == watch .Modified {
239
- foundEvent = true
240
- break
241
- }
242
- }
243
- framework .ExpectEqual (foundEvent , true , "failed to see scale of replicas" )
244
-
245
249
ginkgo .By ("waiting for Replicas to scale" )
246
- foundEvent = false
247
- for event := range dplmtWatchChan {
248
- deployment , ok := event .Object .(* appsv1.Deployment )
249
- framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
250
- if deployment .Status .AvailableReplicas == testDeploymentMinimumReplicas &&
251
- deployment .Status .ReadyReplicas == testDeploymentMinimumReplicas {
252
- foundEvent = true
253
- break
250
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
251
+ defer cancel ()
252
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
253
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
254
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
255
+ deployment .Labels ["test-deployment-static" ] == "true" &&
256
+ deployment .Status .AvailableReplicas == testDeploymentMinimumReplicas &&
257
+ deployment .Status .ReadyReplicas == testDeploymentMinimumReplicas
258
+ return found , nil
254
259
}
255
- }
256
- framework .ExpectEqual (foundEvent , true , "failed to see scale of replicas" )
260
+ return false , nil
261
+ })
262
+ framework .ExpectNoError (err , "failed to see replicas of %v in namespace %v scale to requested amount of %v" , testDeployment .Name , testNamespaceName , testDeploymentMinimumReplicas )
257
263
258
264
ginkgo .By ("listing Deployments" )
259
- deploymentsList , err : = f .ClientSet .AppsV1 ().Deployments ("" ).List (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
265
+ deploymentsList , err = f .ClientSet .AppsV1 ().Deployments ("" ).List (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
260
266
framework .ExpectNoError (err , "failed to list Deployments" )
261
267
foundDeployment := false
262
268
for _ , deploymentItem := range deploymentsList .Items {
@@ -285,14 +291,22 @@ var _ = SIGDescribe("Deployment", func() {
285
291
// currently this hasn't been able to hit the endpoint replaceAppsV1NamespacedDeploymentStatus
286
292
_ , err = dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Update (context .TODO (), & testDeploymentUpdateUnstructured , metav1.UpdateOptions {}) //, "status")
287
293
framework .ExpectNoError (err , "failed to update the DeploymentStatus" )
288
- foundEvent = false
289
- for event := range dplmtWatchChan {
290
- if event .Type == watch .Modified {
291
- foundEvent = true
292
- break
294
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
295
+ defer cancel ()
296
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
297
+ switch event .Type {
298
+ case watch .Modified :
299
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
300
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
301
+ deployment .Labels ["test-deployment-static" ] == "true"
302
+ return found , nil
303
+ }
304
+ default :
305
+ framework .Logf ("observed event type %v" , event .Type )
293
306
}
294
- }
295
- framework .ExpectEqual (foundEvent , true , "failed to find watch event %v" , watch .Modified )
307
+ return false , nil
308
+ })
309
+ framework .ExpectNoError (err , "failed to see %v event" , watch .Modified )
296
310
297
311
ginkgo .By ("fetching the DeploymentStatus" )
298
312
deploymentGetUnstructured , err := dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Get (context .TODO (), testDeploymentName , metav1.GetOptions {}, "status" )
@@ -302,25 +316,20 @@ var _ = SIGDescribe("Deployment", func() {
302
316
framework .ExpectNoError (err , "failed to convert the unstructured response to a Deployment" )
303
317
framework .ExpectEqual (deploymentGet .Spec .Template .Spec .Containers [0 ].Image , testDeploymentUpdateImage , "failed to update image" )
304
318
framework .ExpectEqual (deploymentGet .ObjectMeta .Labels ["test-deployment" ], "updated" , "failed to update labels" )
305
- foundEvent = false
306
- for event := range dplmtWatchChan {
307
- if event .Type == watch .Modified {
308
- foundEvent = true
309
- break
310
- }
311
- }
312
- framework .ExpectEqual (foundEvent , true , "failed to find watch event %v" , watch .Modified )
313
-
314
- foundEvent = false
315
- for event := range dplmtWatchChan {
316
- deployment , ok := event .Object .(* appsv1.Deployment )
317
- framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
318
- if deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
319
- foundEvent = true
320
- break
319
+
320
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
321
+ defer cancel ()
322
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
323
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
324
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
325
+ deployment .Labels ["test-deployment-static" ] == "true" &&
326
+ deployment .Status .AvailableReplicas == testDeploymentDefaultReplicas &&
327
+ deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas
328
+ return found , nil
321
329
}
322
- }
323
- framework .ExpectEqual (foundEvent , true , "failed to see scale of replicas" )
330
+ return false , nil
331
+ })
332
+ framework .ExpectNoError (err , "failed to see replicas of %v in namespace %v scale to requested amount of %v" , testDeployment .Name , testNamespaceName , testDeploymentDefaultReplicas )
324
333
325
334
ginkgo .By ("patching the DeploymentStatus" )
326
335
deploymentStatusPatch , err := json .Marshal (map [string ]interface {}{
@@ -333,6 +342,22 @@ var _ = SIGDescribe("Deployment", func() {
333
342
})
334
343
framework .ExpectNoError (err , "failed to Marshal Deployment JSON patch" )
335
344
dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Patch (context .TODO (), testDeploymentName , types .StrategicMergePatchType , []byte (deploymentStatusPatch ), metav1.PatchOptions {}, "status" )
345
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
346
+ defer cancel ()
347
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
348
+ switch event .Type {
349
+ case watch .Modified :
350
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
351
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
352
+ deployment .Labels ["test-deployment-static" ] == "true"
353
+ return found , nil
354
+ }
355
+ default :
356
+ framework .Logf ("observed event type %v" , event .Type )
357
+ }
358
+ return false , nil
359
+ })
360
+ framework .ExpectNoError (err , "failed to see %v event" , watch .Modified )
336
361
337
362
ginkgo .By ("fetching the DeploymentStatus" )
338
363
deploymentGetUnstructured , err = dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Get (context .TODO (), testDeploymentName , metav1.GetOptions {}, "status" )
@@ -342,36 +367,41 @@ var _ = SIGDescribe("Deployment", func() {
342
367
framework .ExpectNoError (err , "failed to convert the unstructured response to a Deployment" )
343
368
framework .ExpectEqual (deploymentGet .Spec .Template .Spec .Containers [0 ].Image , testDeploymentUpdateImage , "failed to update image" )
344
369
framework .ExpectEqual (deploymentGet .ObjectMeta .Labels ["test-deployment" ], "updated" , "failed to update labels" )
345
- foundEvent = false
346
- for event := range dplmtWatchChan {
347
- if event .Type == watch .Modified {
348
- foundEvent = true
349
- break
370
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
371
+ defer cancel ()
372
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
373
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
374
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
375
+ deployment .Labels ["test-deployment-static" ] == "true" &&
376
+ deployment .Status .AvailableReplicas == testDeploymentDefaultReplicas &&
377
+ deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas &&
378
+ deployment .Spec .Template .Spec .Containers [0 ].Image == testDeploymentUpdateImage
379
+ return found , nil
350
380
}
351
- }
352
- framework .ExpectEqual (foundEvent , true , "failed to find watch event %v" , watch .Modified )
353
- for event := range dplmtWatchChan {
354
- deployment , ok := event .Object .(* appsv1.Deployment )
355
- framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
356
- if deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
357
- break
358
- }
359
- }
381
+ return false , nil
382
+ })
383
+ framework .ExpectNoError (err , "failed to see replicas of %v in namespace %v scale to requested amount of %v" , testDeployment .Name , testNamespaceName , testDeploymentDefaultReplicas )
360
384
361
385
ginkgo .By ("deleting the Deployment" )
362
386
err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
363
387
framework .ExpectNoError (err , "failed to delete Deployment via collection" )
364
388
365
- foundEvent = false
366
- for event := range dplmtWatchChan {
367
- deployment , ok := event .Object .(* appsv1.Deployment )
368
- framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
369
- if event .Type == watch .Deleted && deployment .ObjectMeta .Name == testDeploymentName {
370
- foundEvent = true
371
- break
389
+ ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
390
+ defer cancel ()
391
+ _ , err = watchtools .Until (ctx , deploymentsList .ResourceVersion , w , func (event watch.Event ) (bool , error ) {
392
+ switch event .Type {
393
+ case watch .Deleted :
394
+ if deployment , ok := event .Object .(* appsv1.Deployment ); ok {
395
+ found := deployment .ObjectMeta .Name == testDeployment .Name &&
396
+ deployment .Labels ["test-deployment-static" ] == "true"
397
+ return found , nil
398
+ }
399
+ default :
400
+ framework .Logf ("observed event type %v" , event .Type )
372
401
}
373
- }
374
- framework .ExpectEqual (foundEvent , true , "failed to find watch event %v" , watch .Deleted )
402
+ return false , nil
403
+ })
404
+ framework .ExpectNoError (err , "failed to see %v event" , watch .Deleted )
375
405
})
376
406
})
377
407
0 commit comments