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

Add SharedInformer and SharedInformerFactory setDebugItems #3121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions util/src/main/java/io/kubernetes/client/util/Watch.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public Response(String type, V1Status status) {
}
}

Type watchType;
ResponseBody response;
JSON json;
Call call;
final Type watchType;
final String watchName;
final ResponseBody response;
final JSON json;
final Call call;

/**
* Creates a watch on a TYPENAME (T) using an API Client and a Call object.
Expand All @@ -92,6 +93,8 @@ public static <T> Watch<T> createWatch(ApiClient client, Call call, Type watchTy
throw new ApiException("Watch is incompatible with debugging mode active.");
}
try {
String watchName = call.request().url().encodedPath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to include the query parameters here since they can also modify the watch.

log.debug("creating watch {}", watchName);
okhttp3.Response response = call.execute();
if (!response.isSuccessful()) {
String respBody = null;
Expand All @@ -106,15 +109,16 @@ public static <T> Watch<T> createWatch(ApiClient client, Call call, Type watchTy
throw new ApiException(
response.message(), response.code(), response.headers().toMultimap(), respBody);
}
return new Watch<>(client.getJSON(), response.body(), watchType, call);
return new Watch<>(client.getJSON(), response.body(), watchType, watchName, call);
} catch (IOException e) {
throw new ApiException(e);
}
}

protected Watch(JSON json, ResponseBody body, Type watchType, Call call) {
protected Watch(JSON json, ResponseBody body, Type watchType, String watchName, Call call) {
this.response = body;
this.watchType = watchType;
this.watchName = watchName;
this.json = json;
this.call = call;
}
Expand All @@ -125,6 +129,7 @@ public Response<T> next() {
if (line == null) {
throw new RuntimeException("Null response from the server.");
}
log.debug("{} response line: {}", watchName, line);
return parseLine(line);
} catch (IOException e) {
throw new RuntimeException("IO Exception during next method.", e);
Expand Down Expand Up @@ -177,11 +182,16 @@ protected Response<T> parseLine(String line) throws IOException {
}

public boolean hasNext() {
boolean exhausted;
try {
return !response.source().exhausted();
exhausted = response.source().exhausted();
} catch (IOException e) {
throw new RuntimeException("IO Exception during hasNext method.", e);
}
if (exhausted) {
log.debug("{} response exhausted", watchName);
}
return !exhausted;
}

public Iterator<Response<T>> iterator() {
Expand All @@ -193,6 +203,7 @@ public void remove() {
}

public void close() throws IOException {
log.debug("{} closing", watchName);
this.call.cancel();
this.response.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testWatchEnd() throws IOException {
JSON json = new JSON();
Watch<V1ConfigMap> watch =
new Watch<V1ConfigMap>(
json, null, new TypeToken<Watch.Response<V1ConfigMap>>() {}.getType(), null);
json, null, new TypeToken<Watch.Response<V1ConfigMap>>() {}.getType(), null, null);
JsonObject metadata = new JsonObject();

JsonObject status = new JsonObject();
Expand Down