Skip to content

Signal shutdown / failed startup #869

Answered by nolar
cpnielsen asked this question in Q&A
Discussion options

You must be logged in to vote

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):

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.o…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cpnielsen
Comment options

@nolar
Comment options

@cpnielsen
Comment options

Answer selected by cpnielsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants