From 24e1513943ea39a582a91cecf4c5ec586d670925 Mon Sep 17 00:00:00 2001 From: yue9944882 <291271447@qq.com> Date: Tue, 30 Mar 2021 17:42:15 +0800 Subject: [PATCH] bugfix: properly handling non-410 ApiExcetion in the reflector --- .../informer/cache/ReflectorRunnable.java | 2 + .../informer/cache/ReflectorRunnableTest.java | 57 ++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java b/util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java index 7fc167bdaa..3df432275b 100644 --- a/util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java +++ b/util/src/main/java/io/kubernetes/client/informer/cache/ReflectorRunnable.java @@ -160,6 +160,8 @@ public void run() { "ResourceVersion {} expired, will retry w/o resourceVersion at the next time", getRelistResourceVersion()); isLastSyncResourceVersionUnavailable = true; + } else { + this.exceptionHandler.accept(apiTypeClass, e); } } catch (Throwable t) { this.exceptionHandler.accept(apiTypeClass, t); diff --git a/util/src/test/java/io/kubernetes/client/informer/cache/ReflectorRunnableTest.java b/util/src/test/java/io/kubernetes/client/informer/cache/ReflectorRunnableTest.java index 7c5750396d..7d18e92acb 100644 --- a/util/src/test/java/io/kubernetes/client/informer/cache/ReflectorRunnableTest.java +++ b/util/src/test/java/io/kubernetes/client/informer/cache/ReflectorRunnableTest.java @@ -116,7 +116,7 @@ public Watchable watch(CallGeneratorParams params) throws ApiException { } @Test - public void testReflectorRunnableCaptureListException() throws ApiException { + public void testReflectorRunnableCaptureListRuntimeException() throws ApiException { RuntimeException expectedException = new RuntimeException("noxu"); AtomicReference actualException = new AtomicReference<>(); when(listerWatcher.list(any())).thenThrow(expectedException); @@ -141,6 +141,61 @@ public void testReflectorRunnableCaptureListException() throws ApiException { } } + @Test + public void testReflectorRunnableShouldPardonList410ApiException() throws ApiException { + ApiException expectedException = new ApiException(410, "noxu"); + AtomicReference actualException = new AtomicReference<>(); + when(listerWatcher.list(any())).thenThrow(expectedException); + ReflectorRunnable reflectorRunnable = + new ReflectorRunnable<>( + V1Pod.class, + listerWatcher, + deltaFIFO, + (apiType, t) -> { + actualException.set(t); + }); + try { + Thread thread = new Thread(reflectorRunnable::run); + thread.setDaemon(true); + thread.start(); + Awaitility.await() + .atMost(Duration.ofSeconds(1)) + .pollInterval(Duration.ofMillis(100)) + .until( + () -> { + return reflectorRunnable.isLastSyncResourceVersionUnavailable(); + }); + } finally { + reflectorRunnable.stop(); + } + } + + @Test + public void testReflectorRunnableShouldCaptureListNon410ApiException() throws ApiException { + ApiException expectedException = new ApiException(403, "noxu"); + AtomicReference actualException = new AtomicReference<>(); + when(listerWatcher.list(any())).thenThrow(expectedException); + ReflectorRunnable reflectorRunnable = + new ReflectorRunnable<>( + V1Pod.class, + listerWatcher, + deltaFIFO, + (apiType, t) -> { + actualException.set(t); + }); + try { + Thread thread = new Thread(reflectorRunnable::run); + thread.setDaemon(true); + thread.start(); + Awaitility.await() + .atMost(Duration.ofSeconds(1)) + .pollInterval(Duration.ofMillis(100)) + .untilAtomic(actualException, new IsEqual<>(expectedException)); + } finally { + reflectorRunnable.stop(); + } + } + @Test public void testReflectorRunnableCaptureWatchException() throws ApiException { RuntimeException expectedException = new RuntimeException("noxu");