kubernetes_asyncio icon indicating copy to clipboard operation
kubernetes_asyncio copied to clipboard

dynamic.DynamicClient

Open devlounge opened this issue 3 years ago • 1 comments

Any plan to have dynamic.DynamicClient ?

devlounge avatar Jun 15 '22 15:06 devlounge

Yes, it's on my TODO list.

tomplus avatar Jun 16 '22 22:06 tomplus

@tomplus if this can be a port of the existing code in the sync client I'd be glad to work on it.

bobh66 avatar May 02 '23 12:05 bobh66

@bobh66 Thanks! You can port code from the sync client and make it asynchronous. Let me know if you have any questions.

tomplus avatar May 02 '23 14:05 tomplus

I think the main question is how to handle the async initialization requirements of the Discoverer and DynamicClient classes? They both need to do async operations on class creation, so some sort of factory method is needed, like:

class Discoverer:
    ......
    async def _ainit(self):
        await self.__init_cache()

    @classmethod
    async def create(cls, client, cache_file=None):
        self = cls(client=client, cache_file=cache_file)
        await self._ainit()
        return self

and then the class creation becomes:

self.__discoverer = discoverer.create(self, self.cache_file)

Is there a better pattern or is this an acceptable API for the classes?

Thanks

bobh66 avatar May 02 '23 15:05 bobh66

I like your solution, you can implemented it in this way :+1:

tomplus avatar May 02 '23 15:05 tomplus

I was able to come up with a better solution using the __await__ magic method so that the DynamicClient and Discoverer objects can be await'ed directly and a separate create method is not needed.

These changes are ready to be pushed I'm just waiting on some process overhead from my employer and then I'll create a PR.

bobh66 avatar May 16 '23 16:05 bobh66

@bobh66 Thanks for this! Looking forward to using it.

asteven avatar Jun 26 '23 10:06 asteven