@@ -144,21 +144,21 @@ var _ = SIGDescribe("Deployment", func() {
144
144
145
145
ginkgo .It ("should run the lifecycle of a Deployment" , func () {
146
146
deploymentResource := schema.GroupVersionResource {Group : "apps" , Version : "v1" , Resource : "deployments" }
147
+ testNamespaceName := f .Namespace .Name
147
148
testDeploymentName := "test-deployment"
148
149
testDeploymentInitialImage := "nginx"
149
150
testDeploymentPatchImage := "alpine"
150
151
testDeploymentUpdateImage := "httpd"
151
152
testDeploymentDefaultReplicas := int32 (3 )
152
153
testDeploymentMinimumReplicas := int32 (1 )
153
154
testDeploymentNoReplicas := int32 (0 )
154
- // TODO labels
155
- // TODO flat labels
155
+ testDeploymentLabels := map [ string ] string { "test-deployment-static" : "true" }
156
+ testDeploymentLabelsFlat := "test-deployment-static=true"
156
157
testDeploymentLabelSelectors := metav1.LabelSelector {
157
- MatchLabels : map [ string ] string { "app" : "test-deployment" } ,
158
+ MatchLabels : testDeploymentLabels ,
158
159
}
159
- testNamespaceName := "default"
160
160
161
- fmt . Println ("creating a Deployment" )
161
+ ginkgo . By ("creating a Deployment" )
162
162
testDeployment := appsv1.Deployment {
163
163
ObjectMeta : metav1.ObjectMeta {
164
164
Name : testDeploymentName ,
@@ -180,58 +180,32 @@ var _ = SIGDescribe("Deployment", func() {
180
180
},
181
181
},
182
182
}
183
+ // TODO add watch tooling
183
184
_ , err := f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Create (context .TODO (), & testDeployment , metav1.CreateOptions {})
184
- if err != nil {
185
- fmt .Println (err )
186
- return
187
- }
185
+ framework .ExpectNoError (err , "failed to create Deployment %v in namespace %v" , testDeploymentName , testNamespaceName )
188
186
189
- fmt . Println ("watching for the Deployment to be added" )
187
+ ginkgo . By ("watching for the Deployment to be added" )
190
188
dplmtWatchTimeoutSeconds := int64 (180 )
191
- dplmtWatch , err := f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Watch (context .TODO (), metav1.ListOptions {LabelSelector : "test-deployment-static=true" , TimeoutSeconds : & dplmtWatchTimeoutSeconds })
192
- if err != nil {
193
- fmt .Println (err , "Failed to setup watch on newly created Deployment" )
194
- return
195
- }
189
+ dplmtWatch , err := f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Watch (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat , TimeoutSeconds : & dplmtWatchTimeoutSeconds })
190
+ framework .ExpectNoError (err , "Failed to setup watch on newly created Deployment" )
196
191
197
192
dplmtWatchChan := dplmtWatch .ResultChan ()
198
193
for event := range dplmtWatchChan {
199
194
if event .Type == watch .Added {
200
195
break
201
196
}
202
197
}
203
- defer func () {
204
- fmt .Println ("deleting the Deployment" )
205
- err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : "test-deployment-static=true" })
206
- if err != nil {
207
- fmt .Println (err )
208
- return
209
- }
210
- for event := range dplmtWatchChan {
211
- deployment , ok := event .Object .(* appsv1.Deployment )
212
- if ok != true {
213
- fmt .Println ("unable to convert event.Object type" )
214
- return
215
- }
216
- if event .Type == watch .Deleted && deployment .ObjectMeta .Name == testDeploymentName {
217
- break
218
- }
219
- }
220
- }()
221
- fmt .Println ("waiting for all Replicas to be Ready" )
198
+ ginkgo .By ("waiting for all Replicas to be Ready" )
222
199
for event := range dplmtWatchChan {
223
200
deployment , ok := event .Object .(* appsv1.Deployment )
224
- if ok != true {
225
- fmt .Println ("unable to convert event.Object type" )
226
- return
227
- }
201
+ framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
228
202
if deployment .Status .AvailableReplicas == testDeploymentDefaultReplicas &&
229
203
deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
230
204
break
231
205
}
232
206
}
233
207
234
- fmt . Println ("patching the Deployment" )
208
+ ginkgo . By ("patching the Deployment" )
235
209
deploymentPatch , err := json .Marshal (map [string ]interface {}{
236
210
"metadata" : map [string ]interface {}{
237
211
"labels" : map [string ]string {"test-deployment" : "patched" },
@@ -240,7 +214,7 @@ var _ = SIGDescribe("Deployment", func() {
240
214
"replicas" : testDeploymentMinimumReplicas ,
241
215
"template" : map [string ]interface {}{
242
216
"spec" : map [string ]interface {}{
243
- "containers" : []map [string ]interface {}{{
217
+ "containers" : [1 ]map [string ]interface {}{{
244
218
"name" : testDeploymentName ,
245
219
"image" : testDeploymentPatchImage ,
246
220
"command" : []string {"/bin/sleep" , "100000" },
@@ -249,40 +223,28 @@ var _ = SIGDescribe("Deployment", func() {
249
223
},
250
224
},
251
225
})
252
- if err != nil {
253
- fmt .Println (err , "failed to Marshal Deployment JSON patch" )
254
- return
255
- }
226
+ framework .ExpectNoError (err , "failed to Marshal Deployment JSON patch" )
256
227
_ , err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).Patch (context .TODO (), testDeploymentName , types .StrategicMergePatchType , []byte (deploymentPatch ), metav1.PatchOptions {})
257
- if err != nil {
258
- fmt .Println (err , "failed to patch Deployment" )
259
- return
260
- }
228
+ framework .ExpectNoError (err , "failed to patch Deployment" )
261
229
262
230
for event := range dplmtWatchChan {
263
231
if event .Type == watch .Modified {
264
232
break
265
233
}
266
234
}
267
- fmt . Println ("waiting for Replicas to scale" )
235
+ ginkgo . By ("waiting for Replicas to scale" )
268
236
for event := range dplmtWatchChan {
269
237
deployment , ok := event .Object .(* appsv1.Deployment )
270
- if ok != true {
271
- fmt .Println ("unable to convert event.Object type" )
272
- return
273
- }
238
+ framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
274
239
if deployment .Status .AvailableReplicas == testDeploymentMinimumReplicas &&
275
240
deployment .Status .ReadyReplicas == testDeploymentMinimumReplicas {
276
241
break
277
242
}
278
243
}
279
244
280
- fmt .Println ("listing Deployments" )
281
- deploymentsList , err := f .ClientSet .AppsV1 ().Deployments ("" ).List (context .TODO (), metav1.ListOptions {LabelSelector : "test-deployment-static=true" })
282
- if err != nil {
283
- fmt .Println (err , "failed to list Deployments" )
284
- return
285
- }
245
+ ginkgo .By ("listing Deployments" )
246
+ deploymentsList , err := f .ClientSet .AppsV1 ().Deployments ("" ).List (context .TODO (), metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
247
+ framework .ExpectNoError (err , "failed to list Deployments" )
286
248
foundDeployment := false
287
249
for _ , deploymentItem := range deploymentsList .Items {
288
250
if deploymentItem .ObjectMeta .Name == testDeploymentName &&
@@ -294,70 +256,50 @@ var _ = SIGDescribe("Deployment", func() {
294
256
break
295
257
}
296
258
}
297
- if foundDeployment != true {
298
- fmt .Println ("unable to find the Deployment in list" )
299
- return
300
- }
259
+ framework .ExpectEqual (foundDeployment , true , "unable to find the Deployment in list" , deploymentsList )
301
260
302
- fmt . Println ("updating the DeploymentStatus" )
261
+ ginkgo . By ("updating the DeploymentStatus" )
303
262
testDeploymentUpdate := testDeployment
304
263
testDeploymentUpdate .ObjectMeta .Labels ["test-deployment" ] = "updated"
305
264
testDeploymentUpdate .Spec .Template .Spec .Containers [0 ].Image = testDeploymentUpdateImage
306
265
testDeploymentDefaultReplicasPointer := & testDeploymentDefaultReplicas
307
266
testDeploymentUpdate .Spec .Replicas = testDeploymentDefaultReplicasPointer
308
- testDeploymentUpdate .Status .ReadyReplicas = testDeploymentNoReplicas
309
267
testDeploymentUpdateUnstructuredMap , err := runtime .DefaultUnstructuredConverter .ToUnstructured (& testDeploymentUpdate )
310
- if err != nil {
311
- fmt .Println (err , "failed to convert to unstructured" )
312
- }
268
+ framework .ExpectNoError (err , "failed to convert to unstructured" )
313
269
testDeploymentUpdateUnstructured := unstructuredv1.Unstructured {
314
270
Object : testDeploymentUpdateUnstructuredMap ,
315
271
}
316
272
// currently this hasn't been able to hit the endpoint replaceAppsV1NamespacedDeploymentStatus
317
273
_ , err = dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Update (context .TODO (), & testDeploymentUpdateUnstructured , metav1.UpdateOptions {}) //, "status")
318
- if err != nil {
319
- fmt .Println (err , "failed to update the DeploymentStatus" )
320
- return
321
- }
274
+ framework .ExpectNoError (err , "failed to update the DeploymentStatus" )
322
275
for event := range dplmtWatchChan {
323
276
if event .Type == watch .Modified {
324
277
break
325
278
}
326
279
}
327
280
328
- fmt . Println ("fetching the DeploymentStatus" )
281
+ ginkgo . By ("fetching the DeploymentStatus" )
329
282
deploymentGetUnstructured , err := dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Get (context .TODO (), testDeploymentName , metav1.GetOptions {}, "status" )
330
- if err != nil {
331
- fmt .Println (err , "failed to fetch the Deployment" )
332
- return
333
- }
283
+ framework .ExpectNoError (err , "failed to fetch the Deployment" )
334
284
deploymentGet := appsv1.Deployment {}
335
285
err = runtime .DefaultUnstructuredConverter .FromUnstructured (deploymentGetUnstructured .Object , & deploymentGet )
336
- if err != nil {
337
- fmt .Println (err , "failed to convert the unstructured response to a Deployment" )
338
- return
339
- }
340
- if ! (deploymentGet .Spec .Template .Spec .Containers [0 ].Image == testDeploymentUpdateImage || deploymentGet .Status .ReadyReplicas == testDeploymentNoReplicas || deploymentGet .ObjectMeta .Labels ["test-deployment" ] == "updated" ) {
341
- fmt .Println ("failed to update the Deployment (did not return correct values)" )
342
- return
343
- }
286
+ framework .ExpectNoError (err , "failed to convert the unstructured response to a Deployment" )
287
+ framework .ExpectEqual (deploymentGet .Spec .Template .Spec .Containers [0 ].Image , testDeploymentUpdateImage , "failed to update image" )
288
+ framework .ExpectEqual (deploymentGet .ObjectMeta .Labels ["test-deployment" ], "updated" , "failed to update labels" )
344
289
for event := range dplmtWatchChan {
345
290
if event .Type == watch .Modified {
346
291
break
347
292
}
348
293
}
349
294
for event := range dplmtWatchChan {
350
295
deployment , ok := event .Object .(* appsv1.Deployment )
351
- if ok != true {
352
- fmt .Println ("failed to convert event Object to a Deployment" )
353
- return
354
- }
296
+ framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
355
297
if deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
356
298
break
357
299
}
358
300
}
359
301
360
- fmt . Println ("patching the DeploymentStatus" )
302
+ ginkgo . By ("patching the DeploymentStatus" )
361
303
deploymentStatusPatch , err := json .Marshal (map [string ]interface {}{
362
304
"metadata" : map [string ]interface {}{
363
305
"labels" : map [string ]string {"test-deployment" : "patched-status" },
@@ -366,44 +308,40 @@ var _ = SIGDescribe("Deployment", func() {
366
308
"readyReplicas" : testDeploymentNoReplicas ,
367
309
},
368
310
})
369
- if err != nil {
370
- fmt .Println (err , "failed to Marshal Deployment JSON patch" )
371
- return
372
- }
311
+ framework .ExpectNoError (err , "failed to Marshal Deployment JSON patch" )
373
312
dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Patch (context .TODO (), testDeploymentName , types .StrategicMergePatchType , []byte (deploymentStatusPatch ), metav1.PatchOptions {}, "status" )
374
313
375
- fmt . Println ("fetching the DeploymentStatus" )
314
+ ginkgo . By ("fetching the DeploymentStatus" )
376
315
deploymentGetUnstructured , err = dc .Resource (deploymentResource ).Namespace (testNamespaceName ).Get (context .TODO (), testDeploymentName , metav1.GetOptions {}, "status" )
377
-
378
- if err != nil {
379
- fmt .Println (err , "failed to fetch the DeploymentStatus" )
380
- return
381
- }
316
+ framework .ExpectNoError (err , "failed to fetch the DeploymentStatus" )
382
317
deploymentGet = appsv1.Deployment {}
383
318
err = runtime .DefaultUnstructuredConverter .FromUnstructured (deploymentGetUnstructured .Object , & deploymentGet )
384
- if err != nil {
385
- fmt .Println (err , "failed to convert the unstructured response to a Deployment" )
386
- return
387
- }
388
- if ! (deploymentGet .Spec .Template .Spec .Containers [0 ].Image == testDeploymentUpdateImage || deploymentGet .Status .ReadyReplicas == 0 || deploymentGet .ObjectMeta .Labels ["test-deployment" ] == "patched-status" ) {
389
- fmt .Println ("failed to update the Deployment (did not return correct values)" )
390
- return
391
- }
319
+ framework .ExpectNoError (err , "failed to convert the unstructured response to a Deployment" )
320
+ framework .ExpectEqual (deploymentGet .Spec .Template .Spec .Containers [0 ].Image , testDeploymentUpdateImage , "failed to update image" )
321
+ framework .ExpectEqual (deploymentGet .ObjectMeta .Labels ["test-deployment" ], "updated" , "failed to update labels" )
392
322
for event := range dplmtWatchChan {
393
323
if event .Type == watch .Modified {
394
324
break
395
325
}
396
326
}
397
327
for event := range dplmtWatchChan {
398
328
deployment , ok := event .Object .(* appsv1.Deployment )
399
- if ok != true {
400
- fmt .Println ("failed to convert event Object to a Deployment" )
401
- return
402
- }
329
+ framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
403
330
if deployment .Status .ReadyReplicas == testDeploymentDefaultReplicas {
404
331
break
405
332
}
406
333
}
334
+
335
+ ginkgo .By ("deleting the Deployment" )
336
+ err = f .ClientSet .AppsV1 ().Deployments (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : testDeploymentLabelsFlat })
337
+ framework .ExpectNoError (err , "failed to delete Deployment via collection" )
338
+ for event := range dplmtWatchChan {
339
+ deployment , ok := event .Object .(* appsv1.Deployment )
340
+ framework .ExpectEqual (ok , true , "unable to convert event.Object type" )
341
+ if event .Type == watch .Deleted && deployment .ObjectMeta .Name == testDeploymentName {
342
+ break
343
+ }
344
+ }
407
345
})
408
346
})
409
347
0 commit comments