Skip to content

Commit

Permalink
add blurb about how to wait for a certain state to FAQ (#5493)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Berkhahn <[email protected]>
  • Loading branch information
jberkhahn authored Jan 17, 2022
1 parent 43b5394 commit 6d21c1d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions website/content/en/docs/faqs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ For example, you should refrain from moving the scaffolded files, doing so will

You should not have separate logic. Instead design your reconciler to be idempotent. See the [controller-runtime FAQ][cr-faq] for more details.

## How do I wait for some specific cluster state such as a resource being deleted?

You don't. Instead, design your reconciler to be idempotent by taking the next step based on the current state, and then returning and requeuing. For example, waiting for an object to be deleted might look something like this:

```
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) {
...
if !r.IfPodWasDeleted(ctx, pod) {
if err := r.Delete(ctx, pod); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil
}
// This code will be invoked only after pod deletion
r.DeployBiggerPod(ctx)
...
}
```


## When my Custom Resource is deleted, I need to know its contents or perform cleanup tasks. How can I do that?

Use a [finalizer].
Expand Down

0 comments on commit 6d21c1d

Please sign in to comment.