obmarg / kazan

Kubernetes API client for Elixir
https://hex.pm/packages/kazan
MIT License
140 stars 35 forks source link

handling Kubernetes Errors #51

Open lswith opened 6 years ago

lswith commented 6 years ago

The StatusError that is returned when a call from kubernetes doesn't succeed would be useful.

Currently its just being decoded https://github.com/obmarg/kazan/blob/master/lib/kazan/client/imp.ex#L160

obmarg commented 6 years ago

Hello again @lswith - is there a specific use case that you've got where a decoded map isn't good enough?

I guess the main problem with errors from k8s is that the swagger spec doesn't give us any details on them. It'd be possible for me to write a struct manually and decode into that, but I'd need to pay attention to the k8s code to make sure that we didn't get out of sync in the future...

lswith commented 6 years ago

So with regards to the struct, it's actually a generic Status https://github.com/kubernetes/apimachinery/blob/master/pkg/api/errors/errors.go#L40

Here is the main use case: To determine if a job exists, I need to look the job up. There are 2 possibilities: Get all jobs and iterate through them myself or ask kubernetes for the job and parse the error that is returned. The NotFound error is extremely useful and has many use cases such as the one above.

I do understand though that this library is swagger -> Elixir codegen so it might be hard to implement. It might be worth doing though simply because if its not in the library, it'll have to be implemented by your users. Your users will also be syncing with k8s as well, but now it's custom and everyone will have to do it.

lswith commented 6 years ago

I'm going to try and find out why k8s hasn't implemented their errors into the OpenAPI.

obmarg commented 6 years ago

Looking into this a tiny bit more, it seems like the StatusError contains a metaStatus, which is actually in the kube specs, and the kazan struct is here so it might be possible for kazan to parse one of these out on error...

lswith commented 6 years ago

If your curious, I’ve opened a ticket on the kubernetes api machinery to have these errors in the OpenAPI spec:

https://github.com/kubernetes/kubernetes/issues/69014