Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error messages in the watcher #150

Merged
merged 3 commits into from
Apr 28, 2018
Merged

Handle error messages in the watcher #150

merged 3 commits into from
Apr 28, 2018

Conversation

qmfrederik
Copy link
Contributor

The Watcher currently always expects WatchEvent<T> messages to be sent by the server (e.g. WatchEvent<V1Pod>).

That's not always the case, the server may also respond with a WatchEvent<V1Status> message in case an error occured. For example, if the resourceVersion set in the watch request is outdated, you may get a HTTP 200 response with a single Error event - see kubernetes/kubernetes#25369.

This PR makes the watcher handle that scenario a bit better:

  • It introduces a generic KubernetesObject class which you can use to parse any JSON object returned by the Kubernetes API server. It exposes the ApiVersion and Kind properties which help you determine what object type is actually being returned.
  • It introduces a KubernetesException object which wraps an V1Status message. That's useful because the Watcher currently uses Exception objects to relay errors.
  • Updates the Watcher class to parse the JSON as a KubernetesObject, and decide whether it's an error message or not, and handle things properly from there.
  • Makes the constructor for the Watcher public. This helps with unit testing & will also help others when mocking, extending,...

A unit test is included.

@brendandburns
Copy link
Contributor

LGTM, awesome!

@brendandburns brendandburns merged commit 29a9c22 into kubernetes-client:master Apr 28, 2018
JonJam pushed a commit to JonJam/csharp that referenced this pull request Sep 8, 2018
* Handle error messages in the watcher

* Fix documentation

* Fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants