diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer.java index b7d55a9726..20ccd2a7eb 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer.java @@ -3,9 +3,15 @@ import hudson.model.Executor; import hudson.model.Queue; import hudson.slaves.AbstractCloudComputer; +import io.fabric8.kubernetes.api.model.ComponentStatus; import io.fabric8.kubernetes.api.model.Container; +import io.fabric8.kubernetes.api.model.Event; +import io.fabric8.kubernetes.api.model.EventList; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watcher; import jenkins.model.Jenkins; import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.QueryParameter; @@ -22,7 +28,10 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateEncodingException; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,6 +83,37 @@ public List getContainers() throws UnrecoverableKeyException, Certifi return pod.getSpec().getContainers(); } + @Exported + public List getPodEvents() throws UnrecoverableKeyException, CertificateEncodingException, NoSuchAlgorithmException, KeyStoreException, IOException { + Jenkins.get().checkPermission(Jenkins.ADMINISTER); + + KubernetesSlave slave = getNode(); + if(slave != null) { + KubernetesCloud cloud = slave.getKubernetesCloud(); + KubernetesClient client = cloud.connect(); + + String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), client.getNamespace()); + + Pod pod = client.pods().inNamespace(namespace).withName(getName()).get(); + if(pod != null) { + ObjectMeta podMeta = pod.getMetadata(); + String podNamespace = podMeta.getNamespace(); + + Map fields = new HashMap<>(); + fields.put("involvedObject.uid", podMeta.getUid()); + fields.put("involvedObject.name", podMeta.getName()); + fields.put("involvedObject.namespace", podNamespace); + + EventList eventList = client.events().inNamespace(podNamespace).withFields(fields).list(); + if(eventList != null) { + return eventList.getItems(); + } + } + } + + return Collections.emptyList(); + } + public void doContainerLog(@QueryParameter String containerId, StaplerRequest req, StaplerResponse rsp) throws UnrecoverableKeyException, CertificateEncodingException, NoSuchAlgorithmException, KeyStoreException, IOException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/events.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/events.jelly new file mode 100644 index 0000000000..62a837899b --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/events.jelly @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
${%Type}${%Reason}${%Count}${%FirstTime}${%LastTime}${%From}${%Message}
${v.type}${v.reason}${v.count}${v.firstTimestamp}${v.lastTimestamp}${v.source.component}${v.message}
+
+
+
diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/sidepanel2.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/sidepanel2.jelly index 35e1446350..d64f5f72c0 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/sidepanel2.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesComputer/sidepanel2.jelly @@ -27,5 +27,6 @@ THE SOFTWARE. + \ No newline at end of file