@@ -355,10 +355,57 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
355355 }
356356 }
357357
358- // TODO: it seems that no events will be written if the component's namespace is in deletion
359358 // TODO: do not use GetState(); but accessing the condition directly is not safe (see caveat remark on the
360359 // getCondition() and getOrAddCondition() methods)
361360 state , reason , message := status .GetState ()
361+
362+ if component .GetDeletionTimestamp ().IsZero () || controllerutil .ContainsFinalizer (component , * r .options .Finalizer ) {
363+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
364+ component .GetNamespace (), component .GetName (), string (StateReady )).
365+ Set (float64 (boolToInt (state == StateReady )))
366+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
367+ component .GetNamespace (), component .GetName (), string (StatePending )).
368+ Set (float64 (boolToInt (state == StatePending )))
369+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
370+ component .GetNamespace (), component .GetName (), string (StateProcessing )).
371+ Set (float64 (boolToInt (state == StateProcessing )))
372+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
373+ component .GetNamespace (), component .GetName (), string (StateDeletionPending )).
374+ Set (float64 (boolToInt (state == StateDeletionPending )))
375+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
376+ component .GetNamespace (), component .GetName (), string (StateDeleting )).
377+ Set (float64 (boolToInt (state == StateDeleting )))
378+ metrics .ComponentState .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
379+ component .GetNamespace (), component .GetName (), string (StateError )).
380+ Set (float64 (boolToInt (state == StateError )))
381+ metrics .Dependents .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
382+ component .GetNamespace (), component .GetName ()).
383+ Set (float64 (len (status .Inventory )))
384+ metrics .UnreadyDependents .WithLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
385+ component .GetNamespace (), component .GetName ()).
386+ Set (float64 (slices .Count (status .Inventory , func (item * reconciler.InventoryItem ) bool {
387+ return item .Phase != reconciler .PhaseReady && item .Phase != reconciler .PhaseCompleted
388+ })))
389+ } else {
390+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
391+ component .GetNamespace (), component .GetName (), string (StateReady ))
392+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
393+ component .GetNamespace (), component .GetName (), string (StatePending ))
394+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
395+ component .GetNamespace (), component .GetName (), string (StateProcessing ))
396+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
397+ component .GetNamespace (), component .GetName (), string (StateDeletionPending ))
398+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
399+ component .GetNamespace (), component .GetName (), string (StateDeleting ))
400+ metrics .ComponentState .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
401+ component .GetNamespace (), component .GetName (), string (StateError ))
402+ metrics .Dependents .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
403+ component .GetNamespace (), component .GetName ())
404+ metrics .UnreadyDependents .DeleteLabelValues (r .controllerName , component .GetObjectKind ().GroupVersionKind ().Group , component .GetObjectKind ().GroupVersionKind ().Kind ,
405+ component .GetNamespace (), component .GetName ())
406+ }
407+
408+ // TODO: it seems that no events will be written if the component's namespace is in deletion
362409 var eventAnnotations map [string ]string
363410 // TODO: formalize this into a real published interface
364411 // TODO: pass previousState, and especially componentDigest in a better way;
0 commit comments