kopf
kopf copied to clipboard
Pass a context to every kopf call/handler
Question
I would like to embed kopf in an application to perform some extra cluster functions as a response to events.
I can always use a global variable. Actually, I have to go the embedding way as I want to build wrappers to take some custom arguments as input, validate them, form connection strings, and then start the kopf asyncio loop. Plus I have to pass these params around as every handler would need them.
This should be a pretty common ask, and I am not sure how is that done currently.
Checklist
-
[x] I have read the documentation and searched there for the problem
-
[x] I have searched in the GitHub Issues for similar questions
Keywords
"kopf pass context to handlers" on Google and in docs.
@krish7919 Just to clarify: do you mean an arbitrary object of arbitrary class, which is passed through the call stack from the owning application down to the handlers (all of them), right? Something like a memo
kwarg (per-resource container for arbitrary keys/fields), but global and of external origin?
Precisely. In Go, this is the context
, or a struct
with the values required.
This is something that's interesting for our usage too, especially when we're constantly trying to connect to the Kuberentes API..
This issue also may be related to my question in #367