Skip to content

Commit 6d21c1d

Browse files
authored
add blurb about how to wait for a certain state to FAQ (#5493)
Signed-off-by: Jonathan Berkhahn <[email protected]>
1 parent 43b5394 commit 6d21c1d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

website/content/en/docs/faqs/_index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ For example, you should refrain from moving the scaffolded files, doing so will
3636

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

39+
## How do I wait for some specific cluster state such as a resource being deleted?
40+
41+
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:
42+
43+
```
44+
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) {
45+
...
46+
if !r.IfPodWasDeleted(ctx, pod) {
47+
if err := r.Delete(ctx, pod); err != nil {
48+
return ctrl.Result{}, err
49+
}
50+
return ctrl.Result{Requeue: true}, nil
51+
}
52+
// This code will be invoked only after pod deletion
53+
r.DeployBiggerPod(ctx)
54+
...
55+
}
56+
```
57+
58+
3959
## When my Custom Resource is deleted, I need to know its contents or perform cleanup tasks. How can I do that?
4060

4161
Use a [finalizer].

0 commit comments

Comments
 (0)