@@ -66,6 +66,27 @@ var _ = Describe("GenerateServerConfigMap", func() {
66
66
var configMap * corev1.ConfigMap
67
67
68
68
BeforeEach (func () {
69
+ instance = rabbitmqv1beta1.RabbitmqCluster {
70
+ ObjectMeta : metav1.ObjectMeta {
71
+ Name : "rabbit-example" ,
72
+ },
73
+ }
74
+ instance .Labels = map [string ]string {
75
+ "app.kubernetes.io/foo" : "bar" ,
76
+ "foo" : "bar" ,
77
+ "rabbitmq" : "is-great" ,
78
+ "foo/app.kubernetes.io" : "edgecase" ,
79
+ }
80
+ instance .Annotations = map [string ]string {
81
+ "my-annotation" : "i-like-this" ,
82
+ "kubernetes.io/name" : "i-do-not-like-this" ,
83
+ "kubectl.kubernetes.io/name" : "i-do-not-like-this" ,
84
+ "k8s.io/name" : "i-do-not-like-this" ,
85
+ "kubernetes.io/other" : "i-do-not-like-this" ,
86
+ "kubectl.kubernetes.io/other" : "i-do-not-like-this" ,
87
+ "k8s.io/other" : "i-do-not-like-this" ,
88
+ }
89
+
69
90
obj , err := configMapBuilder .Build ()
70
91
configMap = obj .(* corev1.ConfigMap )
71
92
Expect (err ).NotTo (HaveOccurred ())
@@ -75,6 +96,32 @@ var _ = Describe("GenerateServerConfigMap", func() {
75
96
Expect (configMap .Name ).To (Equal (builder .Instance .ChildResourceName ("server-conf" )))
76
97
Expect (configMap .Namespace ).To (Equal (builder .Instance .Namespace ))
77
98
})
99
+
100
+ It ("adds labels from the instance and default labels" , func () {
101
+ Expect (len (configMap .Labels )).To (Equal (6 ))
102
+ Expect (configMap .Labels ).To (SatisfyAll (
103
+ HaveKeyWithValue ("foo" , "bar" ),
104
+ HaveKeyWithValue ("rabbitmq" , "is-great" ),
105
+ HaveKeyWithValue ("foo/app.kubernetes.io" , "edgecase" ),
106
+ HaveKeyWithValue ("app.kubernetes.io/name" , instance .Name ),
107
+ HaveKeyWithValue ("app.kubernetes.io/component" , "rabbitmq" ),
108
+ HaveKeyWithValue ("app.kubernetes.io/part-of" , "rabbitmq" ),
109
+ Not (HaveKey ("app.kubernetes.io/foo" )),
110
+ ))
111
+ })
112
+
113
+ It ("adds annotations from the instance" , func () {
114
+ Expect (len (configMap .Annotations )).To (Equal (1 ))
115
+ Expect (configMap .Annotations ).To (SatisfyAll (
116
+ HaveKeyWithValue ("my-annotation" , "i-like-this" ),
117
+ Not (HaveKey ("kubernetes.io/name" )),
118
+ Not (HaveKey ("kubectl.kubernetes.io/name" )),
119
+ Not (HaveKey ("k8s.io/name" )),
120
+ Not (HaveKey ("kubernetes.io/other" )),
121
+ Not (HaveKey ("kubectl.kubernetes.io/other" )),
122
+ Not (HaveKey ("k8s.io/other" )),
123
+ ))
124
+ })
78
125
})
79
126
80
127
Context ("Update" , func () {
@@ -284,94 +331,33 @@ ssl_options.verify = verify_peer
284
331
})
285
332
})
286
333
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
- })
334
+ // this is to ensure that pods are not restarted when instance labels are updated
335
+ It ("does not update labels on the config map" , func () {
336
+ configMap .Labels = map [string ]string {
337
+ "app.kubernetes.io/name" : instance .Name ,
338
+ "app.kubernetes.io/component" : "rabbitmq" ,
339
+ "app.kubernetes.io/part-of" : "rabbitmq" ,
340
+ }
341
+ instance .Labels = map [string ]string {
342
+ "new-label" : "test" ,
343
+ }
344
+ Expect (configMapBuilder .Update (configMap )).To (Succeed ())
345
+ Expect (len (configMap .Labels )).To (Equal (3 ))
346
+ Expect (configMap .Labels ).To (SatisfyAll (
347
+ HaveKeyWithValue ("app.kubernetes.io/name" , instance .Name ),
348
+ HaveKeyWithValue ("app.kubernetes.io/component" , "rabbitmq" ),
349
+ HaveKeyWithValue ("app.kubernetes.io/part-of" , "rabbitmq" ),
350
+ Not (HaveKey ("new-label" )),
351
+ ))
328
352
})
329
353
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
- })
354
+ // this is to ensure that pods are not restarted when instance annotations are updated
355
+ It ("does not update labels on the config map" , func () {
356
+ instance .Annotations = map [string ]string {
357
+ "new-annotation" : "test" ,
358
+ }
359
+ Expect (configMapBuilder .Update (configMap )).To (Succeed ())
360
+ Expect (configMap .Annotations ).To (BeEmpty ())
375
361
})
376
362
})
377
363
})
0 commit comments