kopf icon indicating copy to clipboard operation
kopf copied to clipboard

Pass a context to every kopf call/handler

Open krish7919 opened this issue 4 years ago • 4 comments

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 avatar Apr 12 '20 12:04 krish7919

@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?

nolar avatar Apr 15 '20 21:04 nolar

Precisely. In Go, this is the context, or a struct with the values required.

krish7919 avatar Apr 15 '20 21:04 krish7919

This is something that's interesting for our usage too, especially when we're constantly trying to connect to the Kuberentes API..

mnaser avatar Apr 17 '20 21:04 mnaser

This issue also may be related to my question in #367

eshepelyuk avatar May 17 '20 03:05 eshepelyuk