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

Backport "Add backoffLimit to KubernetesScheduler (#392)" #538

Merged
merged 1 commit into from
Apr 30, 2023
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 @@ -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