@@ -41,21 +41,27 @@ import (
4141// TODO: make a can-i check before emitting events to deployment target (e.g. in the client factory when creating the client)
4242// TODO: allow to override namespace auto-creation and adoption policy settings on a per-component level
4343// (e.g. through annotations or another interface that components could optionally implement)
44+ // TODO: allow some timeout feature, such that component will go into error state if not ready within the given timeout
45+ // (e.g. through a TimeoutConfiguration interface that components could optionally implement)
4446// TODO: run admission webhooks (if present) in reconcile (e.g. as post-read hook)
4547
4648const (
4749 readyConditionReasonNew = "FirstSeen"
48- readyConditionPending = "Pending"
50+ readyConditionReasonPending = "Pending"
4951 readyConditionReasonProcessing = "Processing"
5052 readyConditionReasonReady = "Ready"
5153 readyConditionReasonError = "Error"
54+ readyConditionReasonDeletionPending = "DeletionPending"
5255 readyConditionReasonDeletionBlocked = "DeletionBlocked"
5356 readyConditionReasonDeletionProcessing = "DeletionProcessing"
5457)
5558
59+ // TODO: should we pass cluster.Client to hooks instead of just client.Client?
60+
5661// HookFunc is the function signature that can be used to
5762// establish callbacks at certain points in the reconciliation logic.
58- // Hooks will be passed the current (potentially unsaved) state of the component.
63+ // Hooks will be passed a local client (to be precise, the one belonging to the owning
64+ // manager), and the current (potentially unsaved) state of the component.
5965// Post-hooks will only be called if the according operation (read, reconcile, delete)
6066// has been successful.
6167type HookFunc [T Component ] func (ctx context.Context , client client.Client , component T ) error
@@ -183,13 +189,20 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
183189 if retryAfter == nil || * retryAfter == 0 {
184190 retryAfter = & retryInterval
185191 }
186- status .SetState (StatePending , readyConditionPending , err .Error ())
192+ // TODO: allow RetriableError to provide custom reason and message
193+ if component .GetDeletionTimestamp ().IsZero () {
194+ status .SetState (StatePending , readyConditionReasonPending , capitalize (err .Error ()))
195+ } else {
196+ status .SetState (StateDeletionPending , readyConditionReasonDeletionPending , capitalize (err .Error ()))
197+ }
187198 result = ctrl.Result {RequeueAfter : * retryAfter }
188199 err = nil
189200 } else {
190201 status .SetState (StateError , readyConditionReasonError , err .Error ())
191202 }
192203 }
204+ // TODO: should we move this behind the DeepEqual check below?
205+ // TODO: follow-up on missing events
193206 state , reason , message := status .GetState ()
194207 if state == StateError {
195208 r .client .EventRecorder ().Event (component , corev1 .EventTypeWarning , reason , message )
@@ -284,11 +297,13 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
284297 return ctrl.Result {}, errors .Wrap (err , "error checking whether deletion is possible" )
285298 }
286299 log .V (1 ).Info ("deletion not allowed" )
300+ // TODO: have an additional StateDeletionBlocked?
287301 status .SetState (StateDeleting , readyConditionReasonDeletionBlocked , "Deletion blocked: " + msg )
288302 return ctrl.Result {RequeueAfter : 1 * time .Second + r .backoff .Next (req , readyConditionReasonDeletionBlocked )}, nil
289303 } else if len (slices .Remove (component .GetFinalizers (), r .name )) > 0 {
290304 // deletion is blocked because of foreign finalizers
291305 log .V (1 ).Info ("deleted blocked due to existence of foreign finalizers" )
306+ // TODO: have an additional StateDeletionBlocked?
292307 status .SetState (StateDeleting , readyConditionReasonDeletionBlocked , "Deletion blocked due to existing foreign finalizers" )
293308 return ctrl.Result {RequeueAfter : 1 * time .Second + r .backoff .Next (req , readyConditionReasonDeletionBlocked )}, nil
294309 } else {
0 commit comments