Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-50525] Fix mountPath error provisioning #346

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -18,6 +18,7 @@
import com.google.common.base.Preconditions;

import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
Expand Down Expand Up @@ -151,7 +152,7 @@ public String getDisplayName() {

@DataBoundSetter
public void setWorkingDir(String workingDir) {
this.workingDir = workingDir;
this.workingDir = Util.fixEmpty(workingDir);
}

public String getWorkingDir() {
Expand Down Expand Up @@ -238,6 +239,15 @@ public void setResourceRequestCpu(String resourceRequestCpu) {
this.resourceRequestCpu = resourceRequestCpu;
}

public String getShell() {
return shell;
}

@DataBoundSetter
public void setShell(String shell) {
this.shell = shell;
}

public Map<String,Object> getAsArgs() {
Map<String,Object> argMap = new TreeMap<>();

Expand Down Expand Up @@ -374,12 +384,8 @@ public int hashCode() {
return result;
}

public String getShell() {
return shell;
}

@DataBoundSetter
public void setShell(String shell) {
this.shell = shell;
private Object readResolve() {
this.workingDir = Util.fixEmpty(workingDir);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ public Pod build() {
}

if (template.getWorkspaceVolume() != null) {
LOGGER.log(Level.FINE, "Adding workspace volume from template: {0}",
template.getWorkspaceVolume().toString());
volumes.put(WORKSPACE_VOLUME_NAME, template.getWorkspaceVolume().buildVolume(WORKSPACE_VOLUME_NAME));
} else {
// add an empty volume to share the workspace across the pod
LOGGER.log(Level.FINE, "Adding empty workspace volume");
volumes.put(WORKSPACE_VOLUME_NAME, new VolumeBuilder().withName(WORKSPACE_VOLUME_NAME).withNewEmptyDir().endEmptyDir().build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public Volume buildVolume(String volumeName) {
return new VolumeBuilder().withName(volumeName).withNewEmptyDir().withMedium(getMedium()).endEmptyDir().build();
}

@Override
public String toString() {
return "EmptyDirVolume [mountPath=" + mountPath + ", memory=" + memory + "]";
}

@Extension
@Symbol("emptyDirVolume")
public static class DescriptorImpl extends Descriptor<PodVolume> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public String getMountPath() {
return mountPath;
}

@Override
public String toString() {
return "SecretVolume [mountPath=" + mountPath + ", secretName=" + secretName + "]";
}

@Extension
@Symbol("secretVolume")
public static class DescriptorImpl extends Descriptor<PodVolume> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public Volume buildVolume(String volumeName) {
return new VolumeBuilder().withName(volumeName).withNewEmptyDir().withMedium(getMedium()).endEmptyDir().build();
}

@Override
public String toString() {
return "EmptyDirWorkspaceVolume [memory=" + memory + "]";
}

@Extension
@Symbol("emptyDirWorkspaceVolume")
public static class DescriptorImpl extends Descriptor<WorkspaceVolume> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import java.util.stream.Collectors;

import org.apache.commons.compress.utils.IOUtils;
import org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume;
import org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.LoggerRule;
import org.mockito.Mock;
import org.mockito.Spy;
Expand Down Expand Up @@ -93,6 +96,27 @@ public void testBuildFromYaml() throws Exception {
assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
}

@Test
@Issue("JENKINS-50525")
public void testBuildWithCustomWorkspaceVolume() throws Exception {
PodTemplate template = new PodTemplate();
template.setCustomWorkspaceVolumeEnabled(true);
template.setWorkspaceVolume(new EmptyDirWorkspaceVolume(false));
ContainerTemplate containerTemplate = new ContainerTemplate("name", "image");
containerTemplate.setWorkingDir("");
template.getContainers().add(containerTemplate);
setupStubs();
Pod pod = new PodTemplateBuilder(template).withSlave(slave).build();
List<Container> containers = pod.getSpec().getContainers();
assertEquals(2, containers.size());
Container container0 = containers.get(0);
Container container1 = containers.get(1);
ImmutableList<VolumeMount> volumeMounts = ImmutableList
.of(new VolumeMount("/home/jenkins", "workspace-volume", false, null));
assertEquals(volumeMounts, container0.getVolumeMounts());
assertEquals(volumeMounts, container1.getVolumeMounts());
}

private void setupStubs() {
doReturn(JENKINS_URL).when(cloud).getJenkinsUrlOrDie();
when(computer.getName()).thenReturn(AGENT_NAME);
Expand Down