Skip to content

Commit

Permalink
Merge pull request #546 from Vlatombe/JENKINS-58507
Browse files Browse the repository at this point in the history
[JENKINS-58507] Display resulting pod yaml instead of input
  • Loading branch information
Vlatombe committed Jul 16, 2019
2 parents c3f91cb + 2bd5f17 commit 116b949
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public void launch(SlaveComputer computer, TaskListener listener) {
try {
KubernetesClient client = slave.getKubernetesCloud().connect();
Pod pod = template.build(slave);
if (template.isShowRawYaml()) {
slave.assignPod(pod);
}

String podId = pod.getMetadata().getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import io.fabric8.kubernetes.client.utils.Serialization;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
Expand All @@ -25,7 +27,6 @@

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Computer;
import hudson.model.Descriptor;
Expand Down Expand Up @@ -71,6 +72,9 @@ public class KubernetesSlave extends AbstractCloudSlave {
private final PodTemplate template;
private transient Set<Queue.Executable> executables = new HashSet<>();

@CheckForNull
private transient Pod pod;

@Nonnull
public PodTemplate getTemplate() {
return template;
Expand Down Expand Up @@ -350,14 +354,24 @@ public Launcher createLauncher(TaskListener listener) {
ModelHyperlinkNote.encodeTo("/computer/" + getNodeName(), getNodeName()),
getTemplate().getDisplayName())
);
listener.getLogger().println(getTemplate().getDescriptionForLogging());
printAgentDescription(listener);
checkHomeAndWarnIfNeeded(listener);
}
}
}
return launcher;
}

void assignPod(@CheckForNull Pod pod) {
this.pod = pod;
}

private void printAgentDescription(TaskListener listener) {
if (pod != null) {
listener.getLogger().println(Serialization.asYaml(pod));
}
}

private void checkHomeAndWarnIfNeeded(TaskListener listener) {
try {
Computer computer = toComputer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ public Pod build(KubernetesSlave slave) {
return new PodTemplateBuilder(this).withSlave(slave).build();
}

/**
* @deprecated Use {@code Serialization.asYaml(build(KubernetesSlave))} instead.
*/
@Deprecated
public String getDescriptionForLogging() {
return String.format("Agent specification [%s] (%s): %n%s",
getDisplayName(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ public void bourneShellElsewhereInPath() throws Exception {
@Test
public void runInPodWithMultipleContainers() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("[jnlp] jenkins/jnlp-slave:3.10-1-alpine", b);
r.assertLogContains("[maven] maven:3.3.9-jdk-8-alpine", b);
r.assertLogContains("[golang] golang:1.6.3-alpine", b);
r.assertLogContains("image: \"jenkins/jnlp-slave:3.10-1-alpine\"", b);
r.assertLogContains("image: \"maven:3.3.9-jdk-8-alpine\"", b);
r.assertLogContains("image: \"golang:1.6.3-alpine\"", b);
r.assertLogContains("My Kubernetes Pipeline", b);
r.assertLogContains("my-mount", b);
r.assertLogContains("Apache Maven 3.3.9", b);
Expand All @@ -221,8 +221,8 @@ public void runInPodWithMultipleContainers() throws Exception {
@Test
public void runInPodNested() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("[maven] maven:3.3.9-jdk-8-alpine", b);
r.assertLogContains("[golang] golang:1.6.3-alpine", b);
r.assertLogContains("image: \"maven:3.3.9-jdk-8-alpine\"", b);
r.assertLogContains("image: \"golang:1.6.3-alpine\"", b);
r.assertLogContains("Apache Maven 3.3.9", b);
r.assertLogContains("go version go1.6.3", b);
}
Expand All @@ -231,8 +231,8 @@ public void runInPodNested() throws Exception {
@Test
public void runInPodNestedExplicitInherit() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("[maven] maven:3.3.9-jdk-8-alpine", b);
r.assertLogNotContains("[golang] golang:1.6.3-alpine", b);
r.assertLogContains("image: \"maven:3.3.9-jdk-8-alpine\"", b);
r.assertLogNotContains("image: \"golang:1.6.3-alpine\"", b);
r.assertLogContains("Apache Maven 3.3.9", b);
r.assertLogNotContains("go version go1.6.3", b);
}
Expand Down Expand Up @@ -406,7 +406,7 @@ private void assertNotXPath(HtmlPage page, String xpath) {
@Test
public void runInPodWithShowRawYamlFalse() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains("value: container-env-var-value", b);
r.assertLogNotContains("value: \"container-env-var-value\"", b);
}

@Test
Expand Down

0 comments on commit 116b949

Please sign in to comment.