@@ -157,15 +157,17 @@ func (r *AutonomousDatabaseReconciler) eventFilterPredicate() predicate.Predicat
157
157
if adbOk {
158
158
oldADB := e .ObjectOld .(* dbv1alpha1.AutonomousDatabase )
159
159
160
+ specChanged := ! reflect .DeepEqual (oldADB .Spec , desiredADB .Spec )
160
161
statusChanged := ! reflect .DeepEqual (oldADB .Status , desiredADB .Status )
161
162
162
163
oldLastSucSpec := oldADB .GetAnnotations ()[dbv1alpha1 .LastSuccessfulSpec ]
163
164
desiredLastSucSpec := desiredADB .GetAnnotations ()[dbv1alpha1 .LastSuccessfulSpec ]
164
165
lastSucSpecChanged := oldLastSucSpec != desiredLastSucSpec
165
166
166
- if statusChanged || lastSucSpecChanged ||
167
+ if ( ! specChanged && statusChanged ) || lastSucSpecChanged ||
167
168
(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
169
171
return false
170
172
}
171
173
@@ -276,31 +278,36 @@ func (r *AutonomousDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.R
276
278
}
277
279
278
280
/******************************************************************
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.
282
285
******************************************************************/
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 {
287
288
return r .manageError (logger .WithName ("IsADBIntermediateState" ), modifiedADB , err )
288
289
}
290
+ return emptyResult , nil
291
+ }
289
292
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" )
290
301
return requeueResult , nil
291
302
}
292
303
293
304
/******************************************************************
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 .
297
308
******************************************************************/
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
- }
303
309
310
+ var requeue bool = false
304
311
if modifiedADB .GetDeletionTimestamp () != nil &&
305
312
controllerutil .ContainsFinalizer (modifiedADB , dbv1alpha1 .ADBFinalizer ) &&
306
313
modifiedADB .Status .LifecycleState == database .AutonomousDatabaseLifecycleStateTerminated {
@@ -312,10 +319,6 @@ func (r *AutonomousDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.R
312
319
return r .manageError (logger .WithName ("patchLastSuccessfulSpec" ), modifiedADB , err )
313
320
}
314
321
315
- if err := r .KubeClient .Status ().Update (context .TODO (), modifiedADB ); err != nil {
316
- return r .manageError (logger .WithName ("Status().Update" ), modifiedADB , err )
317
- }
318
-
319
322
if requeue {
320
323
logger .Info ("Reconcile queued" )
321
324
return requeueResult , nil
0 commit comments