@@ -157,15 +157,17 @@ func (r *AutonomousDatabaseReconciler) eventFilterPredicate() predicate.Predicat
157157 if adbOk {
158158 oldADB := e .ObjectOld .(* dbv1alpha1.AutonomousDatabase )
159159
160+ specChanged := ! reflect .DeepEqual (oldADB .Spec , desiredADB .Spec )
160161 statusChanged := ! reflect .DeepEqual (oldADB .Status , desiredADB .Status )
161162
162163 oldLastSucSpec := oldADB .GetAnnotations ()[dbv1alpha1 .LastSuccessfulSpec ]
163164 desiredLastSucSpec := desiredADB .GetAnnotations ()[dbv1alpha1 .LastSuccessfulSpec ]
164165 lastSucSpecChanged := oldLastSucSpec != desiredLastSucSpec
165166
166- if statusChanged || lastSucSpecChanged ||
167+ if ( ! specChanged && statusChanged ) || lastSucSpecChanged ||
167168 (controllerutil .ContainsFinalizer (oldADB , dbv1alpha1 .ADBFinalizer ) != controllerutil .ContainsFinalizer (desiredADB , dbv1alpha1 .ADBFinalizer )) {
168- // Don't enqueue if the status, lastSucSpec, or the finalizler changes the first time
169+ // Don't enqueue in the folowing condition:
170+ // 1. only status changes 2. lastSucSpec changes 3. ADBFinalizer changes
169171 return false
170172 }
171173
@@ -276,31 +278,36 @@ func (r *AutonomousDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.R
276278 }
277279
278280 /******************************************************************
279- * Requeue if it's in an intermediate state. Update the status right before
280- * exiting the reconcile, otherwise the modifiedADB will be overwritten
281- * by the object returned from the cluster.
281+ * Update the resource if the spec has been changed.
282+ * Requeue if it's in an intermediate state. Update the status first
283+ * , otherwise the modifiedADB will be overwritten by the object
284+ * returned from the cluster.
282285 ******************************************************************/
283- if dbv1alpha1 .IsADBIntermediateState (modifiedADB .Status .LifecycleState ) {
284- logger .WithName ("IsADBIntermediateState" ).Info ("LifecycleState is " + string (modifiedADB .Status .LifecycleState ) + "; reconcile queued" )
285-
286- if err := r .KubeClient .Status ().Update (context .TODO (), modifiedADB ); err != nil {
286+ if ! reflect .DeepEqual (modifiedADB .Spec , desiredADB .Spec ) {
287+ if err := r .KubeClient .Update (context .TODO (), modifiedADB ); err != nil {
287288 return r .manageError (logger .WithName ("IsADBIntermediateState" ), modifiedADB , err )
288289 }
290+ return emptyResult , nil
291+ }
289292
293+ copiedADB := modifiedADB .DeepCopy ()
294+ if err := r .KubeClient .Status ().Update (context .TODO (), modifiedADB ); err != nil {
295+ return r .manageError (logger .WithName ("Status().Update" ), modifiedADB , err )
296+ }
297+ modifiedADB .Spec = copiedADB .Spec
298+
299+ if dbv1alpha1 .IsADBIntermediateState (modifiedADB .Status .LifecycleState ) {
300+ logger .WithName ("IsADBIntermediateState" ).Info ("LifecycleState is " + string (modifiedADB .Status .LifecycleState ) + "; reconcile queued" )
290301 return requeueResult , nil
291302 }
292303
293304 /******************************************************************
294- * Update the lastSucSpec and the status , and then finish the reconcile.
295- * Requeue if it's in an intermediate state or the modifiedADB
296- * doesn't match the desiredADB .
305+ * Update the lastSucSpec, and then finish the reconcile.
306+ * Requeue if the ADB is terminated, but the finalizer is not yet
307+ * removed .
297308 ******************************************************************/
298- // Do the comparison before updating the status to avoid being overwritten
299- var requeue bool = false
300- if ! reflect .DeepEqual (modifiedADB .Spec , desiredADB .Spec ) {
301- requeue = true
302- }
303309
310+ var requeue bool = false
304311 if modifiedADB .GetDeletionTimestamp () != nil &&
305312 controllerutil .ContainsFinalizer (modifiedADB , dbv1alpha1 .ADBFinalizer ) &&
306313 modifiedADB .Status .LifecycleState == database .AutonomousDatabaseLifecycleStateTerminated {
@@ -312,10 +319,6 @@ func (r *AutonomousDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.R
312319 return r .manageError (logger .WithName ("patchLastSuccessfulSpec" ), modifiedADB , err )
313320 }
314321
315- if err := r .KubeClient .Status ().Update (context .TODO (), modifiedADB ); err != nil {
316- return r .manageError (logger .WithName ("Status().Update" ), modifiedADB , err )
317- }
318-
319322 if requeue {
320323 logger .Info ("Reconcile queued" )
321324 return requeueResult , nil
0 commit comments