Skip to content

Commit

Permalink
Merge pull request #319 from farley13/master
Browse files Browse the repository at this point in the history
Ensuring all data on pod template is copied during combine
  • Loading branch information
carlossg authored May 22, 2018
2 parents 7c69ccc + b9a2144 commit f02a099
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
return template;
}

LOGGER.log(Level.FINEST, "Combining pod templates, parent: {0}", parent);
LOGGER.log(Level.FINEST, "Combining pod templates, template: {0}", template);

String name = template.getName();
String label = template.getLabel();
String nodeSelector = Strings.isNullOrEmpty(template.getNodeSelector()) ? parent.getNodeSelector() : template.getNodeSelector();
Expand Down Expand Up @@ -306,8 +309,31 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
podTemplate.setAnnotations(new ArrayList<>(podAnnotations));
podTemplate.setNodeProperties(toolLocationNodeProperties);
podTemplate.setNodeUsageMode(nodeUsageMode);
podTemplate.setInheritFrom(!Strings.isNullOrEmpty(template.getInheritFrom()) ?
template.getInheritFrom() : parent.getInheritFrom());

podTemplate.setInstanceCap(template.getInstanceCap() != Integer.MAX_VALUE ?
template.getInstanceCap() : parent.getInstanceCap());

podTemplate.setSlaveConnectTimeout(template.getSlaveConnectTimeout() != PodTemplate.DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT ?
template.getSlaveConnectTimeout() : parent.getSlaveConnectTimeout());

podTemplate.setIdleMinutes(template.getIdleMinutes() != 0 ?
template.getIdleMinutes() : parent.getIdleMinutes());

podTemplate.setActiveDeadlineSeconds(template.getActiveDeadlineSeconds() != 0 ?
template.getActiveDeadlineSeconds() : parent.getActiveDeadlineSeconds());


podTemplate.setServiceAccount(!Strings.isNullOrEmpty(template.getServiceAccount()) ?
template.getServiceAccount() : parent.getServiceAccount());

podTemplate.setCustomWorkspaceVolumeEnabled(template.isCustomWorkspaceVolumeEnabled() ?
template.isCustomWorkspaceVolumeEnabled() : parent.isCustomWorkspaceVolumeEnabled());

podTemplate.setYaml(template.getYaml() == null ? parent.getYaml() : template.getYaml());

LOGGER.log(Level.FINEST, "Pod templates combined: {0}", podTemplate);
return podTemplate;
}

Expand Down Expand Up @@ -345,7 +371,9 @@ static PodTemplate unwrap(PodTemplate template, String defaultProviderTemplate,
parent = combine(parent, unwrap(next, allTemplates));
}
}
return combine(parent, template);
PodTemplate combined = combine(parent, template);
LOGGER.log(Level.FINEST, "Combined parent + template is {0}", combined);
return combined;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import com.google.common.collect.ImmutableMap;

import hudson.model.Node;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.ObjectMeta;
Expand Down Expand Up @@ -204,6 +205,44 @@ public void shouldUnwrapParent() {
assertEquals("key:value", result.getNodeSelector());
}

@Test
public void shouldDropNoDataWhenIdentical() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setName("Name");
podTemplate.setNamespace("NameSpace");
podTemplate.setLabel("Label");
podTemplate.setServiceAccount("ServiceAccount");
podTemplate.setNodeSelector("NodeSelector");
podTemplate.setNodeUsageMode(Node.Mode.EXCLUSIVE);
podTemplate.setImagePullSecrets(asList(SECRET_1));
podTemplate.setInheritFrom("Inherit");
podTemplate.setInstanceCap(99);
podTemplate.setSlaveConnectTimeout(99);
podTemplate.setIdleMinutes(99);
podTemplate.setActiveDeadlineSeconds(99);
podTemplate.setServiceAccount("ServiceAccount");
podTemplate.setCustomWorkspaceVolumeEnabled(true);
podTemplate.setYaml("Yaml");

PodTemplate selfCombined = combine(podTemplate, podTemplate);

assertEquals("Name", podTemplate.getName());
assertEquals("NameSpace", podTemplate.getNamespace());
assertEquals("Label", podTemplate.getLabel());
assertEquals("ServiceAccount", podTemplate.getServiceAccount());
assertEquals("NodeSelector", podTemplate.getNodeSelector());
assertEquals(Node.Mode.EXCLUSIVE, podTemplate.getNodeUsageMode());
assertEquals(asList(SECRET_1), podTemplate.getImagePullSecrets());
assertEquals("Inherit", podTemplate.getInheritFrom());
assertEquals(99, podTemplate.getInstanceCap());
assertEquals(99, podTemplate.getSlaveConnectTimeout());
assertEquals(99, podTemplate.getIdleMinutes());
assertEquals(99, podTemplate.getActiveDeadlineSeconds());
assertEquals("ServiceAccount", podTemplate.getServiceAccount());
assertEquals(true, podTemplate.isCustomWorkspaceVolumeEnabled());
assertEquals("Yaml", podTemplate.getYaml());
}

@Test
public void shouldUnwrapMultipleParents() {
PodTemplate parent = new PodTemplate();
Expand Down

0 comments on commit f02a099

Please sign in to comment.