Skip to content

Commit f1bcfab

Browse files
authored
Merge pull request #962 from yue9944882/defensive-reconciler-execution
Catches runtime-exception upon executing reconciler
2 parents 8bf8727 + 4bce518 commit f1bcfab

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

extended/src/main/java/io/kubernetes/client/extended/controller/DefaultController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ private void worker() {
151151
log.debug("Controller {} start reconciling {}..", this.name, request);
152152

153153
// do reconciliation, invoke user customized logic.
154-
Result result = this.reconciler.reconcile(request);
154+
Result result = null;
155+
try {
156+
result = this.reconciler.reconcile(request);
157+
} catch (Throwable t) {
158+
log.error("Reconciler aborted unexpectedly", t);
159+
result = new Result(true);
160+
}
155161

156162
try {
157163
// checks whether do a re-queue (on failure)

extended/src/test/java/io/kubernetes/client/extended/controller/DefaultControllerTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void testControllerWontStartBeforeReady() throws InterruptedException {
103103
}
104104

105105
@Test
106-
public void testControllerStopsWorkingWhenReconcilerAbortsWithRuntimeException()
106+
public void testControllerKeepsWorkingWhenReconcilerAbortsWithRuntimeException()
107107
throws InterruptedException {
108108
AtomicBoolean aborts = new AtomicBoolean(true);
109109
AtomicBoolean resumed = new AtomicBoolean(false);
@@ -135,9 +135,10 @@ public Result reconcile(Request request) {
135135
// emit another event, the previous one has been backoff'd
136136
Request request2 = new Request("test2");
137137
workQueue.add(request2);
138+
cooldown();
138139
testController.shutdown();
139140

140-
assertFalse(resumed.get());
141-
assertEquals(0, finishedRequests.size());
141+
assertTrue(resumed.get());
142+
assertTrue(finishedRequests.size() >= 1);
142143
}
143144
}

0 commit comments

Comments
 (0)