openshift/openshift-restclient-python

Client init fails if one of apis is unavailable

dbazhal opened this issue · 5 comments

Hi!
I've faced issue with client init. There are number of custom apis(ApiService resources) in my cluster, like, for example, /apis/metrics.k8s.io/v1beta1. It appeared that not all of apis might work all the time, some apis might stop answering. I'm not sure if that is ok situation, but if such minor api fails, I'd like my cluster's core functionality(running containers, making changes to deployments, etc) continued working.
This discovery code https://github.com/openshift/openshift-restclient-python/blob/master/openshift/dynamic/discovery.py#L108 is pretty good now, but it fails openshift python client in case of one failed minor api(logic "full api discovery failed == client init failed").
Unfortunately I'm not proposing PR to fix that, but I suggest to change that behavior to "some apis discovery failed == continue working and fail if user requested api that is not discovered").

What version of the client are you using? Any version >= 0.9.x should be using the LazyDiscoverer by default, which should only attempt discovery on a group if a resource in that group is actively accessed.

It's 0.8. As I understand, when I make

client.resources.get('my.apigroup.tld')

It's time to discover all the apigroups. Am I wrong?

I mean, inside this loop https://github.com/openshift/openshift-restclient-python/blob/master/openshift/dynamic/discovery.py#L116 it makes this https://github.com/openshift/openshift-restclient-python/blob/master/openshift/dynamic/discovery.py#L120 request to all of the discovered apis, and if any of them is not working, I can't work with openshift dynamic client.

It's 0.8. As I understand, when I make

client.resources.get('my.apigroup.tld')

It's time to discover all the apigroups. Am I wrong?

In 0.8.x it will actually happen when you instantiate the client, on 0.9.x+ by default it will only load the resources for the specific api group you are attempting to access. If possible I'd recommend moving to 0.9.x so you can use the lazy discovery, which is superior for a number of reasons, but if that's not an option this patch shouldn't be hard to get in

Oh, ok, thank you, I'll try 0.9 :)