@@ -3,7 +3,9 @@ package controllers_test
33import (
44 "context"
55 "fmt"
6+ "github.com/rabbitmq/cluster-operator/internal/status"
67 "k8s.io/utils/pointer"
8+ runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
79
810 rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
911
@@ -91,6 +93,7 @@ var _ = Describe("Reconcile TLS", func() {
9193 cluster = rabbitmqClusterWithTLS (ctx , "tls-secret-missing" , defaultNamespace , tlsSpec )
9294
9395 verifyTLSErrorEvents (ctx , cluster , fmt .Sprintf ("TLS secret tls-secret-missing in namespace %s does not have the field ca.crt" , defaultNamespace ))
96+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
9497 })
9598 })
9699
@@ -104,6 +107,7 @@ var _ = Describe("Reconcile TLS", func() {
104107 }
105108 cluster = rabbitmqClusterWithTLS (ctx , "rabbitmq-tls-secret-does-not-exist" , defaultNamespace , tlsSpec )
106109 verifyTLSErrorEvents (ctx , cluster , "Failed to get CA certificate secret" )
110+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
107111
108112 _ , err := clientSet .AppsV1 ().StatefulSets (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("server" ), metav1.GetOptions {})
109113 Expect (err ).To (HaveOccurred ())
@@ -136,6 +140,7 @@ var _ = Describe("Reconcile TLS", func() {
136140 }
137141 cluster = rabbitmqClusterWithTLS (ctx , "rabbitmq-mutual-tls-missing" , defaultNamespace , tlsSpec )
138142 verifyTLSErrorEvents (ctx , cluster , fmt .Sprintf ("TLS secret ca-cert-secret-invalid in namespace %s does not have the field ca.crt" , defaultNamespace ))
143+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
139144 })
140145 })
141146 })
@@ -191,18 +196,19 @@ var _ = Describe("Reconcile TLS", func() {
191196
192197 It ("fails to deploy the RabbitmqCluster" , func () {
193198 verifyTLSErrorEvents (ctx , cluster , fmt .Sprintf ("TLS secret rabbitmq-tls-malformed in namespace %s does not have the fields tls.crt and tls.key" , defaultNamespace ))
199+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
194200 })
195201 })
196202
197203 When ("the TLS secret does not exist" , func () {
198204 It ("fails to deploy the RabbitmqCluster until the secret is detected" , func () {
199-
200205 tlsSpec := rabbitmqv1beta1.TLSSpec {
201206 SecretName : "tls-secret-does-not-exist" ,
202207 }
203208 cluster = rabbitmqClusterWithTLS (ctx , "rabbitmq-tls-secret-does-not-exist" , defaultNamespace , tlsSpec )
204209
205210 verifyTLSErrorEvents (ctx , cluster , "Failed to get TLS secret" )
211+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
206212
207213 _ , err := clientSet .AppsV1 ().StatefulSets (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("server" ), metav1.GetOptions {})
208214 Expect (err ).To (HaveOccurred ())
@@ -222,7 +228,7 @@ var _ = Describe("Reconcile TLS", func() {
222228 })
223229
224230 When ("DiableNonTLSListeners set to true" , func () {
225- It ("errors and logs TLSError when TLS is not enabled" , func () {
231+ It ("returns an error, logs TLSError and set ReconcileSuccess to false when TLS is not enabled" , func () {
226232 tlsSpec := rabbitmqv1beta1.TLSSpec {
227233 DisableNonTLSListeners : true ,
228234 }
@@ -232,10 +238,28 @@ var _ = Describe("Reconcile TLS", func() {
232238
233239 _ , err := clientSet .AppsV1 ().StatefulSets (cluster .Namespace ).Get (ctx , cluster .ChildResourceName ("server" ), metav1.GetOptions {})
234240 Expect (err ).To (HaveOccurred ())
241+ verifyReconcileSuccessFalse (cluster .Name , cluster .Namespace )
235242 })
236243 })
237244})
238245
246+ func verifyReconcileSuccessFalse (name , namespace string ) bool {
247+ return EventuallyWithOffset (1 , func () string {
248+ rabbit := & rabbitmqv1beta1.RabbitmqCluster {}
249+ Expect (client .Get (ctx , runtimeClient.ObjectKey {
250+ Name : name ,
251+ Namespace : namespace ,
252+ }, rabbit )).To (Succeed ())
253+
254+ for i := range rabbit .Status .Conditions {
255+ if rabbit .Status .Conditions [i ].Type == status .ReconcileSuccess {
256+ return fmt .Sprintf ("ReconcileSuccess status: %s" , rabbit .Status .Conditions [i ].Status )
257+ }
258+ }
259+ return "ReconcileSuccess status: condition not present"
260+ }, 5 ).Should (Equal ("ReconcileSuccess status: False" ))
261+ }
262+
239263func tlsSecretWithCACert (ctx context.Context , secretName , namespace string ) {
240264 tlsData := map [string ]string {
241265 "tls.crt" : "this is a tls cert" ,
0 commit comments