@@ -110,19 +110,12 @@ func (r *RabbitmqClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, er
110110 return ctrl.Result {}, err
111111 }
112112
113- childResources , err := r .getChildResources (ctx , * rabbitmqCluster )
113+ requeueAfter , err := r .updateStatus (ctx , rabbitmqCluster )
114114 if err != nil {
115115 return ctrl.Result {}, err
116116 }
117-
118- oldConditions := make ([]status.RabbitmqClusterCondition , len (rabbitmqCluster .Status .Conditions ))
119- copy (oldConditions , rabbitmqCluster .Status .Conditions )
120- rabbitmqCluster .Status .SetConditions (childResources )
121-
122- if ! reflect .DeepEqual (rabbitmqCluster .Status .Conditions , oldConditions ) {
123- if err = r .Status ().Update (ctx , rabbitmqCluster ); err != nil {
124- return ctrl.Result {}, err
125- }
117+ if requeueAfter > 0 {
118+ return ctrl.Result {RequeueAfter : requeueAfter }, nil
126119 }
127120
128121 sts , err := r .statefulSet (ctx , rabbitmqCluster )
@@ -186,7 +179,7 @@ func (r *RabbitmqClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, er
186179 }
187180 }
188181
189- requeueAfter , err : = r .restartStatefulSetIfNeeded (ctx , rabbitmqCluster )
182+ requeueAfter , err = r .restartStatefulSetIfNeeded (ctx , rabbitmqCluster )
190183 if err != nil {
191184 return ctrl.Result {}, err
192185 }
@@ -252,7 +245,31 @@ func (r *RabbitmqClusterReconciler) logAndRecordOperationResult(rmq runtime.Obje
252245 }
253246}
254247
255- func (r * RabbitmqClusterReconciler ) getChildResources (ctx context.Context , rmq rabbitmqv1beta1.RabbitmqCluster ) ([]runtime.Object , error ) {
248+ func (r * RabbitmqClusterReconciler ) updateStatus (ctx context.Context , rmq * rabbitmqv1beta1.RabbitmqCluster ) (time.Duration , error ) {
249+ childResources , err := r .getChildResources (ctx , rmq )
250+ if err != nil {
251+ return 0 , err
252+ }
253+
254+ oldConditions := make ([]status.RabbitmqClusterCondition , len (rmq .Status .Conditions ))
255+ copy (oldConditions , rmq .Status .Conditions )
256+ rmq .Status .SetConditions (childResources )
257+
258+ if ! reflect .DeepEqual (rmq .Status .Conditions , oldConditions ) {
259+ if err = r .Status ().Update (ctx , rmq ); err != nil {
260+ if errors .IsConflict (err ) {
261+ r .Log .Info ("failed to update status because of conflict; requeueing..." ,
262+ "namespace" , rmq .Namespace ,
263+ "name" , rmq .Name )
264+ return 2 * time .Second , nil
265+ }
266+ return 0 , err
267+ }
268+ }
269+ return 0 , nil
270+ }
271+
272+ func (r * RabbitmqClusterReconciler ) getChildResources (ctx context.Context , rmq * rabbitmqv1beta1.RabbitmqCluster ) ([]runtime.Object , error ) {
256273 sts := & appsv1.StatefulSet {}
257274 endPoints := & corev1.Endpoints {}
258275
0 commit comments