Skip to content

Commit b893977

Browse files
author
Mor Cohen
committed
Modify existing listener
1 parent b8da99e commit b893977

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/retention/Reaper.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ public void onEvent(@NonNull Action action, @NonNull KubernetesSlave node, @NonN
240240
LOGGER.info(() -> ns + "/" + name + " Container " + c.getName() + " was just terminated, so removing the corresponding Jenkins agent");
241241
runListener.getLogger().printf("%s/%s Container %s was terminated (Exit Code: %d, Reason: %s)%n", ns, name, c.getName(), t.getExitCode(), t.getReason());
242242
});
243+
try (ACLContext _ = ACL.as(ACL.SYSTEM)) {
244+
PodUtils.cancelQueueItemFor(pod, "ContainerError");
245+
}
243246
logLastLinesThenTerminateNode(node, pod, runListener);
244247
}
245248
}
@@ -298,27 +301,4 @@ public void onEvent(@NonNull Action action, @NonNull KubernetesSlave node, @NonN
298301
node.terminate();
299302
}
300303
}
301-
302-
@Extension
303-
public static class TerminateAgentOnCreateContainerError implements Listener {
304-
305-
@Override
306-
public void onEvent(@NonNull Action action, @NonNull KubernetesSlave node, @NonNull Pod pod) throws IOException, InterruptedException {
307-
List<ContainerStatus> backOffContainers = PodUtils.getContainers(pod, cs -> {
308-
ContainerStateWaiting waiting = cs.getState().getWaiting();
309-
return waiting != null && waiting.getMessage() != null && waiting.getMessage().contains("container create failed");
310-
});
311-
if (backOffContainers.isEmpty()) {
312-
return;
313-
}
314-
backOffContainers.forEach(cs -> {
315-
TaskListener runListener = node.getTemplate().getListener();
316-
runListener.error("Container creation error \""+cs.getName()+"\". Please check container's logs.");
317-
});
318-
try (ACLContext _ = ACL.as(ACL.SYSTEM)) {
319-
PodUtils.cancelQueueItemFor(pod, "CreateContainerError");
320-
}
321-
node.terminate();
322-
}
323-
}
324304
}

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void declarativeWithNonexistentDockerImage() throws Exception {
183183
public void declarativeWithCreateContainerError() throws Exception {
184184
assertNotNull(createJobThenScheduleRun());
185185
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
186-
r.assertLogContains("ERROR: Container creation error", b);
186+
r.assertLogContains("was terminated", b);
187187
}
188188

189189
@Issue("JENKINS-61360")

0 commit comments

Comments
 (0)