Skip to content

Commit

Permalink
Use default workingDir when not set
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossg committed Mar 30, 2018
1 parent cd4b89b commit 07cb5e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Expand Up @@ -109,6 +109,12 @@ public PodTemplateBuilder withSlave(KubernetesSlave slave) {
return this;
}

@Deprecated
public Pod build(KubernetesSlave slave) {
LOGGER.log(Level.WARNING, "This method is deprecated and does nothing");
return this.build();
}

/**
* Create a Pod object from a PodTemplate
*/
Expand Down Expand Up @@ -225,6 +231,7 @@ public Pod build() {
.filter(c -> c.getVolumeMounts().stream().noneMatch(vm -> WORKSPACE_VOLUME_NAME.equals(vm.getName())))
.forEach(c -> c.getVolumeMounts().add(getDefaultVolumeMount(c.getWorkingDir())));

LOGGER.log(Level.FINE, "Pod built: {0}", pod);
return pod;
}

Expand Down Expand Up @@ -321,8 +328,13 @@ private Container createContainer(ContainerTemplate containerTemplate, Collectio
.build();
}

private VolumeMount getDefaultVolumeMount(String workingDir) {
return new VolumeMount(workingDir, WORKSPACE_VOLUME_NAME, false, null);
private VolumeMount getDefaultVolumeMount(@CheckForNull String workingDir) {
String wd = workingDir;
if (wd == null) {
wd = ContainerTemplate.DEFAULT_WORKING_DIR;
LOGGER.log(Level.FINE, "Container workingDir is null, defaulting to {0}", wd);
}
return new VolumeMount(wd, WORKSPACE_VOLUME_NAME, false, null);
}

private List<VolumeMount> getContainerVolumeMounts(Collection<VolumeMount> volumeMounts, String workingDir) {
Expand Down
Expand Up @@ -12,6 +12,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -42,6 +44,9 @@
import io.fabric8.kubernetes.api.model.VolumeMount;

public class PodTemplateUtils {

private static final Logger LOGGER = Logger.getLogger(PodTemplateUtils.class.getName());

/**
* Combines a {@link ContainerTemplate} with its parent.
* @param parent The parent container template (nullable).
Expand Down Expand Up @@ -161,6 +166,9 @@ public static Pod combine(Pod parent, Pod template) {
return template;
}

LOGGER.log(Level.FINE, "Combining pods, parent: {0}", parent);
LOGGER.log(Level.FINE, "Combining pods, template: {0}", template);

Map<String, String> nodeSelector = mergeMaps(parent.getSpec().getNodeSelector(),
template.getSpec().getNodeSelector());
String serviceAccount = Strings.isNullOrEmpty(template.getSpec().getServiceAccount())
Expand Down Expand Up @@ -218,7 +226,9 @@ public static Pod combine(Pod parent, Pod template) {
// podTemplate.setNodeUsageMode(nodeUsageMode);
// podTemplate.setYaml(template.getYaml() == null ? parent.getYaml() : template.getYaml());

return specBuilder.endSpec().build();
Pod pod = specBuilder.endSpec().build();
LOGGER.log(Level.FINE, "Pods combined: {0}", pod);
return pod;
}

/**
Expand Down

0 comments on commit 07cb5e4

Please sign in to comment.