Skip to content

Commit

Permalink
Add ability to provide a custom ttl to the job
Browse files Browse the repository at this point in the history
  • Loading branch information
film42 committed Mar 28, 2022
1 parent c941967 commit 30b4e4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions deploymenthook.pod_template_by_spec.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
labels:
app: nginx
template:
ttlSecondsAfterFinished: 30
spec:
metadata:
labels:
Expand Down
5 changes: 5 additions & 0 deletions deploymenthooks.apps.mx.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,11 @@ spec:
- containers
type: object
type: object
ttlSecondsAfterFinished:
default: 259200
format: int32
nullable: true
type: integer
type: object
required:
- selector
Expand Down
4 changes: 4 additions & 0 deletions docbot-controller/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub fn generate_from_template(
&hook.metadata.name.as_ref().expect("name is missing")
));
let mut job_spec = JobSpec::default();

// Set the job ttl after it finishes.
job_spec.ttl_seconds_after_finished = hook.spec.template.ttl_seconds_after_finished;

if let Some(pod_template_spec) = template.template {
if let Some(ref metadata) = pod_template_spec.metadata {
job.metadata.annotations = metadata.annotations.clone();
Expand Down
9 changes: 9 additions & 0 deletions docbot-crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

/// The default job ttl is 72 hours.
fn default_job_ttl_seconds_after_finished() -> Option<i32> {
Some(259200)
}

/// Struct corresponding to the Specification (`spec`) part of the `DeploymentHook` resource,
/// directly reflects context of the `deploymenthooks.apps.mx.com.yaml` file to be found in
/// this repository.
Expand All @@ -28,12 +33,16 @@ pub struct DeploymentHookSpec {
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DeploymentSelector {
pub labels: BTreeMap<String, String>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct InternalPodTemplate {
#[serde(default = "default_job_ttl_seconds_after_finished")]
pub ttl_seconds_after_finished: Option<i32>,
pub name: Option<String>,
pub spec: Option<PodTemplateSpec>,
}
Expand Down

0 comments on commit 30b4e4c

Please sign in to comment.