kazan icon indicating copy to clipboard operation
kazan copied to clipboard

handling Kubernetes Errors

Open lswith opened this issue 7 years ago • 5 comments

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

lswith avatar Sep 18 '18 23:09 lswith

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...

obmarg avatar Sep 22 '18 20:09 obmarg

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 avatar Sep 24 '18 00:09 lswith

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

lswith avatar Sep 24 '18 00:09 lswith

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...

obmarg avatar Sep 24 '18 13:09 obmarg

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

lswith avatar Sep 29 '18 00:09 lswith