Skip to content

Commit e719b72

Browse files
committed
Update checks and status messages; Remove asserting of status values
1 parent 3149247 commit e719b72

File tree

1 file changed

+50
-112
lines changed

1 file changed

+50
-112
lines changed

test/e2e/apps/deployment.go

Lines changed: 50 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ var _ = SIGDescribe("Deployment", func() {
144144

145145
ginkgo.It("should run the lifecycle of a Deployment", func() {
146146
deploymentResource := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
147+
testNamespaceName := f.Namespace.Name
147148
testDeploymentName := "test-deployment"
148149
testDeploymentInitialImage := "nginx"
149150
testDeploymentPatchImage := "alpine"
150151
testDeploymentUpdateImage := "httpd"
151152
testDeploymentDefaultReplicas := int32(3)
152153
testDeploymentMinimumReplicas := int32(1)
153154
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"
156157
testDeploymentLabelSelectors := metav1.LabelSelector{
157-
MatchLabels: map[string]string{"app": "test-deployment"},
158+
MatchLabels: testDeploymentLabels,
158159
}
159-
testNamespaceName := "default"
160160

161-
fmt.Println("creating a Deployment")
161+
ginkgo.By("creating a Deployment")
162162
testDeployment := appsv1.Deployment{
163163
ObjectMeta: metav1.ObjectMeta{
164164
Name: testDeploymentName,
@@ -180,58 +180,32 @@ var _ = SIGDescribe("Deployment", func() {
180180
},
181181
},
182182
}
183+
// TODO add watch tooling
183184
_, 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)
188186

189-
fmt.Println("watching for the Deployment to be added")
187+
ginkgo.By("watching for the Deployment to be added")
190188
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")
196191

197192
dplmtWatchChan := dplmtWatch.ResultChan()
198193
for event := range dplmtWatchChan {
199194
if event.Type == watch.Added {
200195
break
201196
}
202197
}
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")
222199
for event := range dplmtWatchChan {
223200
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")
228202
if deployment.Status.AvailableReplicas == testDeploymentDefaultReplicas &&
229203
deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
230204
break
231205
}
232206
}
233207

234-
fmt.Println("patching the Deployment")
208+
ginkgo.By("patching the Deployment")
235209
deploymentPatch, err := json.Marshal(map[string]interface{}{
236210
"metadata": map[string]interface{}{
237211
"labels": map[string]string{"test-deployment": "patched"},
@@ -240,7 +214,7 @@ var _ = SIGDescribe("Deployment", func() {
240214
"replicas": testDeploymentMinimumReplicas,
241215
"template": map[string]interface{}{
242216
"spec": map[string]interface{}{
243-
"containers": []map[string]interface{}{{
217+
"containers": [1]map[string]interface{}{{
244218
"name": testDeploymentName,
245219
"image": testDeploymentPatchImage,
246220
"command": []string{"/bin/sleep", "100000"},
@@ -249,40 +223,28 @@ var _ = SIGDescribe("Deployment", func() {
249223
},
250224
},
251225
})
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")
256227
_, 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")
261229

262230
for event := range dplmtWatchChan {
263231
if event.Type == watch.Modified {
264232
break
265233
}
266234
}
267-
fmt.Println("waiting for Replicas to scale")
235+
ginkgo.By("waiting for Replicas to scale")
268236
for event := range dplmtWatchChan {
269237
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")
274239
if deployment.Status.AvailableReplicas == testDeploymentMinimumReplicas &&
275240
deployment.Status.ReadyReplicas == testDeploymentMinimumReplicas {
276241
break
277242
}
278243
}
279244

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")
286248
foundDeployment := false
287249
for _, deploymentItem := range deploymentsList.Items {
288250
if deploymentItem.ObjectMeta.Name == testDeploymentName &&
@@ -294,70 +256,50 @@ var _ = SIGDescribe("Deployment", func() {
294256
break
295257
}
296258
}
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)
301260

302-
fmt.Println("updating the DeploymentStatus")
261+
ginkgo.By("updating the DeploymentStatus")
303262
testDeploymentUpdate := testDeployment
304263
testDeploymentUpdate.ObjectMeta.Labels["test-deployment"] = "updated"
305264
testDeploymentUpdate.Spec.Template.Spec.Containers[0].Image = testDeploymentUpdateImage
306265
testDeploymentDefaultReplicasPointer := &testDeploymentDefaultReplicas
307266
testDeploymentUpdate.Spec.Replicas = testDeploymentDefaultReplicasPointer
308-
testDeploymentUpdate.Status.ReadyReplicas = testDeploymentNoReplicas
309267
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")
313269
testDeploymentUpdateUnstructured := unstructuredv1.Unstructured{
314270
Object: testDeploymentUpdateUnstructuredMap,
315271
}
316272
// currently this hasn't been able to hit the endpoint replaceAppsV1NamespacedDeploymentStatus
317273
_, 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")
322275
for event := range dplmtWatchChan {
323276
if event.Type == watch.Modified {
324277
break
325278
}
326279
}
327280

328-
fmt.Println("fetching the DeploymentStatus")
281+
ginkgo.By("fetching the DeploymentStatus")
329282
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")
334284
deploymentGet := appsv1.Deployment{}
335285
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")
344289
for event := range dplmtWatchChan {
345290
if event.Type == watch.Modified {
346291
break
347292
}
348293
}
349294
for event := range dplmtWatchChan {
350295
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")
355297
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
356298
break
357299
}
358300
}
359301

360-
fmt.Println("patching the DeploymentStatus")
302+
ginkgo.By("patching the DeploymentStatus")
361303
deploymentStatusPatch, err := json.Marshal(map[string]interface{}{
362304
"metadata": map[string]interface{}{
363305
"labels": map[string]string{"test-deployment": "patched-status"},
@@ -366,44 +308,40 @@ var _ = SIGDescribe("Deployment", func() {
366308
"readyReplicas": testDeploymentNoReplicas,
367309
},
368310
})
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")
373312
dc.Resource(deploymentResource).Namespace(testNamespaceName).Patch(context.TODO(), testDeploymentName, types.StrategicMergePatchType, []byte(deploymentStatusPatch), metav1.PatchOptions{}, "status")
374313

375-
fmt.Println("fetching the DeploymentStatus")
314+
ginkgo.By("fetching the DeploymentStatus")
376315
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")
382317
deploymentGet = appsv1.Deployment{}
383318
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")
392322
for event := range dplmtWatchChan {
393323
if event.Type == watch.Modified {
394324
break
395325
}
396326
}
397327
for event := range dplmtWatchChan {
398328
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")
403330
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
404331
break
405332
}
406333
}
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+
}
407345
})
408346
})
409347

0 commit comments

Comments
 (0)