@@ -34,7 +34,7 @@ import (
34
34
)
35
35
36
36
const (
37
- ClusterCreationTimeout = 5 * time .Second
37
+ ClusterCreationTimeout = 10 * time .Second
38
38
ClusterDeletionTimeout = 5 * time .Second
39
39
)
40
40
@@ -79,19 +79,15 @@ var _ = Describe("RabbitmqClusterController", func() {
79
79
})
80
80
81
81
By ("creating the server conf configmap" , func () {
82
- configMapName := cluster .ChildResourceName ("server-conf" )
83
- configMap , err := clientSet .CoreV1 ().ConfigMaps (cluster .Namespace ).Get (ctx , configMapName , metav1.GetOptions {})
84
- Expect (err ).NotTo (HaveOccurred ())
85
- Expect (configMap .Name ).To (Equal (configMapName ))
86
- Expect (configMap .OwnerReferences [0 ].Name ).To (Equal (cluster .Name ))
82
+ cfm := configMap (ctx , cluster , "server-conf" )
83
+ Expect (cfm .Name ).To (Equal (cluster .ChildResourceName ("server-conf" )))
84
+ Expect (cfm .OwnerReferences [0 ].Name ).To (Equal (cluster .Name ))
87
85
})
88
86
89
87
By ("creating the plugins conf configmap" , func () {
90
- configMapName := cluster .ChildResourceName ("plugins-conf" )
91
- configMap , err := clientSet .CoreV1 ().ConfigMaps (cluster .Namespace ).Get (ctx , configMapName , metav1.GetOptions {})
92
- Expect (err ).NotTo (HaveOccurred ())
93
- Expect (configMap .Name ).To (Equal (configMapName ))
94
- Expect (configMap .OwnerReferences [0 ].Name ).To (Equal (cluster .Name ))
88
+ cfm := configMap (ctx , cluster , "plugins-conf" )
89
+ Expect (cfm .Name ).To (Equal (cluster .ChildResourceName ("plugins-conf" )))
90
+ Expect (cfm .OwnerReferences [0 ].Name ).To (Equal (cluster .Name ))
95
91
})
96
92
97
93
By ("creating a rabbitmq default-user secret" , func () {
@@ -352,19 +348,13 @@ var _ = Describe("RabbitmqClusterController", func() {
352
348
})
353
349
354
350
Context ("Custom Resource updates" , func () {
355
- var (
356
- svcName string
357
- stsName string
358
- )
359
351
BeforeEach (func () {
360
352
cluster = & rabbitmqv1beta1.RabbitmqCluster {
361
353
ObjectMeta : metav1.ObjectMeta {
362
354
Name : "rabbitmq-cr-update" ,
363
355
Namespace : defaultNamespace ,
364
356
},
365
357
}
366
- svcName = cluster .ChildResourceName ("" )
367
- stsName = cluster .ChildResourceName ("server" )
368
358
369
359
Expect (client .Create (ctx , cluster )).To (Succeed ())
370
360
waitForClusterCreation (ctx , cluster , client )
@@ -381,8 +371,7 @@ var _ = Describe("RabbitmqClusterController", func() {
381
371
})).To (Succeed ())
382
372
383
373
Eventually (func () map [string ]string {
384
- svcName := cluster .ChildResourceName ("" )
385
- svc , _ := clientSet .CoreV1 ().Services (cluster .Namespace ).Get (ctx , svcName , metav1.GetOptions {})
374
+ svc := service (ctx , cluster , "" )
386
375
return svc .Annotations
387
376
}, 3 ).Should (HaveKeyWithValue ("test-key" , "test-value" ))
388
377
@@ -409,8 +398,7 @@ var _ = Describe("RabbitmqClusterController", func() {
409
398
})).To (Succeed ())
410
399
411
400
Eventually (func () corev1.ResourceList {
412
- sts , err := clientSet .AppsV1 ().StatefulSets (cluster .Namespace ).Get (ctx , stsName , metav1.GetOptions {})
413
- Expect (err ).NotTo (HaveOccurred ())
401
+ sts := statefulSet (ctx , cluster )
414
402
resourceRequirements = sts .Spec .Template .Spec .Containers [0 ].Resources
415
403
return resourceRequirements .Requests
416
404
}, 3 ).Should (HaveKeyWithValue (corev1 .ResourceCPU , expectedRequirements .Requests [corev1 .ResourceCPU ]))
@@ -430,7 +418,7 @@ var _ = Describe("RabbitmqClusterController", func() {
430
418
})).To (Succeed ())
431
419
432
420
Eventually (func () string {
433
- sts , _ := clientSet . AppsV1 (). StatefulSets ( cluster . Namespace ). Get ( ctx , stsName , metav1. GetOptions {} )
421
+ sts := statefulSet ( ctx , cluster )
434
422
return sts .Spec .Template .Spec .Containers [0 ].Image
435
423
}, 3 ).Should (Equal ("rabbitmq:3.8.0" ))
436
424
})
@@ -441,7 +429,7 @@ var _ = Describe("RabbitmqClusterController", func() {
441
429
})).To (Succeed ())
442
430
443
431
Eventually (func () []corev1.LocalObjectReference {
444
- sts , _ := clientSet . AppsV1 (). StatefulSets ( cluster . Namespace ). Get ( ctx , stsName , metav1. GetOptions {} )
432
+ sts := statefulSet ( ctx , cluster )
445
433
return sts .Spec .Template .Spec .ImagePullSecrets
446
434
}, 3 ).Should (ConsistOf (corev1.LocalObjectReference {Name : "my-new-secret" }))
447
435
})
@@ -453,13 +441,11 @@ var _ = Describe("RabbitmqClusterController", func() {
453
441
})).To (Succeed ())
454
442
455
443
Eventually (func () map [string ]string {
456
- service , err := clientSet .CoreV1 ().Services (cluster .Namespace ).Get (ctx , svcName , metav1.GetOptions {})
457
- Expect (err ).NotTo (HaveOccurred ())
458
- return service .Labels
444
+ svc := service (ctx , cluster , "" )
445
+ return svc .Labels
459
446
}, 3 ).Should (HaveKeyWithValue ("foo" , "bar" ))
460
- var sts * appsv1.StatefulSet
461
447
Eventually (func () map [string ]string {
462
- sts , _ = clientSet . AppsV1 (). StatefulSets ( cluster . Namespace ). Get ( ctx , stsName , metav1. GetOptions {} )
448
+ sts := statefulSet ( ctx , cluster )
463
449
return sts .Labels
464
450
}, 3 ).Should (HaveKeyWithValue ("foo" , "bar" ))
465
451
})
@@ -477,22 +463,19 @@ var _ = Describe("RabbitmqClusterController", func() {
477
463
478
464
It ("updates annotations for services" , func () {
479
465
Eventually (func () map [string ]string {
480
- service , err := clientSet .CoreV1 ().Services (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("nodes" ), metav1.GetOptions {})
481
- Expect (err ).NotTo (HaveOccurred ())
482
- return service .Annotations
466
+ svc := service (ctx , cluster , "nodes" )
467
+ return svc .Annotations
483
468
}, 3 ).Should (HaveKeyWithValue (annotationKey , annotationValue ))
484
469
485
470
Eventually (func () map [string ]string {
486
- service , err := clientSet .CoreV1 ().Services (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("" ), metav1.GetOptions {})
487
- Expect (err ).NotTo (HaveOccurred ())
488
- return service .Annotations
471
+ svc := service (ctx , cluster , "" )
472
+ return svc .Annotations
489
473
}, 3 ).Should (HaveKeyWithValue (annotationKey , annotationValue ))
490
474
})
491
475
492
476
It ("updates annotations for stateful set" , func () {
493
477
Eventually (func () map [string ]string {
494
- sts , err := clientSet .AppsV1 ().StatefulSets (cluster .Namespace ).Get (ctx , stsName , metav1.GetOptions {})
495
- Expect (err ).NotTo (HaveOccurred ())
478
+ sts := statefulSet (ctx , cluster )
496
479
return sts .Annotations
497
480
}, 3 ).Should (HaveKeyWithValue (annotationKey , annotationValue ))
498
481
})
@@ -542,9 +525,8 @@ var _ = Describe("RabbitmqClusterController", func() {
542
525
})).To (Succeed ())
543
526
544
527
Eventually (func () string {
545
- service , err := clientSet .CoreV1 ().Services (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("" ), metav1.GetOptions {})
546
- Expect (err ).NotTo (HaveOccurred ())
547
- return string (service .Spec .Type )
528
+ svc := service (ctx , cluster , "" )
529
+ return string (svc .Spec .Type )
548
530
}, 3 ).Should (Equal ("NodePort" ))
549
531
})
550
532
@@ -572,7 +554,7 @@ var _ = Describe("RabbitmqClusterController", func() {
572
554
})).To (Succeed ())
573
555
574
556
Eventually (func () * corev1.Affinity {
575
- sts , _ := clientSet . AppsV1 (). StatefulSets ( cluster . Namespace ). Get ( ctx , stsName , metav1. GetOptions {} )
557
+ sts := statefulSet ( ctx , cluster )
576
558
return sts .Spec .Template .Spec .Affinity
577
559
}, 3 ).Should (Equal (affinity ))
578
560
@@ -587,7 +569,7 @@ var _ = Describe("RabbitmqClusterController", func() {
587
569
r .Spec .Affinity = affinity
588
570
})).To (Succeed ())
589
571
Eventually (func () * corev1.Affinity {
590
- sts , _ := clientSet . AppsV1 (). StatefulSets ( cluster . Namespace ). Get ( ctx , stsName , metav1. GetOptions {} )
572
+ sts := statefulSet ( ctx , cluster )
591
573
return sts .Spec .Template .Spec .Affinity
592
574
}, 3 ).Should (BeNil ())
593
575
})
@@ -621,13 +603,9 @@ var _ = Describe("RabbitmqClusterController", func() {
621
603
})
622
604
623
605
It ("recreates child resources after deletion" , func () {
624
- oldConfMap , err := clientSet .CoreV1 ().ConfigMaps (defaultNamespace ).Get (ctx , configMapName , metav1.GetOptions {})
625
- Expect (err ).NotTo (HaveOccurred ())
626
-
606
+ oldConfMap := configMap (ctx , cluster , "server-conf" )
627
607
oldClientSvc := service (ctx , cluster , "" )
628
-
629
608
oldHeadlessSvc := service (ctx , cluster , "nodes" )
630
-
631
609
oldSts := statefulSet (ctx , cluster )
632
610
633
611
Expect (clientSet .AppsV1 ().StatefulSets (defaultNamespace ).Delete (ctx , stsName , metav1.DeleteOptions {})).NotTo (HaveOccurred ())
@@ -636,26 +614,17 @@ var _ = Describe("RabbitmqClusterController", func() {
636
614
Expect (clientSet .CoreV1 ().Services (defaultNamespace ).Delete (ctx , headlessServiceName , metav1.DeleteOptions {})).NotTo (HaveOccurred ())
637
615
638
616
Eventually (func () bool {
639
- sts , err := clientSet .AppsV1 ().StatefulSets (defaultNamespace ).Get (ctx , stsName , metav1.GetOptions {})
640
- if err != nil {
641
- return false
642
- }
617
+ sts := statefulSet (ctx , cluster )
643
618
return string (sts .UID ) != string (oldSts .UID )
644
619
}, 10 ).Should (BeTrue ())
645
620
646
621
Eventually (func () bool {
647
- clientSvc , err := clientSet .CoreV1 ().Services (defaultNamespace ).Get (ctx , svcName , metav1.GetOptions {})
648
- if err != nil {
649
- return false
650
- }
622
+ clientSvc := service (ctx , cluster , "" )
651
623
return string (clientSvc .UID ) != string (oldClientSvc .UID )
652
624
}, 5 ).Should (BeTrue ())
653
625
654
626
Eventually (func () bool {
655
- headlessSvc , err := clientSet .CoreV1 ().Services (defaultNamespace ).Get (ctx , headlessServiceName , metav1.GetOptions {})
656
- if err != nil {
657
- return false
658
- }
627
+ headlessSvc := service (ctx , cluster , "nodes" )
659
628
return string (headlessSvc .UID ) != string (oldHeadlessSvc .UID )
660
629
}, 5 ).Should (Not (Equal (oldHeadlessSvc .UID )))
661
630
@@ -1096,6 +1065,94 @@ var _ = Describe("RabbitmqClusterController", func() {
1096
1065
})
1097
1066
})
1098
1067
1068
+ Context ("Pause reconciliation" , func () {
1069
+ BeforeEach (func () {
1070
+ cluster = & rabbitmqv1beta1.RabbitmqCluster {
1071
+ ObjectMeta : metav1.ObjectMeta {
1072
+ Name : "rabbitmq-pause-reconcile" ,
1073
+ Namespace : defaultNamespace ,
1074
+ },
1075
+ }
1076
+ Expect (client .Create (ctx , cluster )).To (Succeed ())
1077
+ waitForClusterCreation (ctx , cluster , client )
1078
+ })
1079
+
1080
+ AfterEach (func () {
1081
+ Expect (client .Delete (ctx , cluster )).To (Succeed ())
1082
+ })
1083
+
1084
+ It ("works" , func () {
1085
+ By ("skipping reconciling if label is set to true" , func () {
1086
+ Expect (updateWithRetry (cluster , func (r * rabbitmqv1beta1.RabbitmqCluster ) {
1087
+ r .Labels = map [string ]string {"rabbitmq.com/pauseReconciliation" : "true" }
1088
+ r .Spec .Service .Type = "LoadBalancer"
1089
+ r .Spec .Rabbitmq .AdditionalConfig = "test=test"
1090
+ })).To (Succeed ())
1091
+
1092
+ // service type is unchanged
1093
+ Consistently (func () corev1.ServiceType {
1094
+ return service (ctx , cluster , "" ).Spec .Type
1095
+ }, 10 * time .Second ).Should (Equal (corev1 .ServiceTypeClusterIP ))
1096
+
1097
+ // configMap and statefulSet do not have their update and restart annotations set
1098
+ Expect (configMap (ctx , cluster , "server-conf" ).Annotations ).ShouldNot (HaveKey ("rabbitmq.com/serverConfUpdatedAt" ))
1099
+ Expect (statefulSet (ctx , cluster ).Annotations ).ShouldNot (HaveKey ("rabbitmq.com/lastRestartAt" ))
1100
+
1101
+ // PausedReconciliation event is published
1102
+ Expect (aggregateEventMsgs (ctx , cluster , "PausedReconciliation" )).To (
1103
+ ContainSubstring ("label 'rabbitmq.com/pauseReconciliation' is set to true" ))
1104
+
1105
+ // NoWarnings status.condition is set to false with reason 'reconciliation paused'
1106
+ Eventually (func () string {
1107
+ rmq := & rabbitmqv1beta1.RabbitmqCluster {}
1108
+ Expect (client .Get (ctx ,
1109
+ types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )).To (Succeed ())
1110
+ for i := range rmq .Status .Conditions {
1111
+ if rmq .Status .Conditions [i ].Type == status .NoWarnings {
1112
+ return fmt .Sprintf ("NoWarnings status: %s with reason: %s" ,
1113
+ rmq .Status .Conditions [i ].Status ,
1114
+ rmq .Status .Conditions [i ].Reason )
1115
+ }
1116
+ }
1117
+ return "NoWarnings status: condition not present"
1118
+ }, 5 ).Should (Equal ("NoWarnings status: False with reason: reconciliation paused" ))
1119
+ })
1120
+
1121
+ By ("resuming reconciliation when label is removed" , func () {
1122
+ Expect (updateWithRetry (cluster , func (r * rabbitmqv1beta1.RabbitmqCluster ) {
1123
+ r .Labels = map [string ]string {}
1124
+ })).To (Succeed ())
1125
+
1126
+ // service type is updated
1127
+ Eventually (func () corev1.ServiceType {
1128
+ svc := service (ctx , cluster , "" )
1129
+ return svc .Spec .Type
1130
+ }, 10 * time .Second ).Should (Equal (corev1 .ServiceTypeLoadBalancer ))
1131
+
1132
+ // configMap and statefulSet now have their update and restart annotations set
1133
+ Eventually (func () map [string ]string {
1134
+ return configMap (ctx , cluster , "server-conf" ).Annotations
1135
+ }, 10 * time .Second ).Should (HaveKey ("rabbitmq.com/serverConfUpdatedAt" ))
1136
+ Eventually (func () map [string ]string {
1137
+ return statefulSet (ctx , cluster ).Spec .Template .Annotations
1138
+ }, 10 * time .Second ).Should (HaveKey ("rabbitmq.com/lastRestartAt" ))
1139
+
1140
+ // NoWarnings status.condition is set to true
1141
+ Eventually (func () string {
1142
+ rmq := & rabbitmqv1beta1.RabbitmqCluster {}
1143
+ Expect (client .Get (ctx ,
1144
+ types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, rmq )).To (Succeed ())
1145
+ for i := range rmq .Status .Conditions {
1146
+ if rmq .Status .Conditions [i ].Type == status .NoWarnings {
1147
+ return fmt .Sprintf ("NoWarnings status: %s" , rmq .Status .Conditions [i ].Status )
1148
+ }
1149
+ }
1150
+ return "NoWarnings status: condition not present"
1151
+ }, 5 ).Should (Equal ("NoWarnings status: True" ))
1152
+ })
1153
+ })
1154
+ })
1155
+
1099
1156
})
1100
1157
1101
1158
func extractContainer (containers []corev1.Container , containerName string ) corev1.Container {
@@ -1144,6 +1201,17 @@ func service(ctx context.Context, rabbitmqCluster *rabbitmqv1beta1.RabbitmqClust
1144
1201
return svc
1145
1202
}
1146
1203
1204
+ func configMap (ctx context.Context , rabbitmqCluster * rabbitmqv1beta1.RabbitmqCluster , configMapName string ) * corev1.ConfigMap {
1205
+ cfmName := rabbitmqCluster .ChildResourceName (configMapName )
1206
+ var cfm * corev1.ConfigMap
1207
+ EventuallyWithOffset (1 , func () error {
1208
+ var err error
1209
+ cfm , err = clientSet .CoreV1 ().ConfigMaps (rabbitmqCluster .Namespace ).Get (ctx , cfmName , metav1.GetOptions {})
1210
+ return err
1211
+ }, 10 ).Should (Succeed ())
1212
+ return cfm
1213
+ }
1214
+
1147
1215
func createSecret (ctx context.Context , secretName string , namespace string , data map [string ]string ) (corev1.Secret , error ) {
1148
1216
secret := corev1.Secret {
1149
1217
ObjectMeta : metav1.ObjectMeta {
0 commit comments