Skip to content

Commit

Permalink
feat: Allow override of scheduler name spec field
Browse files Browse the repository at this point in the history
  • Loading branch information
CptLemming committed Mar 13, 2021
1 parent 55e01ea commit 487d544
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements

private String serviceAccount;

private String schedulerName;

private String nodeSelector;

private Node.Mode nodeUsageMode;
Expand Down Expand Up @@ -567,6 +569,15 @@ public void setServiceAccount(String serviceAccount) {
this.serviceAccount = Util.fixEmpty(serviceAccount);
}

public String getSchedulerName() {
return schedulerName;
}

@DataBoundSetter
public void setSchedulerName(String schedulerName) {
this.schedulerName = Util.fixEmpty(schedulerName);
}

@Deprecated
@DataBoundSetter
public void setAlwaysPullImage(boolean alwaysPullImage) {
Expand Down Expand Up @@ -1018,6 +1029,7 @@ public String toString() {
(activeDeadlineSeconds == 0 ? "" : ", activeDeadlineSeconds=" + activeDeadlineSeconds) +
(label == null ? "" : ", label='" + label + '\'') +
(serviceAccount == null ? "" : ", serviceAccount='" + serviceAccount + '\'') +
(schedulerName == null ? "" : ", schedulerName='" + schedulerName + '\'') +
(nodeSelector == null ? "" : ", nodeSelector='" + nodeSelector + '\'') +
(nodeUsageMode == null ? "" : ", nodeUsageMode=" + nodeUsageMode) +
(resourceRequestCpu == null ? "" : ", resourceRequestCpu='" + resourceRequestCpu + '\'') +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ public Pod build() {
if (template.getServiceAccount() != null) {
builder.withServiceAccountName(substituteEnv(template.getServiceAccount()));
}
if (template.getSchedulerName() != null) {
builder.withSchedulerName(substituteEnv(template.getSchedulerName()));
}

List<LocalObjectReference> imagePullSecrets = template.getImagePullSecrets().stream()
.map((x) -> x.toLocalObjectReference()).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ public static Pod combine(Pod parent, Pod template) {
String serviceAccountName = Strings.isNullOrEmpty(template.getSpec().getServiceAccountName())
? parent.getSpec().getServiceAccountName()
: template.getSpec().getServiceAccountName();
String schedulerName = Strings.isNullOrEmpty(template.getSpec().getSchedulerName())
? parent.getSpec().getSchedulerName()
: template.getSpec().getSchedulerName();

Boolean hostNetwork = template.getSpec().getHostNetwork() != null
? template.getSpec().getHostNetwork()
Expand Down Expand Up @@ -298,6 +301,7 @@ public static Pod combine(Pod parent, Pod template) {
.withNodeSelector(nodeSelector) //
.withServiceAccount(serviceAccount) //
.withServiceAccountName(serviceAccountName) //
.withSchedulerName(schedulerName)
.withHostNetwork(hostNetwork) //
.withContainers(combinedContainers) //
.withInitContainers(combinedInitContainers) //
Expand Down Expand Up @@ -371,6 +375,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
String label = template.getLabel();
String nodeSelector = Strings.isNullOrEmpty(template.getNodeSelector()) ? parent.getNodeSelector() : template.getNodeSelector();
String serviceAccount = Strings.isNullOrEmpty(template.getServiceAccount()) ? parent.getServiceAccount() : template.getServiceAccount();
String schedulerName = Strings.isNullOrEmpty(template.getSchedulerName()) ? parent.getSchedulerName() : template.getSchedulerName();
Node.Mode nodeUsageMode = template.getNodeUsageMode() == null ? parent.getNodeUsageMode() : template.getNodeUsageMode();

Set<PodAnnotation> podAnnotations = new LinkedHashSet<>();
Expand Down Expand Up @@ -406,6 +411,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
podTemplate.setLabel(label);
podTemplate.setNodeSelector(nodeSelector);
podTemplate.setServiceAccount(serviceAccount);
podTemplate.setSchedulerName(schedulerName);
podTemplate.setEnvVars(combineEnvVars(parent, template));
podTemplate.setContainers(new ArrayList<>(combinedContainers.values()));
podTemplate.setWorkspaceVolume(workspaceVolume);
Expand Down Expand Up @@ -434,6 +440,9 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
podTemplate.setServiceAccount(!Strings.isNullOrEmpty(template.getServiceAccount()) ?
template.getServiceAccount() : parent.getServiceAccount());

podTemplate.setSchedulerName(!Strings.isNullOrEmpty(template.getSchedulerName()) ?
template.getSchedulerName() : parent.getSchedulerName());

podTemplate.setPodRetention(template.getPodRetention());
podTemplate.setShowRawYaml(template.isShowRawYamlSet() ? template.isShowRawYaml() : parent.isShowRawYaml());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class KubernetesDeclarativeAgent extends DeclarativeAgent<KubernetesDecla
@CheckForNull
private String serviceAccount;
@CheckForNull
private String schedulerName;
@CheckForNull
private String nodeSelector;
@CheckForNull
private String namespace;
Expand Down Expand Up @@ -163,6 +165,15 @@ public void setServiceAccount(String serviceAccount) {
this.serviceAccount = serviceAccount;
}

public String getSchedulerName() {
return schedulerName;
}

@DataBoundSetter
public void setSchedulerName(String schedulerName) {
this.schedulerName = schedulerName;
}

public String getNodeSelector() {
return nodeSelector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class PodTemplateStep extends Step implements Serializable {
@CheckForNull
private String serviceAccount;

@CheckForNull
private String schedulerName;

@CheckForNull
private String nodeSelector;

Expand Down Expand Up @@ -269,6 +272,14 @@ public void setServiceAccount(@CheckForNull String serviceAccount) {
this.serviceAccount = Util.fixEmpty(serviceAccount);
}

@CheckForNull
public String getSchedulerName() { return schedulerName; }

@DataBoundSetter
public void setSchedulerName(@CheckForNull String schedulerName) {
this.schedulerName = Util.fixEmpty(schedulerName);
}

@CheckForNull
public String getNodeSelector() {
return nodeSelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public boolean start() throws Exception {
newTemplate.setNodeSelector(step.getNodeSelector());
newTemplate.setNodeUsageMode(step.getNodeUsageMode());
newTemplate.setServiceAccount(step.getServiceAccount());
newTemplate.setSchedulerName(step.getSchedulerName());
newTemplate.setRunAsUser(step.getRunAsUser());
newTemplate.setRunAsGroup(step.getRunAsGroup());
if (step.getHostNetwork() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,31 @@ public void yamlOverrideHostNetwork() {
assertTrue(pod.getSpec().getHostNetwork());
}

@Test
public void yamlOverrideSchedulerName() {
PodTemplate parent = new PodTemplate();
parent.setYaml(
"apiVersion: v1\n" +
"kind: Pod\n" +
"metadata:\n" +
" labels:\n" +
" some-label: some-label-value\n" +
"spec:\n" +
" schedulerName: default-scheduler\n"
);

PodTemplate child = new PodTemplate();
child.setYaml(
"spec:\n" +
" schedulerName: custom-scheduler\n"
);
child.setInheritFrom("parent");
child.setYamlMergeStrategy(merge());
PodTemplate result = combine(parent, child);
Pod pod = new PodTemplateBuilder(result, slave).build();
assertEquals("custom-scheduler", pod.getSpec().getSchedulerName());
}

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

0 comments on commit 487d544

Please sign in to comment.