Skip to content

Commit 24e1513

Browse files
committed
bugfix: properly handling non-410 ApiExcetion in the reflector
1 parent bfcaea2 commit 24e1513

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public void run() {
160160
"ResourceVersion {} expired, will retry w/o resourceVersion at the next time",
161161
getRelistResourceVersion());
162162
isLastSyncResourceVersionUnavailable = true;
163+
} else {
164+
this.exceptionHandler.accept(apiTypeClass, e);
163165
}
164166
} catch (Throwable t) {
165167
this.exceptionHandler.accept(apiTypeClass, t);

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public Watchable<V1Pod> watch(CallGeneratorParams params) throws ApiException {
116116
}
117117

118118
@Test
119-
public void testReflectorRunnableCaptureListException() throws ApiException {
119+
public void testReflectorRunnableCaptureListRuntimeException() throws ApiException {
120120
RuntimeException expectedException = new RuntimeException("noxu");
121121
AtomicReference<Throwable> actualException = new AtomicReference<>();
122122
when(listerWatcher.list(any())).thenThrow(expectedException);
@@ -141,6 +141,61 @@ public void testReflectorRunnableCaptureListException() throws ApiException {
141141
}
142142
}
143143

144+
@Test
145+
public void testReflectorRunnableShouldPardonList410ApiException() throws ApiException {
146+
ApiException expectedException = new ApiException(410, "noxu");
147+
AtomicReference<Throwable> actualException = new AtomicReference<>();
148+
when(listerWatcher.list(any())).thenThrow(expectedException);
149+
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable =
150+
new ReflectorRunnable<>(
151+
V1Pod.class,
152+
listerWatcher,
153+
deltaFIFO,
154+
(apiType, t) -> {
155+
actualException.set(t);
156+
});
157+
try {
158+
Thread thread = new Thread(reflectorRunnable::run);
159+
thread.setDaemon(true);
160+
thread.start();
161+
Awaitility.await()
162+
.atMost(Duration.ofSeconds(1))
163+
.pollInterval(Duration.ofMillis(100))
164+
.until(
165+
() -> {
166+
return reflectorRunnable.isLastSyncResourceVersionUnavailable();
167+
});
168+
} finally {
169+
reflectorRunnable.stop();
170+
}
171+
}
172+
173+
@Test
174+
public void testReflectorRunnableShouldCaptureListNon410ApiException() throws ApiException {
175+
ApiException expectedException = new ApiException(403, "noxu");
176+
AtomicReference<Throwable> actualException = new AtomicReference<>();
177+
when(listerWatcher.list(any())).thenThrow(expectedException);
178+
ReflectorRunnable<V1Pod, V1PodList> reflectorRunnable =
179+
new ReflectorRunnable<>(
180+
V1Pod.class,
181+
listerWatcher,
182+
deltaFIFO,
183+
(apiType, t) -> {
184+
actualException.set(t);
185+
});
186+
try {
187+
Thread thread = new Thread(reflectorRunnable::run);
188+
thread.setDaemon(true);
189+
thread.start();
190+
Awaitility.await()
191+
.atMost(Duration.ofSeconds(1))
192+
.pollInterval(Duration.ofMillis(100))
193+
.untilAtomic(actualException, new IsEqual<>(expectedException));
194+
} finally {
195+
reflectorRunnable.stop();
196+
}
197+
}
198+
144199
@Test
145200
public void testReflectorRunnableCaptureWatchException() throws ApiException {
146201
RuntimeException expectedException = new RuntimeException("noxu");

0 commit comments

Comments
 (0)