How to deal with stores being empty at creation #1124
Replies: 1 comment 1 reply
-
So this is going to depend on your use-case, yeah... For the simple use-case of "one store for the main resource being reconciled" then this doesn't matter, since the controller will populate the store before calling into your reconciler. For 1:1 relations to secondary types it might also be ok (assuming that the secondary object is mandatory for reconciliation), since the reconciler will be called again when the secondary object is discovered (assuming correctly configured watches). Where it becomes troublesome is 1:n and 1:(0-1) relationships, since this means that I ended up writing a helper type for this (https://github.com/stackabletech/commons-operator/blob/6a398e08e80b4810e289162fe555fa3945d6eeb1/rust/operator-binary/src/utils/delayed_init.rs), but it's definitely pretty ugly. There are a few options here.. we could allow users to detect the condition by changing |
Beta Was this translation helpful? Give feedback.
-
When we first started using stores we encountered a bug because there can be a race condition if you just create one and give it to a Controller. If the Controller reconciles before the Store has received its first event then the Store will be empty; which can cause incorrect behaviour in your reconciliation. To solve this we've created an async wrapper function around creating a store that waits for the first event before returning the store.
Is there a better / more idiomatic KubeRS way of solving this?
Beta Was this translation helpful? Give feedback.
All reactions