Skip to content

Reflector list should handle expired resource version from watch handler as well #1927

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

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ private void watchHandler(Watchable<ApiType> watch) {
}
if (eventType.get() == EventType.ERROR) {
if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
log.info("Watch connection expired: {}", item.status.getMessage());
log.info(
"ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time",
getRelistResourceVersion(),
item.status.getMessage());
isLastSyncResourceVersionUnavailable = true;
throw new WatchExpiredException();
} else {
String errorMessage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package io.kubernetes.client.informer.cache;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -312,4 +313,34 @@ public void testReflectorWatchShouldRelistUponExpiredWatchItem() throws ApiExcep
.until(() -> future.isDone());
assertFalse(future.isCompletedExceptionally());
}

@Test
public void testReflectorListShouldHandleExpiredResourceVersionFromWatchHandler()
throws ApiException {
String expectedResourceVersion = "100";
when(listerWatcher.list(any()))
.thenReturn(
new V1PodList().metadata(new V1ListMeta().resourceVersion(expectedResourceVersion)));

V1Status v1Status = new V1Status();
v1Status.setMessage("dummy-error-message");
v1Status.setCode(410);
when(listerWatcher.watch(any()))
.thenReturn(new MockWatch<>(new Watch.Response("Error", v1Status)));
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable =
new ReflectorRunnable<>(V1Pod.class, listerWatcher, deltaFIFO);
try {
Thread thread = new Thread(reflectorRunnable::run);
thread.setDaemon(true);
thread.start();
Awaitility.await()
.atMost(Duration.ofSeconds(1))
.pollInterval(Duration.ofMillis(100))
.until(
() -> expectedResourceVersion.equals(reflectorRunnable.getLastSyncResourceVersion()));
assertTrue(reflectorRunnable.isLastSyncResourceVersionUnavailable());
} finally {
reflectorRunnable.stop();
}
}
}