1
1
package controllers_test
2
2
3
3
import (
4
+ "time"
5
+
4
6
"k8s.io/apimachinery/pkg/types"
5
7
"k8s.io/utils/pointer"
6
- "time"
7
8
8
9
appsv1 "k8s.io/api/apps/v1"
9
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -13,7 +14,7 @@ import (
13
14
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
14
15
)
15
16
16
- var _ = Describe ("Reconcile queue Rebalance " , func () {
17
+ var _ = Describe ("Reconcile post deploy " , func () {
17
18
var (
18
19
cluster * rabbitmqv1beta1.RabbitmqCluster
19
20
annotations map [string ]string
@@ -29,6 +30,41 @@ var _ = Describe("Reconcile queue Rebalance", func() {
29
30
waitForClusterDeletion (ctx , cluster , client )
30
31
})
31
32
33
+ When ("cluster is created" , func () {
34
+ var sts * appsv1.StatefulSet
35
+ BeforeEach (func () {
36
+ cluster = & rabbitmqv1beta1.RabbitmqCluster {
37
+ ObjectMeta : metav1.ObjectMeta {
38
+ Name : "rabbitmq-feature-flags" ,
39
+ Namespace : defaultNamespace ,
40
+ },
41
+ }
42
+ Expect (client .Create (ctx , cluster )).To (Succeed ())
43
+ waitForClusterCreation (ctx , cluster , client )
44
+ })
45
+
46
+ It ("enables all feature flags" , func () {
47
+ By ("annotating that StatefulSet got created" , func () {
48
+ sts = statefulSet (ctx , cluster )
49
+ value := sts .ObjectMeta .Annotations ["rabbitmq.com/createdAt" ]
50
+ _ , err := time .Parse (time .RFC3339 , value )
51
+ Expect (err ).NotTo (HaveOccurred (), "annotation rabbitmq.com/createdAt was not a valid RFC3339 timestamp" )
52
+ })
53
+
54
+ By ("enabling all feature flags once all Pods are up, and removing the annotation" , func () {
55
+ sts .Status .Replicas = 1
56
+ sts .Status .ReadyReplicas = 1
57
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
58
+ Eventually (func () map [string ]string {
59
+ Expect (client .Get (ctx , types.NamespacedName {Namespace : cluster .Namespace , Name : cluster .ChildResourceName ("server" )}, sts )).To (Succeed ())
60
+ return sts .ObjectMeta .Annotations
61
+ }, 5 ).ShouldNot (HaveKey ("rabbitmq.com/createdAt" ))
62
+ Expect (fakeExecutor .ExecutedCommands ()).To (ContainElement (command {"bash" , "-c" ,
63
+ "set -eo pipefail; rabbitmqctl -s list_feature_flags name state stability | (grep 'disabled\\ sstable$' || true) | cut -f 1 | xargs -r -n1 rabbitmqctl enable_feature_flag" }))
64
+ })
65
+ })
66
+ })
67
+
32
68
When ("the cluster is configured to run post-deploy steps" , func () {
33
69
BeforeEach (func () {
34
70
cluster = & rabbitmqv1beta1.RabbitmqCluster {
@@ -54,22 +90,19 @@ var _ = Describe("Reconcile queue Rebalance", func() {
54
90
sts .Status .UpdatedReplicas = 1
55
91
sts .Status .UpdateRevision = "some-new-revision"
56
92
57
- statusWriter := client .Status ()
58
- err := statusWriter .Update (ctx , sts )
59
- Expect (err ).NotTo (HaveOccurred ())
93
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
60
94
})
61
95
62
96
It ("triggers the controller to run rabbitmq-queues rebalance all" , func () {
63
97
By ("setting an annotation on the CR" , func () {
64
98
Eventually (func () map [string ]string {
65
99
rmq := & rabbitmqv1beta1.RabbitmqCluster {}
66
- err := client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )
67
- Expect (err ).To (BeNil ())
100
+ Expect (client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )).To (Succeed ())
68
101
annotations = rmq .ObjectMeta .Annotations
69
102
return annotations
70
103
}, 5 ).Should (HaveKey ("rabbitmq.com/queueRebalanceNeededAt" ))
71
104
_ , err := time .Parse (time .RFC3339 , annotations ["rabbitmq.com/queueRebalanceNeededAt" ])
72
- Expect (err ).NotTo (HaveOccurred (), "Annotation rabbitmq.com/queueRebalanceNeededAt was not a valid RFC3339 timestamp" )
105
+ Expect (err ).NotTo (HaveOccurred (), "annotation rabbitmq.com/queueRebalanceNeededAt was not a valid RFC3339 timestamp" )
73
106
})
74
107
75
108
By ("not removing the annotation when all replicas are updated but not yet ready" , func () {
@@ -78,9 +111,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
78
111
sts .Status .UpdatedReplicas = 3
79
112
sts .Status .UpdateRevision = "some-new-revision"
80
113
sts .Status .ReadyReplicas = 2
81
- statusWriter := client .Status ()
82
- err := statusWriter .Update (ctx , sts )
83
- Expect (err ).NotTo (HaveOccurred ())
114
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
84
115
Eventually (func () map [string ]string {
85
116
rmq := & rabbitmqv1beta1.RabbitmqCluster {}
86
117
err := client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )
@@ -89,15 +120,13 @@ var _ = Describe("Reconcile queue Rebalance", func() {
89
120
return annotations
90
121
}, 5 ).Should (HaveKey ("rabbitmq.com/queueRebalanceNeededAt" ))
91
122
Expect (fakeExecutor .ExecutedCommands ()).NotTo (ContainElement (command {"sh" , "-c" , "rabbitmq-queues rebalance all" }))
92
- _ , err = time .Parse (time .RFC3339 , annotations ["rabbitmq.com/queueRebalanceNeededAt" ])
123
+ _ , err : = time .Parse (time .RFC3339 , annotations ["rabbitmq.com/queueRebalanceNeededAt" ])
93
124
Expect (err ).NotTo (HaveOccurred (), "Annotation rabbitmq.com/queueRebalanceNeededAt was not a valid RFC3339 timestamp" )
94
125
})
95
126
96
127
By ("removing the annotation once all Pods are up, and triggering the queue rebalance" , func () {
97
128
sts .Status .ReadyReplicas = 3
98
- statusWriter := client .Status ()
99
- err := statusWriter .Update (ctx , sts )
100
- Expect (err ).NotTo (HaveOccurred ())
129
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
101
130
Eventually (func () map [string ]string {
102
131
rmq := & rabbitmqv1beta1.RabbitmqCluster {}
103
132
err := client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )
@@ -136,9 +165,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
136
165
sts .Status .UpdatedReplicas = 1
137
166
sts .Status .UpdateRevision = "some-new-revision"
138
167
139
- statusWriter := client .Status ()
140
- err := statusWriter .Update (ctx , sts )
141
- Expect (err ).NotTo (HaveOccurred ())
168
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
142
169
})
143
170
144
171
It ("does not trigger the controller to run rabbitmq-queues rebalance all" , func () {
@@ -157,9 +184,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
157
184
sts .Status .UpdatedReplicas = 3
158
185
sts .Status .UpdateRevision = "some-new-revision"
159
186
sts .Status .ReadyReplicas = 3
160
- statusWriter := client .Status ()
161
- err := statusWriter .Update (ctx , sts )
162
- Expect (err ).NotTo (HaveOccurred ())
187
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
163
188
Consistently (func () map [string ]string {
164
189
rmq := & rabbitmqv1beta1.RabbitmqCluster {}
165
190
err := client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )
@@ -168,9 +193,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
168
193
}, 5 ).ShouldNot (HaveKey ("rabbitmq.com/queueRebalanceNeededAt" ))
169
194
Expect (fakeExecutor .ExecutedCommands ()).NotTo (ContainElement (command {"sh" , "-c" , "rabbitmq-queues rebalance all" }))
170
195
})
171
-
172
196
})
173
-
174
197
})
175
198
})
176
199
@@ -201,9 +224,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
201
224
sts .Status .UpdateRevision = "some-new-revision"
202
225
sts .Status .ReadyReplicas = 0
203
226
204
- statusWriter := client .Status ()
205
- err := statusWriter .Update (ctx , sts )
206
- Expect (err ).NotTo (HaveOccurred ())
227
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
207
228
})
208
229
209
230
It ("does not trigger the controller to run rabbitmq-queues rebalance all" , func () {
@@ -222,9 +243,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
222
243
sts .Status .UpdatedReplicas = 1
223
244
sts .Status .UpdateRevision = "some-new-revision"
224
245
sts .Status .ReadyReplicas = 1
225
- statusWriter := client .Status ()
226
- err := statusWriter .Update (ctx , sts )
227
- Expect (err ).NotTo (HaveOccurred ())
246
+ Expect (client .Status ().Update (ctx , sts )).To (Succeed ())
228
247
Consistently (func () map [string ]string {
229
248
rmq := & rabbitmqv1beta1.RabbitmqCluster {}
230
249
err := client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )
@@ -233,9 +252,7 @@ var _ = Describe("Reconcile queue Rebalance", func() {
233
252
}, 5 ).ShouldNot (HaveKey ("rabbitmq.com/queueRebalanceNeededAt" ))
234
253
Expect (fakeExecutor .ExecutedCommands ()).NotTo (ContainElement (command {"sh" , "-c" , "rabbitmq-queues rebalance all" }))
235
254
})
236
-
237
255
})
238
-
239
256
})
240
257
})
241
258
})
0 commit comments