Handle error messages in the watcher #150
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
Watcher
currently always expectsWatchEvent<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 aHTTP 200
response with a single Error event - see kubernetes/kubernetes#25369.This PR makes the watcher handle that scenario a bit better:
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.KubernetesException
object which wraps anV1Status
message. That's useful because the Watcher currently usesException
objects to relay errors.Watcher
class to parse the JSON as aKubernetesObject
, and decide whether it's an error message or not, and handle things properly from there.Watcher
public. This helps with unit testing & will also help others when mocking, extending,...A unit test is included.