@@ -30,8 +30,8 @@ import (
3030 "syscall"
3131 "time"
3232
33- "k8s.io/utils/ptr"
3433 "k8s.io/apimachinery/pkg/api/equality"
34+ "k8s.io/utils/ptr"
3535
3636 "github.com/FoundationDB/fdb-kubernetes-operator/v2/pkg/fdbadminclient"
3737 "github.com/FoundationDB/fdb-kubernetes-operator/v2/pkg/podmanager"
@@ -181,15 +181,23 @@ func (r *FoundationDBClusterReconciler) Reconcile(
181181 ctx context.Context ,
182182 request ctrl.Request ,
183183) (ctrl.Result , error ) {
184+ return processResult (r .doReconcile (ctx , request ))
185+ }
186+
187+ // doReconcile will run the reconcile logic for the FoundationDBClusterReconciler.
188+ func (r * FoundationDBClusterReconciler ) doReconcile (
189+ ctx context.Context ,
190+ request ctrl.Request ,
191+ ) (* ctrl.Result , error ) {
184192 cluster := & fdbv1beta2.FoundationDBCluster {}
185193
186194 err := r .Get (ctx , request .NamespacedName , cluster )
187195 if err != nil {
188196 if k8serrors .IsNotFound (err ) {
189- return ctrl. Result {} , nil
197+ return nil , nil
190198 }
191199 // Error reading the object - requeue the request.
192- return ctrl. Result {} , err
200+ return nil , err
193201 }
194202
195203 clusterLog := globalControllerLogger .WithValues (
@@ -206,6 +214,7 @@ func (r *FoundationDBClusterReconciler) Reconcile(
206214
207215 originalStatus := cluster .Status .DeepCopy ()
208216 startTime := time .Now ()
217+ result := & ctrl.Result {}
209218 defer func () {
210219 // If the cluster.Status has changed compared to the original Status, we have to update the status.
211220 // See: https://github.com/kubernetes-sigs/kubebuilder/issues/592
@@ -216,6 +225,10 @@ func (r *FoundationDBClusterReconciler) Reconcile(
216225 err = r .updateOrApply (ctx , cluster )
217226 if err != nil {
218227 clusterLog .Error (err , "Error updating cluster clusterStatus" )
228+ // If no requeue is planned, we should target a requeue to ensure that the status will be updated.
229+ if result .IsZero () || result .RequeueAfter == 0 {
230+ result .RequeueAfter = 2 * time .Second
231+ }
219232 }
220233 }
221234
@@ -232,33 +245,33 @@ func (r *FoundationDBClusterReconciler) Reconcile(
232245 if cluster .Spec .Skip {
233246 clusterLog .Info ("Skipping cluster with skip value true" , "skip" , cluster .Spec .Skip )
234247 // Don't requeue
235- return ctrl. Result {} , nil
248+ return nil , nil
236249 }
237250
238251 err = internal .NormalizeClusterSpec (cluster , r .DeprecationOptions )
239252 if err != nil {
240- return ctrl. Result {}, err
253+ return nil , nil
241254 }
242255
243256 err = cluster .Validate ()
244257 if err != nil {
245258 r .Recorder .Event (cluster , corev1 .EventTypeWarning , "ClusterSpec not valid" , err .Error ())
246- return ctrl. Result {} , fmt .Errorf ("ClusterSpec is not valid: %w" , err )
259+ return nil , fmt .Errorf ("ClusterSpec is not valid: %w" , err )
247260 }
248261
249262 adminClient , err := r .getAdminClient (clusterLog , cluster )
250263 if err != nil {
251- return ctrl. Result {} , err
264+ return nil , err
252265 }
253266 defer func () {
254267 _ = adminClient .Close ()
255268 }()
256269 supportedVersion , err := adminClient .VersionSupported (cluster .Spec .Version )
257270 if err != nil {
258- return ctrl. Result {} , err
271+ return nil , err
259272 }
260273 if ! supportedVersion {
261- return ctrl. Result {} , fmt .Errorf ("version %s is not supported" , cluster .Spec .Version )
274+ return nil , fmt .Errorf ("version %s is not supported" , cluster .Spec .Version )
262275 }
263276
264277 // When using DNS entries in the cluster file, we want to make sure to create pods if required before doing any
@@ -336,13 +349,13 @@ func (r *FoundationDBClusterReconciler) Reconcile(
336349 process , err := os .FindProcess (os .Getpid ())
337350 if err != nil {
338351 fmt .Printf ("Error finding process: %v\n " , err )
339- return ctrl.Result {RequeueAfter : 5 * time .Second }, err
352+ return & ctrl.Result {RequeueAfter : 5 * time .Second }, err
340353 }
341354
342355 err = process .Signal (syscall .SIGTERM )
343356 if err != nil {
344357 fmt .Printf ("Error sending signal: %v\n " , err )
345- return ctrl.Result {RequeueAfter : 5 * time .Second }, err
358+ return & ctrl.Result {RequeueAfter : 5 * time .Second }, err
346359 }
347360 }
348361 }
@@ -399,7 +412,7 @@ func (r *FoundationDBClusterReconciler) Reconcile(
399412 delayedRequeueDuration = 2 * time .Second
400413 }
401414
402- return ctrl.Result {RequeueAfter : delayedRequeueDuration }, nil
415+ return & ctrl.Result {RequeueAfter : delayedRequeueDuration }, nil
403416 }
404417
405418 clusterLog .Info ("Reconciliation complete" , "generation" , cluster .Status .Generations .Reconciled )
@@ -410,7 +423,7 @@ func (r *FoundationDBClusterReconciler) Reconcile(
410423 fmt .Sprintf ("Reconciled generation %d" , cluster .Status .Generations .Reconciled ),
411424 )
412425
413- return ctrl. Result {} , nil
426+ return result , nil
414427}
415428
416429// runClusterSubReconciler will start the subReconciler and will log the duration of the subReconciler.
0 commit comments