Skip to content

Commit dd061ba

Browse files
author
Mor Cohen
committed
Add TerminateAgentOnCreateContainerError
Signed-off-by: Mor Cohen <[email protected]>
1 parent 6103d89 commit dd061ba

File tree

1 file changed

+23
-0
lines changed
  • src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/retention

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,27 @@ public void onEvent(@NonNull Action action, @NonNull KubernetesSlave node, @NonN
298298
node.terminate();
299299
}
300300
}
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+
}
301324
}

0 commit comments

Comments
 (0)