-
Hi 👋 I am working an a kopf operator, and want to load some configuration before the operator starts. Looking at the documentation, I assume that However, in my case there are situations where I do not want to continue loading - ie. some configuration is missing, malformed, etc. or the startup cannot complete for other reasons (no connectivity to a database, etc.). I tried throwing an exception from the startup function, but that just causes the method to be retried indefinitely. My questions are:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello. Technically, there is no way to stop the operator from inside. But there is a way to stop it from outside, which you can extend to the insides. You need to abandon the import asyncio
import threading
import kopf
@kopf.on.create('kopfexamples')
def create_kex(memo, name, **_):
if name == 'stop-me':
memo.my_stop_flag.set()
def main():
kopf.configure(verbose=True, log_prefix=True) # purely for logging
# either threading.Event(), or asyncio.Event(), or asyncio/concurrent Future().
memo = kopf.Memo(my_stop_flag=threading.Event())
asyncio.run(kopf.operator(memo=memo, stop_flag=memo.my_stop_flag, ...))
if __name__ == '__main__':
main()
Don't worry, there is not much which PS: Oops. The PPS: Just for some extra clarity: |
Beta Was this translation helpful? Give feedback.
Hello. Technically, there is no way to stop the operator from inside. But there is a way to stop it from outside, which you can extend to the insides.
You need to abandon the
kop run
CLI and make your own CLI with an embedded operator, combined with the in-memory container (memo):