Skip to content

Commit

Permalink
Backport "Add backoffLimit to KubernetesScheduler (#392)" (#538)
Browse files Browse the repository at this point in the history
See #407
  • Loading branch information
onobc authored Apr 30, 2023
1 parent 4a39101 commit 117840b
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,8 @@ public static class CronConfig {

private Integer ttlSecondsAfterFinished;

private Integer backoffLimit;

public String getConcurrencyPolicy() {
return concurrencyPolicy;
}
Expand All @@ -1507,6 +1509,14 @@ public Integer getTtlSecondsAfterFinished() {
public void setTtlSecondsAfterFinished(Integer ttlSecondsAfterFinished) {
this.ttlSecondsAfterFinished = ttlSecondsAfterFinished;
}

public Integer getBackoffLimit() {
return backoffLimit;
}

public void setBackoffLimit(Integer backoffLimit) {
this.backoffLimit = backoffLimit;
}
}

public Boolean getShareProcessNamespace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class KubernetesScheduler extends AbstractKubernetesDeployer implements S

static final String KUBERNETES_DEPLOYER_CRON_TTL_SECONDS_AFTER_FINISHED = KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX + ".cron.ttlSecondsAfterFinished";

static final String KUBERNETES_DEPLOYER_CRON_BACKOFF_LIMIT = KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX + ".cron.backoffLimit";

public KubernetesScheduler(KubernetesClient client,
KubernetesDeployerProperties properties) {
Assert.notNull(client, "KubernetesClient must not be null");
Expand Down Expand Up @@ -212,7 +214,7 @@ protected CronJob createCronJob(ScheduleRequest scheduleRequest) {
if (!StringUtils.hasText(concurrencyPolicy)) {
concurrencyPolicy = this.properties.getCron().getConcurrencyPolicy();
}
if(concurrencyPolicy==null) {
if (concurrencyPolicy == null) {
concurrencyPolicy = "Allow";
}

Expand All @@ -225,6 +227,15 @@ protected CronJob createCronJob(ScheduleRequest scheduleRequest) {
ttlSecondsAfterFinished = this.properties.getCron().getTtlSecondsAfterFinished();
}

final Integer backoffLimit;
String backoffLimitString = schedulerProperties.get(KUBERNETES_DEPLOYER_CRON_BACKOFF_LIMIT);
if (StringUtils.hasText(backoffLimitString)) {
backoffLimit = Integer.parseInt(backoffLimitString);
}
else {
backoffLimit = this.properties.getCron().getBackoffLimit();
}

PodSpec podSpec = createPodSpec(new ScheduleRequest(scheduleRequest.getDefinition(),schedulerProperties, scheduleRequest.getCommandlineArguments(), scheduleRequest.getScheduleName(),scheduleRequest.getResource()));
String taskServiceAccountName = this.deploymentPropertiesResolver.getTaskServiceAccountName(schedulerProperties);
taskServiceAccountName = taskServiceAccountName != null ? taskServiceAccountName : KubernetesDeployerProperties.DEFAULT_TASK_SERVICE_ACCOUNT_NAME;
Expand All @@ -234,13 +245,29 @@ protected CronJob createCronJob(ScheduleRequest scheduleRequest) {
Map<String, String> annotations = this.deploymentPropertiesResolver.getPodAnnotations(schedulerProperties);
labels.putAll(this.deploymentPropertiesResolver.getDeploymentLabels(schedulerProperties));

CronJob cronJob = new CronJobBuilder().withNewMetadata().withName(scheduleRequest.getScheduleName())
.withLabels(labels).withAnnotations(this.deploymentPropertiesResolver.getJobAnnotations(schedulerProperties)).endMetadata()
.withNewSpec().withSchedule(schedule).withConcurrencyPolicy(concurrencyPolicy).withNewJobTemplate()
.withNewSpec().withTtlSecondsAfterFinished(ttlSecondsAfterFinished)
.withNewTemplate().withNewMetadata().addToAnnotations(annotations).addToLabels(labels)
.endMetadata().withSpec(podSpec).endTemplate().endSpec()
.endJobTemplate().endSpec().build();
CronJob cronJob = new CronJobBuilder()
.withNewMetadata()
.withName(scheduleRequest.getScheduleName())
.withLabels(labels)
.withAnnotations(this.deploymentPropertiesResolver.getJobAnnotations(schedulerProperties))
.endMetadata()
.withNewSpec()
.withSchedule(schedule)
.withConcurrencyPolicy(concurrencyPolicy)
.withNewJobTemplate()
.withNewSpec()
.withBackoffLimit(backoffLimit)
.withTtlSecondsAfterFinished(ttlSecondsAfterFinished)
.withNewTemplate()
.withNewMetadata()
.addToAnnotations(annotations).addToLabels(labels)
.endMetadata()
.withSpec(podSpec)
.endTemplate()
.endSpec()
.endJobTemplate()
.endSpec()
.build();

setImagePullSecret(scheduleRequest, cronJob);

Expand Down
Loading

0 comments on commit 117840b

Please sign in to comment.