kubernetes_asyncio
kubernetes_asyncio copied to clipboard
Generic client
Is there any way of using a generic client with kubernetes_asyncio? Similar to for example what kubernetes federated v2 have in their client code?
https://github.com/kubernetes-sigs/federation-v2/blob/9c6ce26ea02d103572b69aa09acd1d51ffe29447/pkg/kubefed2/enable/enable.go#L243
https://github.com/kubernetes-sigs/federation-v2/blob/master/pkg/client/generic/genericclient.go
https://github.com/kubernetes-sigs/federation-v2/blob/master/pkg/apis/core/v1alpha1/federatedtypeconfig_types.go
If you have any example I would be grateful. Could I just do something similar to how generated code use the api_client.call_api?
You can use the api_client.call_api but some work have to be done to prepare a request. Please take a look at the function for example "create_deployment": https://github.com/tomplus/kubernetes_asyncio/blob/5e927afb4941e35590b80032637163f2f3cc9ac0/kubernetes_asyncio/client/api/apps_v1_api.py#L377
Another option can be generating functions and models (client/api/*
, client/models/*
) from spec by openapi-generator, but using api_client from this library. You will get new APIs but the client will remain the same. I see that the federation APIs v1 has a swagger definition. How does it look?
I managed to create a method to call the call_api, by looking at one of the others. I think I have to use the argument _preload_content = False
since otherwise it will fail due to no model exist, but that is a minor issue doing the json load in my wrapping function instead.
I have not found any swagger for federation v2, I guess it is due to being so new and still in alpha.
The latest version of the library contains the Generic Client which can address your needs. Please take a look: https://github.com/tomplus/kubernetes_asyncio/tree/master/examples/dynamic-client I'm closing the issue, fill free to reopen if necessary. Thanks.