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

Ensuring all data on pod template is copied during combine #319

Merged
merged 1 commit into from
May 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 @@ -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