@@ -23,6 +23,7 @@ import (
2323
2424 . "github.com/onsi/ginkgo"
2525 . "github.com/onsi/gomega"
26+ "k8s.io/apimachinery/pkg/types"
2627 "sigs.k8s.io/controller-runtime/pkg/client"
2728
2829 chaosv1beta1 "github.com/DataDog/chaos-controller/api/v1beta1"
@@ -127,24 +128,24 @@ func expectChaosInjectors(instance *chaosv1beta1.Disruption, count int) error {
127128 return nil
128129}
129130
130- func expectDisruptionStatus (instance * chaosv1beta1. Disruption , desiredTargetsCount int , ignoredTargetsCount int , selectedTargetsCount int , injectedTargetsCount int ) error {
131+ func expectDisruptionStatus (desiredTargetsCount int , ignoredTargetsCount int , selectedTargetsCount int , injectedTargetsCount int ) error {
131132 updatedInstance := & chaosv1beta1.Disruption {}
132133
133134 if err := k8sClient .Get (context .Background (), instanceKey , updatedInstance ); err != nil {
134135 return err
135136 }
136137
137138 if desiredTargetsCount != updatedInstance .Status .DesiredTargetsCount {
138- return fmt .Errorf ("incorred number of desired targets: expected %d, found %d" , desiredTargetsCount , updatedInstance .Status .DesiredTargetsCount )
139+ return fmt .Errorf ("incorrect number of desired targets: expected %d, found %d" , desiredTargetsCount , updatedInstance .Status .DesiredTargetsCount )
139140 }
140141 if ignoredTargetsCount != updatedInstance .Status .IgnoredTargetsCount {
141- return fmt .Errorf ("incorred number of ignored targets: expected %d, found %d" , ignoredTargetsCount , updatedInstance .Status .IgnoredTargetsCount )
142+ return fmt .Errorf ("incorrect number of ignored targets: expected %d, found %d" , ignoredTargetsCount , updatedInstance .Status .IgnoredTargetsCount )
142143 }
143144 if injectedTargetsCount != updatedInstance .Status .InjectedTargetsCount {
144- return fmt .Errorf ("incorred number of injected targets: expected %d, found %d" , injectedTargetsCount , updatedInstance .Status .InjectedTargetsCount )
145+ return fmt .Errorf ("incorrect number of injected targets: expected %d, found %d" , injectedTargetsCount , updatedInstance .Status .InjectedTargetsCount )
145146 }
146147 if selectedTargetsCount != updatedInstance .Status .SelectedTargetsCount {
147- return fmt .Errorf ("incorred number of selected targets: expected %d, found %d" , selectedTargetsCount , updatedInstance .Status .SelectedTargetsCount )
148+ return fmt .Errorf ("incorrect number of selected targets: expected %d, found %d" , selectedTargetsCount , updatedInstance .Status .SelectedTargetsCount )
148149 }
149150
150151 return nil
@@ -413,7 +414,7 @@ var _ = Describe("Disruption Controller", func() {
413414 Expect (expectChaosInjectors (disruption , 2 )).To (BeNil ())
414415
415416 By ("Ensuring that the disruption status is displaying the right number of targets" )
416- Eventually (func () error { return expectDisruptionStatus (disruption , 2 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
417+ Eventually (func () error { return expectDisruptionStatus (2 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
417418
418419 By ("Adding an extra target" )
419420 Expect (k8sClient .Create (context .Background (), targetPodA2 )).To (BeNil ())
@@ -422,7 +423,7 @@ var _ = Describe("Disruption Controller", func() {
422423 Eventually (func () error { return expectChaosPod (disruption , 3 ) }, timeout ).Should (Succeed ())
423424
424425 By ("Ensuring that the disruption status is displaying the right number of targets" )
425- Eventually (func () error { return expectDisruptionStatus (disruption , 3 , 0 , 3 , 3 ) }, timeout ).Should (Succeed ())
426+ Eventually (func () error { return expectDisruptionStatus (3 , 0 , 3 , 3 ) }, timeout ).Should (Succeed ())
426427
427428 By ("Deleting the extra target" )
428429 Expect (k8sClient .Delete (context .Background (), targetPodA2 )).To (BeNil ())
@@ -431,7 +432,7 @@ var _ = Describe("Disruption Controller", func() {
431432 Eventually (func () error { return expectChaosPod (disruption , 2 ) }, timeout ).Should (Succeed ())
432433
433434 By ("Ensuring that the disruption status is displaying the right number of targets" )
434- Eventually (func () error { return expectDisruptionStatus (disruption , 2 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
435+ Eventually (func () error { return expectDisruptionStatus (2 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
435436 })
436437 })
437438
@@ -463,7 +464,7 @@ var _ = Describe("Disruption Controller", func() {
463464
464465 It ("should scale up then down with the right number of targets count" , func () {
465466 By ("Ensuring that the disruption status is displaying the right number of targets" )
466- Eventually (func () error { return expectDisruptionStatus (disruption , 3 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
467+ Eventually (func () error { return expectDisruptionStatus (3 , 0 , 2 , 2 ) }, timeout ).Should (Succeed ())
467468
468469 By ("Adding an extra target" )
469470 Expect (k8sClient .Create (context .Background (), targetPodA3 )).To (BeNil ())
@@ -472,7 +473,7 @@ var _ = Describe("Disruption Controller", func() {
472473 Expect (k8sClient .Create (context .Background (), targetPodA4 )).To (BeNil ())
473474
474475 By ("Ensuring that the disruption status is displaying the right number of targets" )
475- Eventually (func () error { return expectDisruptionStatus (disruption , 3 , 1 , 3 , 3 ) }, timeout ).Should (Succeed ())
476+ Eventually (func () error { return expectDisruptionStatus (3 , 1 , 3 , 3 ) }, timeout ).Should (Succeed ())
476477
477478 By ("Deleting the extra target" )
478479 Expect (k8sClient .Delete (context .Background (), targetPodA3 )).To (BeNil ())
@@ -482,26 +483,22 @@ var _ = Describe("Disruption Controller", func() {
482483 })
483484 })
484485
485- // NOTE: disabled until fixed
486- // the feature is broken now that we moved all chaos pods into the same namespace
487- // because we had to remove the owner reference on those pods, meaning that
488- // the reconcile loop does not automatically trigger anymore on chaos pods events like a delete
489- // Context("manually delete a chaos pod", func() {
490- // It("should properly handle the chaos pod finalizer", func() {
491- // By("Ensuring that the chaos pods have been created")
492- // Eventually(func() error { return expectChaosPod(disruption, 5) }, timeout).Should(Succeed())
493-
494- // By("Listing chaos pods to pick one to delete")
495- // chaosPods, err := listChaosPods(disruption)
496- // Expect(err).To(BeNil())
497- // chaosPod := chaosPods.Items[0]
498- // chaosPodKey := types.NamespacedName{Namespace: chaosPod.Namespace, Name: chaosPod.Name}
499-
500- // By("Deleting one of the chaos pod")
501- // Expect(k8sClient.Delete(context.Background(), &chaosPod)).To(BeNil())
502-
503- // By("Waiting for the chaos pod finalizer to be removed")
504- // Eventually(func() error { return k8sClient.Get(context.Background(), chaosPodKey, &chaosPod) }, timeout).Should(MatchError(fmt.Sprintf("Pod \"%s\" not found", chaosPod.Name)))
505- // })
506- // })
486+ Context ("manually delete a chaos pod" , func () {
487+ It ("should properly handle the chaos pod finalizer" , func () {
488+ By ("Ensuring that the chaos pods have been created" )
489+ Eventually (func () error { return expectChaosPod (disruption , 4 ) }, timeout ).Should (Succeed ())
490+
491+ By ("Listing chaos pods to pick one to delete" )
492+ chaosPods , err := listChaosPods (disruption )
493+ Expect (err ).To (BeNil ())
494+ chaosPod := chaosPods .Items [0 ]
495+ chaosPodKey := types.NamespacedName {Namespace : chaosPod .Namespace , Name : chaosPod .Name }
496+
497+ By ("Deleting one of the chaos pod" )
498+ Expect (k8sClient .Delete (context .Background (), & chaosPod )).To (BeNil ())
499+
500+ By ("Waiting for the chaos pod finalizer to be removed" )
501+ Eventually (func () error { return k8sClient .Get (context .Background (), chaosPodKey , & chaosPod ) }, timeout ).Should (MatchError (fmt .Sprintf ("Pod \" %s\" not found" , chaosPod .Name )))
502+ })
503+ })
507504})
0 commit comments