@@ -2,7 +2,6 @@ package controllers
22
33import (
44 "context"
5- "errors"
65 "fmt"
76 "strconv"
87
@@ -16,22 +15,23 @@ import (
1615
1716const beforeZeroReplicasConfigured = "rabbitmq.com/before-zero-replicas-configured"
1817
19- // scaleToZero checks if the desired replicas is zero and the current replicas is not zero.
20- func ( r * RabbitmqClusterReconciler ) scaleToZero (current , sts * appsv1.StatefulSet ) bool {
18+ // ScaleToZero checks if the desired replicas is zero and the current replicas is not zero.
19+ func ScaleToZero (current , sts * appsv1.StatefulSet ) bool {
2120 currentReplicas := * current .Spec .Replicas
2221 desiredReplicas := * sts .Spec .Replicas
2322 return desiredReplicas == 0 && currentReplicas > 0
2423}
2524
26- // scaleFromZero checks if the current replicas is zero and the desired replicas is greater than zero.
27- func ( r * RabbitmqClusterReconciler ) scaleFromZero (current , sts * appsv1.StatefulSet ) bool {
25+ // ScaleFromZero checks if the current replicas is zero and the desired replicas is greater than zero.
26+ func ScaleFromZero (current , sts * appsv1.StatefulSet ) bool {
2827 currentReplicas := * current .Spec .Replicas
2928 desiredReplicas := * sts .Spec .Replicas
3029 return currentReplicas == 0 && desiredReplicas > 0
3130}
3231
3332// scaleDownFromZero checks if the current replicas is desired replicas would be greatter than replicas configured before zero state.
3433func (r * RabbitmqClusterReconciler ) scaleFromZeroToBeforeReplicasConfigured (ctx context.Context , cluster * v1beta1.RabbitmqCluster , sts * appsv1.StatefulSet ) bool {
34+ logger := ctrl .LoggerFrom (ctx )
3535 var err error
3636 var beforeZeroReplicas int64
3737 desiredReplicas := * sts .Spec .Replicas
@@ -46,7 +46,7 @@ func (r *RabbitmqClusterReconciler) scaleFromZeroToBeforeReplicasConfigured(ctx
4646 reason := "TransformErrorOperation"
4747 err = r .recordEventsAndSetCondition (ctx , cluster , status .ReconcileSuccess , corev1 .ConditionFalse , corev1 .EventTypeWarning , reason , msg )
4848 if err != nil {
49- return true
49+ logger . V ( 1 ). Info ( err . Error ())
5050 }
5151 return true
5252 }
@@ -55,7 +55,7 @@ func (r *RabbitmqClusterReconciler) scaleFromZeroToBeforeReplicasConfigured(ctx
5555 reason := "UnsupportedOperation"
5656 err = r .recordEventsAndSetCondition (ctx , cluster , status .ReconcileSuccess , corev1 .ConditionFalse , corev1 .EventTypeWarning , reason , msg )
5757 if err != nil {
58- return true
58+ logger . V ( 1 ). Info ( err . Error ())
5959 }
6060 return true
6161 }
@@ -66,15 +66,13 @@ func (r *RabbitmqClusterReconciler) scaleFromZeroToBeforeReplicasConfigured(ctx
6666// saveReplicasBeforeZero saves the current replicas count in an annotation before scaling down to zero.
6767// This is used to prevent scaling down when the cluster change from zero replicas to a number less than the saved replicas count.
6868func (r * RabbitmqClusterReconciler ) saveReplicasBeforeZero (ctx context.Context , cluster * v1beta1.RabbitmqCluster , current * appsv1.StatefulSet ) error {
69- var err error
7069 currentReplicas := * current .Spec .Replicas
7170 logger := ctrl .LoggerFrom (ctx )
72- msg := "Cluster Scale down to 0 replicas. "
71+ msg := "Cluster Scale down to 0 replicas"
7372 reason := "ScaleDownToZero"
7473 logger .Info (msg )
75- err = r .updateAnnotation (ctx , cluster , cluster .Namespace , cluster .Name , beforeZeroReplicasConfigured , fmt .Sprint (currentReplicas ))
7674 r .Recorder .Event (cluster , corev1 .EventTypeNormal , reason , msg )
77- return err
75+ return r . updateAnnotation ( ctx , cluster , cluster . Namespace , cluster . Name , beforeZeroReplicasConfigured , fmt . Sprint ( currentReplicas ))
7876}
7977
8078// If the annotation rabbitmq.com/before-zero-replicas-configured exists it will be deleted.
@@ -85,11 +83,7 @@ func (r *RabbitmqClusterReconciler) removeReplicasBeforeZeroAnnotationIfExists(c
8583}
8684
8785func (r * RabbitmqClusterReconciler ) recordEventsAndSetCondition (ctx context.Context , cluster * v1beta1.RabbitmqCluster , condType status.RabbitmqClusterConditionType , condStatus corev1.ConditionStatus , eventType , reason , msg string ) error {
88- logger := ctrl .LoggerFrom (ctx )
89- var statusErr error
90- logger .Error (errors .New (reason ), msg )
9186 r .Recorder .Event (cluster , eventType , reason , msg )
9287 cluster .Status .SetCondition (condType , condStatus , reason , msg )
93- statusErr = r .Status ().Update (ctx , cluster )
94- return statusErr
88+ return r .Status ().Update (ctx , cluster )
9589}
0 commit comments