@@ -66,6 +66,22 @@ var _ = Describe("GenerateServerConfigMap", func() {
66
66
var configMap * corev1.ConfigMap
67
67
68
68
BeforeEach (func () {
69
+ instance .Labels = map [string ]string {
70
+ "app.kubernetes.io/foo" : "bar" ,
71
+ "foo" : "bar" ,
72
+ "rabbitmq" : "is-great" ,
73
+ "foo/app.kubernetes.io" : "edgecase" ,
74
+ }
75
+ instance .Annotations = map [string ]string {
76
+ "my-annotation" : "i-like-this" ,
77
+ "kubernetes.io/name" : "i-do-not-like-this" ,
78
+ "kubectl.kubernetes.io/name" : "i-do-not-like-this" ,
79
+ "k8s.io/name" : "i-do-not-like-this" ,
80
+ "kubernetes.io/other" : "i-do-not-like-this" ,
81
+ "kubectl.kubernetes.io/other" : "i-do-not-like-this" ,
82
+ "k8s.io/other" : "i-do-not-like-this" ,
83
+ }
84
+
69
85
obj , err := configMapBuilder .Build ()
70
86
configMap = obj .(* corev1.ConfigMap )
71
87
Expect (err ).NotTo (HaveOccurred ())
@@ -75,6 +91,32 @@ var _ = Describe("GenerateServerConfigMap", func() {
75
91
Expect (configMap .Name ).To (Equal (builder .Instance .ChildResourceName ("server-conf" )))
76
92
Expect (configMap .Namespace ).To (Equal (builder .Instance .Namespace ))
77
93
})
94
+
95
+ It ("adds labels from the instance and default labels" , func () {
96
+ Expect (configMap .Labels ).To (SatisfyAll (
97
+ HaveLen (6 ),
98
+ HaveKeyWithValue ("foo" , "bar" ),
99
+ HaveKeyWithValue ("rabbitmq" , "is-great" ),
100
+ HaveKeyWithValue ("foo/app.kubernetes.io" , "edgecase" ),
101
+ HaveKeyWithValue ("app.kubernetes.io/name" , instance .Name ),
102
+ HaveKeyWithValue ("app.kubernetes.io/component" , "rabbitmq" ),
103
+ HaveKeyWithValue ("app.kubernetes.io/part-of" , "rabbitmq" ),
104
+ Not (HaveKey ("app.kubernetes.io/foo" )),
105
+ ))
106
+ })
107
+
108
+ It ("adds annotations from the instance" , func () {
109
+ Expect (configMap .Annotations ).To (SatisfyAll (
110
+ HaveLen (1 ),
111
+ HaveKeyWithValue ("my-annotation" , "i-like-this" ),
112
+ Not (HaveKey ("kubernetes.io/name" )),
113
+ Not (HaveKey ("kubectl.kubernetes.io/name" )),
114
+ Not (HaveKey ("k8s.io/name" )),
115
+ Not (HaveKey ("kubernetes.io/other" )),
116
+ Not (HaveKey ("kubectl.kubernetes.io/other" )),
117
+ Not (HaveKey ("k8s.io/other" )),
118
+ ))
119
+ })
78
120
})
79
121
80
122
Context ("Update" , func () {
@@ -284,94 +326,33 @@ ssl_options.verify = verify_peer
284
326
})
285
327
})
286
328
287
- Context ("labels" , func () {
288
- BeforeEach (func () {
289
- instance = rabbitmqv1beta1.RabbitmqCluster {
290
- ObjectMeta : metav1.ObjectMeta {
291
- Name : "rabbit-labelled" ,
292
- },
293
- }
294
- instance .Labels = map [string ]string {
295
- "app.kubernetes.io/foo" : "bar" ,
296
- "foo" : "bar" ,
297
- "rabbitmq" : "is-great" ,
298
- "foo/app.kubernetes.io" : "edgecase" ,
299
- }
300
-
301
- configMap = & corev1.ConfigMap {
302
- ObjectMeta : metav1.ObjectMeta {
303
- Labels : map [string ]string {
304
- "app.kubernetes.io/name" : instance .Name ,
305
- "app.kubernetes.io/part-of" : "rabbitmq" ,
306
- "this-was-the-previous-label" : "should-be-deleted" ,
307
- },
308
- },
309
- }
310
- err := configMapBuilder .Update (configMap )
311
- Expect (err ).NotTo (HaveOccurred ())
312
- })
313
-
314
- It ("adds labels from the CR" , func () {
315
- testLabels (configMap .Labels )
316
- })
317
-
318
- It ("restores the default labels" , func () {
319
- labels := configMap .Labels
320
- Expect (labels ["app.kubernetes.io/name" ]).To (Equal (instance .Name ))
321
- Expect (labels ["app.kubernetes.io/component" ]).To (Equal ("rabbitmq" ))
322
- Expect (labels ["app.kubernetes.io/part-of" ]).To (Equal ("rabbitmq" ))
323
- })
324
-
325
- It ("deletes the labels that are removed from the CR" , func () {
326
- Expect (configMap .Labels ).NotTo (HaveKey ("this-was-the-previous-label" ))
327
- })
329
+ // this is to ensure that pods are not restarted when instance labels are updated
330
+ It ("does not update labels on the config map" , func () {
331
+ configMap .Labels = map [string ]string {
332
+ "app.kubernetes.io/name" : instance .Name ,
333
+ "app.kubernetes.io/component" : "rabbitmq" ,
334
+ "app.kubernetes.io/part-of" : "rabbitmq" ,
335
+ }
336
+ instance .Labels = map [string ]string {
337
+ "new-label" : "test" ,
338
+ }
339
+ Expect (configMapBuilder .Update (configMap )).To (Succeed ())
340
+ Expect (configMap .Labels ).To (SatisfyAll (
341
+ HaveLen (3 ),
342
+ HaveKeyWithValue ("app.kubernetes.io/name" , instance .Name ),
343
+ HaveKeyWithValue ("app.kubernetes.io/component" , "rabbitmq" ),
344
+ HaveKeyWithValue ("app.kubernetes.io/part-of" , "rabbitmq" ),
345
+ Not (HaveKey ("new-label" )),
346
+ ))
328
347
})
329
348
330
- Context ("instance annotations" , func () {
331
- BeforeEach (func () {
332
- instance = rabbitmqv1beta1.RabbitmqCluster {
333
- ObjectMeta : metav1.ObjectMeta {
334
- Name : "rabbit-labelled" ,
335
- },
336
- }
337
- instance .Annotations = map [string ]string {
338
- "my-annotation" : "i-like-this" ,
339
- "kubernetes.io/name" : "i-do-not-like-this" ,
340
- "kubectl.kubernetes.io/name" : "i-do-not-like-this" ,
341
- "k8s.io/name" : "i-do-not-like-this" ,
342
- "kubernetes.io/other" : "i-do-not-like-this" ,
343
- "kubectl.kubernetes.io/other" : "i-do-not-like-this" ,
344
- "k8s.io/other" : "i-do-not-like-this" ,
345
- }
346
-
347
- configMap = & corev1.ConfigMap {
348
- ObjectMeta : metav1.ObjectMeta {
349
- Annotations : map [string ]string {
350
- "my-annotation" : "i-will-not-stay" ,
351
- "old-annotation" : "old-value" ,
352
- "im-here-to-stay.kubernetes.io" : "for-a-while" ,
353
- "kubernetes.io/name" : "should-stay" ,
354
- "kubectl.kubernetes.io/name" : "should-stay" ,
355
- "k8s.io/name" : "should-stay" ,
356
- },
357
- },
358
- }
359
- err := configMapBuilder .Update (configMap )
360
- Expect (err ).NotTo (HaveOccurred ())
361
- })
362
-
363
- It ("updates config map annotations" , func () {
364
- expectedAnnotations := map [string ]string {
365
- "my-annotation" : "i-like-this" ,
366
- "old-annotation" : "old-value" ,
367
- "im-here-to-stay.kubernetes.io" : "for-a-while" ,
368
- "kubernetes.io/name" : "should-stay" ,
369
- "kubectl.kubernetes.io/name" : "should-stay" ,
370
- "k8s.io/name" : "should-stay" ,
371
- }
372
-
373
- Expect (configMap .Annotations ).To (Equal (expectedAnnotations ))
374
- })
349
+ // this is to ensure that pods are not restarted when instance annotations are updated
350
+ It ("does not update annotations on the config map" , func () {
351
+ instance .Annotations = map [string ]string {
352
+ "new-annotation" : "test" ,
353
+ }
354
+ Expect (configMapBuilder .Update (configMap )).To (Succeed ())
355
+ Expect (configMap .Annotations ).To (BeEmpty ())
375
356
})
376
357
})
377
358
})
0 commit comments