Skip to content
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 @@ -532,8 +532,9 @@ public Collection<NodeProvisioner.PlannedNode> provision(@NonNull final Cloud.Cl
LOGGER.log(Level.FINE, "Template for label \"{0}\": {1}", new Object[]{label, podTemplate.getName()});
// check overall concurrency limit using the default label(s) on all templates
int numExecutors = 1;
PodTemplate unwrappedTemplate = getUnwrappedTemplate(podTemplate);
while (toBeProvisioned > 0 && KubernetesProvisioningLimits.get().register(this, podTemplate, numExecutors)) {
plannedNodes.add(PlannedNodeBuilderFactory.createInstance().cloud(this).template(podTemplate).label(label).numExecutors(1).build());
plannedNodes.add(PlannedNodeBuilderFactory.createInstance().cloud(this).template(unwrappedTemplate).label(label).numExecutors(1).build());
toBeProvisioned--;
}
if (!plannedNodes.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ protected static MessageDigest getLabelDigestFunction() {

private String id;

private transient boolean unwrapped;

private String inheritFrom;

private String name;
Expand Down Expand Up @@ -924,6 +926,14 @@ public void setShowRawYaml(boolean showRawYaml) {
this.showRawYaml = Boolean.valueOf(showRawYaml);
}

void setUnwrapped(boolean unwrapped) {
this.unwrapped = unwrapped;
}

boolean isUnwrapped() {
return unwrapped;
}

private String getContainersDescriptionForLogging() {
List<ContainerTemplate> containers = getContainers();
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -1052,6 +1062,7 @@ public String toString() {
(imagePullSecrets == null || imagePullSecrets.isEmpty() ? "" : ", imagePullSecrets=" + imagePullSecrets) +
(nodeProperties == null || nodeProperties.isEmpty() ? "" : ", nodeProperties=" + nodeProperties) +
(yamls == null || yamls.isEmpty() ? "" : ", yamls=" + yamls) +
(!unwrapped ? "" : ", unwrapped=" + unwrapped) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,33 +486,38 @@ static PodTemplate unwrap(PodTemplate template, String defaultProviderTemplate,
return null;
}

StringBuilder sb = new StringBuilder();
if (!isNullOrEmpty(defaultProviderTemplate)) {
sb.append(defaultProviderTemplate).append(" ");

}
if (!isNullOrEmpty(template.getInheritFrom())) {
sb.append(template.getInheritFrom()).append(" ");
}
String inheritFrom = sb.toString();

if (isNullOrEmpty(inheritFrom)) {
List<String> inheritFrom = computedInheritFrom(template, defaultProviderTemplate);
if (inheritFrom.isEmpty()) {
return template;
} else {
String[] parentNames = inheritFrom.split("[ ]+");
PodTemplate parent = null;
for (String name : parentNames) {
for (String name : inheritFrom) {
PodTemplate next = getTemplateByName(name, allTemplates);
if (next != null) {
parent = combine(parent, unwrap(next, allTemplates));
}
}
PodTemplate combined = combine(parent, template);
combined.setUnwrapped(true);
LOGGER.log(Level.FINEST, "Combined parent + template is {0}", combined);
return combined;
}
}

private static List<String> computedInheritFrom(PodTemplate template, String defaultProviderTemplate) {
List<String> hierarchy = new ArrayList<>();
if (!isNullOrEmpty(defaultProviderTemplate)) {
hierarchy.add(defaultProviderTemplate);
}
if (!isNullOrEmpty(template.getInheritFrom())) {
String[] split = template.getInheritFrom().split(" +");
for (String name : split) {
hierarchy.add(name);
}
}
return Collections.unmodifiableList(hierarchy);
}

/**
* Unwraps the hierarchy of the PodTemplate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public NodeProvisioner.PlannedNode build() {
try {
KubernetesSlave agent = KubernetesSlave
.builder()
.podTemplate(cloud.getUnwrappedTemplate(t))
.podTemplate(t.isUnwrapped() ? t : cloud.getUnwrappedTemplate(t))
.cloud(cloud)
.build();
displayName = agent.getDisplayName();
Expand Down