controller-runtime
controller-runtime copied to clipboard
Inconsistency between informer cache and etcd
I have a problem for my k8s controller.
My controller reconcile logic is:
- Get the CR
- If CR does not exist, print a log "not exist". Finish reconcile loop.
- If CR exists, update the CR state with a counter and print "CR updated". Reconcile again after 100ms with
RequeueAfter
. - If CR exists, and the CR is updated 100 times (check the CR state), delete the CR. Reconcile again after 100ms with
RequeueAfter
.
I start my reconcile with builder.WithPredicates(predicate.GenerationChangedPredicate{})
.
What happened,
- My reconcile loop deletes the CR.
- Then I manually create the CR again.
- My reconcile loop prints a log says "CR updated" only once.
- My reconcile loop prints "not exist".
How could that happen? Could this because when I update the CR state, it directly writes to etcd. But when I read the CR, it reads from informer cache?