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

When watch can't parse an object, try to parse it to a Status. #165

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion util/src/main/java/io/kubernetes/client/util/Watch.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
*/
package io.kubernetes.client.util;

import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.ResponseBody;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.JSON;

import io.kubernetes.client.models.V1Status;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Iterator;
Expand Down Expand Up @@ -46,9 +49,18 @@ public static class Response<T> {
@SerializedName("object")
public T object;

public V1Status status;

Response(String type, T object) {
this.type = type;
this.object = object;
this.status = null;
}

Response(String type, V1Status status) {
this.type = type;
this.object = null;
this.status = status;
}
}

Expand Down Expand Up @@ -99,7 +111,13 @@ public Response<T> next() {
if (line == null) {
throw new RuntimeException("Null response from the server.");
}
return json.deserialize(line, watchType);
try {
return json.deserialize(line, watchType);
} catch (JsonParseException ex) {
Type statusType = new TypeToken<Response<V1Status>>(){}.getType();
Response<V1Status> status = json.deserialize(line, statusType);
return new Response<T>(status.type, status.object);
}
} catch (IOException e) {
throw new RuntimeException("IO Exception during next method.", e);
}
Expand Down