Skip to content

Commit

Permalink
Slave nodes now get their own copy of the template node properties. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdarton authored Sep 10, 2019
1 parent ac7d142 commit 91d8c74
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ public String getFullImageId() {
return dockerTemplateBase.getFullImageId();
}



public DockerTemplateBase getDockerTemplateBase() {
return dockerTemplateBase;
}
Expand Down Expand Up @@ -346,7 +344,7 @@ public void setPullTimeout(int pullTimeout) {
public List<? extends NodeProperty<?>> getNodeProperties() {
return Collections.unmodifiableList(nodeProperties);
}

@DataBoundSetter
public void setNodeProperties(List<? extends NodeProperty<?>> nodeProperties) {
this.nodeProperties = nodeProperties;
Expand Down Expand Up @@ -442,7 +440,7 @@ public DockerTemplate cloneWithLabel(String label) {
template.setPullStrategy(pullStrategy);
template.setRemoveVolumes(removeVolumes);
template.setRetentionStrategy((DockerOnceRetentionStrategy) retentionStrategy);
template.setNodeProperties(nodeProperties);
template.setNodeProperties(makeCopyOfList(nodeProperties));
return template;
}

Expand Down Expand Up @@ -564,13 +562,12 @@ private DockerTransientNode doProvisionNode(DockerAPI api, DockerClient client,
connector.afterContainerStarted(api, remoteFs, containerId);

final ComputerLauncher launcher = connector.createLauncher(api, containerId, remoteFs, listener);

final DockerTransientNode node = new DockerTransientNode(nodeName, containerId, remoteFs, launcher);
node.setNodeDescription("Docker Agent [" + getImage() + " on "+ api.getDockerHost().getUri() + " ID " + containerId + "]");
node.setMode(mode);
node.setLabelString(labelString);
node.setRetentionStrategy(retentionStrategy);
robustlySetNodeProperties(node, nodeProperties);
robustlySetNodeProperties(node, makeCopyOfList(nodeProperties));
node.setRemoveVolumes(removeVolumes);
node.setDockerAPI(api);
finallyRemoveTheContainer = false;
Expand All @@ -590,6 +587,23 @@ private DockerTransientNode doProvisionNode(DockerAPI api, DockerClient client,
}
}

private static <T> List<T> makeCopyOfList(List<? extends T> listOrNull) {
final List<? extends T> originalList = Util.fixNull(listOrNull);
final List<T> copyList = new ArrayList<T>(originalList.size());
for( final T originalElement : originalList) {
final T copyOfElement = makeCopy(originalElement);
copyList.add(copyOfElement);
}
return copyList;
}

@SuppressWarnings("unchecked")
private static <T> T makeCopy(final T original) {
final String xml = Jenkins.XSTREAM.toXML(original);
final Object copy = Jenkins.XSTREAM.fromXML(xml);
return (T) copy;
}

/**
* Returns a node name for a new node that doesn't clash with any we've
* currently got.
Expand Down Expand Up @@ -701,7 +715,6 @@ public static final class DescriptorImpl extends Descriptor<DockerTemplate> {
* Get a list of all {@link NodePropertyDescriptor}s we can use to define DockerSlave NodeProperties.
*/
public List<NodePropertyDescriptor> getNodePropertiesDescriptors() {

// Copy/paste hudson.model.Slave.SlaveDescriptor.nodePropertyDescriptors marked as @Restricted for reasons I don't get
List<NodePropertyDescriptor> result = new ArrayList<>();
Collection<NodePropertyDescriptor> list =
Expand All @@ -711,8 +724,6 @@ public List<NodePropertyDescriptor> getNodePropertiesDescriptors() {
result.add(npd);
}
}


final Iterator<NodePropertyDescriptor> iterator = result.iterator();
while (iterator.hasNext()) {
final NodePropertyDescriptor de = iterator.next();
Expand Down

0 comments on commit 91d8c74

Please sign in to comment.