@@ -290,20 +290,42 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
290
290
}
291
291
292
292
addonObject , ok := instance .(addonsv1alpha1.CommonObject )
293
- if ! ok {
294
- return reconcile.Result {}, fmt .Errorf ("instance %T was not an addonsv1alpha1.CommonObject" , instance )
295
- }
296
- status := addonObject .GetCommonStatus ()
297
- if status .Phase != string (aggregateStatus (statusMap )) {
298
- status .Phase = string (aggregateStatus (statusMap ))
299
- addonObject .SetCommonStatus (status )
300
- log .WithValues ("name" , addonObject .GetName ()).WithValues ("status" , status ).Info ("updating status" )
301
-
302
- err = r .client .Status ().Update (ctx , instance )
293
+ unstruct , unstructOk := instance .(* unstructured.Unstructured )
294
+ aggregatedStatus := string (aggregateStatus (statusMap ))
295
+ if ok {
296
+ addonStatus := addonObject .GetCommonStatus ()
297
+ if addonStatus .Phase != aggregatedStatus {
298
+ addonStatus .Phase = aggregatedStatus
299
+ 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
+ }
306
+ }
307
+ } else if unstructOk {
308
+ statusPhase , _ , err := unstructured .NestedString (unstruct .Object , "status" , "phase" )
303
309
if err != nil {
304
- log .Error (err , "error updating status" )
305
310
return reconcile.Result {}, err
306
311
}
312
+
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 )
320
+ if err != nil {
321
+ log .Error (err , "error updating status" )
322
+ return reconcile.Result {}, err
323
+ }
324
+ }
325
+ } else {
326
+ return reconcile.Result {}, fmt .Errorf ("instance %T was not an addonsv1alpha1.CommonObject or unstructured." +
327
+ "Unstructured" ,
328
+ instance )
307
329
}
308
330
309
331
if r .options .sink != nil {
@@ -312,7 +334,6 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
312
334
return reconcile.Result {}, err
313
335
}
314
336
}
315
-
316
337
return reconcile.Result {}, nil
317
338
}
318
339
0 commit comments