...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package finalizers
15
16 import (
17 "context"
18 "time"
19
20 . "github.com/onsi/ginkgo"
21 . "github.com/onsi/gomega"
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 "k8s.io/apimachinery/pkg/types"
24 "k8s.io/apimachinery/pkg/util/wait"
25
26 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
27 )
28
29
30
31
32 var _ = Describe("Finalizer", func() {
33
34 BeforeEach(func() {
35
36 })
37
38 AfterEach(func() {
39
40 })
41
42 Context("Adding finalizer", func() {
43 It("should add record finalizer", func() {
44 key := types.NamespacedName{
45 Name: "foo1",
46 Namespace: "default",
47 }
48 duration := "1000s"
49 chaos := &v1alpha1.TimeChaos{
50 ObjectMeta: metav1.ObjectMeta{
51 Name: "foo1",
52 Namespace: "default",
53 },
54 Spec: v1alpha1.TimeChaosSpec{
55 TimeOffset: "100ms",
56 ClockIds: []string{"CLOCK_REALTIME"},
57 Duration: &duration,
58 ContainerSelector: v1alpha1.ContainerSelector{
59 PodSelector: v1alpha1.PodSelector{
60 Mode: v1alpha1.OnePodMode,
61 },
62 },
63 },
64 }
65
66 By("creating a chaos")
67 {
68 Expect(k8sClient.Create(context.TODO(), chaos)).To(Succeed())
69 }
70
71 By("Adding finalizers")
72 {
73 err := wait.Poll(time.Second*1, time.Second*10, func() (ok bool, err error) {
74 err = k8sClient.Get(context.TODO(), key, chaos)
75 if err != nil {
76 return false, err
77 }
78 return len(chaos.GetObjectMeta().GetFinalizers()) > 0 && chaos.GetObjectMeta().GetFinalizers()[0] == RecordFinalizer, nil
79 })
80 Expect(err).ToNot(HaveOccurred())
81 }
82
83 By("deleting the created object")
84 {
85 Expect(k8sClient.Delete(context.TODO(), chaos)).To(Succeed())
86 }
87 })
88 })
89 })
90