@@ -291,43 +291,45 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
291
291
292
292
addonObject , ok := instance .(addonsv1alpha1.CommonObject )
293
293
unstruct , unstructOk := instance .(* unstructured.Unstructured )
294
- aggregatedStatus := string (aggregateStatus (statusMap ))
294
+ aggregatedPhase := string (aggregateStatus (statusMap ))
295
+ changed := false
295
296
if ok {
296
297
addonStatus := addonObject .GetCommonStatus ()
297
- if addonStatus .Phase != aggregatedStatus {
298
- addonStatus .Phase = aggregatedStatus
298
+ if addonStatus .Phase != aggregatedPhase {
299
+ addonStatus .Phase = aggregatedPhase
299
300
addonObject .SetCommonStatus (addonStatus )
300
- log .WithValues ("name" , addonObject .GetName ()).WithValues ("status" , addonStatus ).Info ("updating status" )
301
- err = r .client .Status ().Update (ctx , addonObject )
302
- if err != nil {
303
- log .Error (err , "error updating status" )
304
- return reconcile.Result {}, err
305
- }
301
+ changed = true
306
302
}
307
303
} else if unstructOk {
308
304
statusPhase , _ , err := unstructured .NestedString (unstruct .Object , "status" , "phase" )
309
305
if err != nil {
306
+ log .Error (err , "error retrieving status" )
310
307
return reconcile.Result {}, err
311
308
}
312
309
313
- if statusPhase != aggregatedStatus {
314
- err := unstructured .SetNestedField (unstruct .Object , statusPhase , "status" , "phase" )
315
- if err != nil {
316
- return reconcile.Result {}, err
317
- }
318
- log .WithValues ("name" , addonObject .GetName ()).WithValues ("phase" , statusPhase ).Info ("updating status" )
319
- err = r .client .Status ().Update (ctx , unstruct )
310
+ if statusPhase != aggregatedPhase {
311
+ err := unstructured .SetNestedField (unstruct .Object , aggregatedPhase , "status" , "phase" )
320
312
if err != nil {
321
- log .Error (err , "error updating status" )
313
+ log .Error (err , "error retrieving status" )
322
314
return reconcile.Result {}, err
323
315
}
316
+ changed = true
324
317
}
325
318
} else {
326
319
return reconcile.Result {}, fmt .Errorf ("instance %T was not an addonsv1alpha1.CommonObject or unstructured." +
327
320
"Unstructured" ,
328
321
instance )
329
322
}
330
323
324
+ if changed == true {
325
+ log .WithValues ("name" , instance .GetName ()).WithValues ("phase" , aggregatedPhase ).Info ("updating status" )
326
+ err = r .client .Status ().Update (ctx , instance )
327
+ if err != nil {
328
+ log .Error (err , "error updating status" )
329
+ return reconcile.Result {}, err
330
+ }
331
+ }
332
+
331
333
if r .options .sink != nil {
332
334
if err := r .options .sink .Notify (ctx , instance , objects ); err != nil {
333
335
log .Error (err , "notifying sink" )
@@ -620,12 +622,13 @@ func aggregateStatus(m map[status.Status]bool) status.Status {
620
622
failed := m [status .FailedStatus ]
621
623
622
624
if inProgress || terminating {
623
- return status .TerminatingStatus
625
+ return status .InProgressStatus
624
626
}
625
627
626
628
if failed {
627
629
return status .FailedStatus
628
630
}
631
+
629
632
return status .CurrentStatus
630
633
}
631
634
0 commit comments