Skip to content

Commit 36edb18

Browse files
committed
Reflector list should handle expired resource version from watch handler as well
1 parent f58be10 commit 36edb18

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
@@ -224,7 +224,11 @@ private void watchHandler(Watchable<ApiType> watch) {
224224
}
225225
if (eventType.get() == EventType.ERROR) {
226226
if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
227-
log.info("Watch connection expired: {}", item.status.getMessage());
227+
log.info(
228+
"ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time",
229+
getRelistResourceVersion(),
230+
item.status.getMessage());
231+
isLastSyncResourceVersionUnavailable = true;
228232
return;
229233
} else {
230234
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.never;
1819
import static org.mockito.Mockito.times;
@@ -255,4 +256,34 @@ public void testReflectorListShouldHandleExpiredResourceVersion() throws ApiExce
255256
reflectorRunnable.stop();
256257
}
257258
}
259+
260+
@Test
261+
public void testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler()
262+
throws ApiException {
263+
String expectedResourceVersion = "100";
264+
when(listerWatcher.list(any()))
265+
.thenReturn(
266+
new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));
267+
268+
V1Status v1Status = new V1Status();
269+
v1Status.setMessage("dummy-error-message");
270+
v1Status.setCode(410);
271+
when(listerWatcher.watch(any()))
272+
.thenReturn(new MockWatch<>(new Watch.Response("Error", v1Status)));
273+
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable =
274+
new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
275+
try {
276+
Thread thread = new Thread(reflectorRunnable::run);
277+
thread.setDaemon(true);
278+
thread.start();
279+
Awaitility.await()
280+
.atMost(Duration.ofSeconds(1))
281+
.pollInterval(Duration.ofMillis(100))
282+
.until(
283+
() -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
284+
assertTrue(reflectorRunnable.isLastSyncResourceVersionUnavailable());
285+
} finally {
286+
reflectorRunnable.stop();
287+
}
288+
}
258289
}

0 commit comments

Comments
 (0)