Reputation: 405
I have an operator listening for CRs. I am using observedGeneration
in status to check whether a reconciled event should be considered for processing or not.
The operator just ignores the reconcile event if the metadata.generation == status.observedGenration
. It works fine when the operator reconciles events.
But when the operator restarts, I need to process all the existing CRs even if its metadata.generation == status.observedGenration
because the operator needs to store an up-to-date state of the CR in memory.
Is there a best practice to solve this problem instead of keeping a local cache about the processed CR details?
Upvotes: 0
Views: 325
Reputation: 1673
You need to handle operator state, I recommend you to externalize the storage of the state of the operator to preserve this state between restarts.
Storage options goes from ConfigMap, or Volumes to databases or distributed cache, it depends on your requirements.
Then you can use a finalizer
/ lifecycle event onShutdown
/container lifecycle event preStop
, to update the operator state in that external storage, to indicate the operator was restarted, for example.
Upvotes: 0