Skip to content

Commit 1f9413d

Browse files
committed
Reflector list should handle expired resource version from watch handler as well
1 parent f413347 commit 1f9413d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ private void watchHandler(Watchable<ApiType> watch) {
237237
}
238238
if (eventType.get() == EventType.ERROR) {
239239
if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
240-
log.info("Watch connection expired: {}", item.status.getMessage());
240+
log.info(
241+
"ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time",
242+
getRelistResourceVersion(),
243+
item.status.getMessage());
244+
isLastSyncResourceVersionUnavailable = true;
241245
throw new WatchExpiredException();
242246
} else {
243247
String errorMessage =

util/src/test/java/io/kubernetes/client/informer/cache/ReflectorRunnableTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package io.kubernetes.client.informer.cache;
1414

1515
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertTrue;
1617
import static org.mockito.Mockito.any;
1718
import static org.mockito.Mockito.mock;
1819
import static org.mockito.Mockito.never;
@@ -312,4 +313,34 @@ public void testReflectorWatchShouldRelistUponExpiredWatchItem() throws ApiExcep
312313
.until(() -> future.isDone());
313314
assertFalse(future.isCompletedExceptionally());
314315
}
316+
317+
@Test
318+
public void testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler()
319+
throws ApiException {
320+
String expectedResourceVersion = "100";
321+
when(listerWatcher.list(any()))
322+
.thenReturn(
323+
new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));
324+
325+
V1Status v1Status = new V1Status();
326+
v1Status.setMessage("dummy-error-message");
327+
v1Status.setCode(410);
328+
when(listerWatcher.watch(any()))
329+
.thenReturn(new MockWatch<>(new Watch.Response("Error", v1Status)));
330+
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable =
331+
new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
332+
try {
333+
Thread thread = new Thread(reflectorRunnable::run);
334+
thread.setDaemon(true);
335+
thread.start();
336+
Awaitility.await()
337+
.atMost(Duration.ofSeconds(1))
338+
.pollInterval(Duration.ofMillis(100))
339+
.until(
340+
() -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
341+
assertTrue(reflectorRunnable.isLastSyncResourceVersionUnavailable());
342+
} finally {
343+
reflectorRunnable.stop();
344+
}
345+
}
315346
}

0 commit comments

Comments
 (0)