Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.csanchez.jenkins.plugins.kubernetes;

import io.fabric8.kubernetes.api.model.Event;

import java.util.List;

/**
* Prints
*/
public class KubernetesEventsException extends Exception {
public KubernetesEventsException(List<Event> events) {
super(toMessage(events));
}

private static String toMessage(List<Event> events) {
StringBuilder sb = new StringBuilder("Events follow:\n");
for (Event event : events) {
String[] lines = event.getMessage().split("\n");
for (String line : lines) {
sb.append(String.format("[%s][%s/%s][%s] %s%n", event.getType(), event.getInvolvedObject().getNamespace(), event.getInvolvedObject().getName(), event.getReason(), line));
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
import javax.annotation.CheckForNull;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.client.KubernetesClientException;
import jenkins.metrics.api.Metrics;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException;
import org.kohsuke.stapler.DataBoundConstructor;

import com.google.common.base.Throwables;
Expand Down Expand Up @@ -255,6 +257,14 @@ else if (httpCode == 409 && e.getMessage().contains("Operation cannot be fulfill
}
Metrics.metricRegistry().counter(MetricNames.PODS_LAUNCHED).inc();
} catch (Throwable ex) {
try {
List<Event> podEvents = ((KubernetesComputer) computer).getPodEvents();
if (!podEvents.isEmpty()) {
ex.addSuppressed(new KubernetesEventsException(podEvents));
}
} catch (KubernetesAuthException | IOException e) {
LOGGER.log(Level.FINE, "Unable to add Kubernetes events");
}
setProblem(ex);
LOGGER.log(Level.WARNING, String.format("Error in provisioning; agent=%s, template=%s", node, template), ex);
LOGGER.log(Level.FINER, "Removing Jenkins node: {0}", node.getNodeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.deletePods;
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.getLabels;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.oneOf;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -675,6 +677,13 @@ public void invalidPodGetsCancelled() throws Exception {
r.assertLogContains("ERROR: Queue task was cancelled", b);
}

@Test
public void podEventsPrinted() throws Exception {
Thread.sleep(5000);
b.doKill();
assertThat(logs.getMessages(), hasItem(containsString("Readiness probe failed")));
}

@Issue("SECURITY-1646")
@Test
public void substituteEnv() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
podTemplate(slaveConnectTimeout:10, yaml:'''
spec:
containers:
- name: neverready
image: busybox
command: ['sleep', '99999999']
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
''') {
node(POD_LABEL) {
sh 'true'
}
}