k8s_openapi_ext/ext/
cronjob.rs1use super::*;
2
3pub trait CronJobExt: super::ResourceBuilder + Sized {
4 fn new(name: impl ToString) -> Self;
5 fn with_labels(
6 name: impl ToString,
7 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
8 ) -> Self;
9
10 fn starting_deadline_seconds(self, seconds: i64) -> Self;
11
12 fn schedule(self, schedule: impl ToString) -> Self;
13
14 fn suspend(self, yes: bool) -> Self;
15
16 fn template(self, template: batchv1::JobTemplateSpec) -> Self;
17}
18
19impl CronJobExt for batchv1::CronJob {
20 fn new(name: impl ToString) -> Self {
21 let metadata = metadata(name);
22 Self {
23 metadata,
24 ..default()
27 }
28 }
29
30 fn with_labels(
31 name: impl ToString,
32 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
33 ) -> Self {
34 Self::new(name).labels(labels)
35 }
36
37 fn starting_deadline_seconds(mut self, seconds: i64) -> Self {
38 self.spec_mut().starting_deadline_seconds.replace(seconds);
39 self
40 }
41
42 fn schedule(mut self, schedule: impl ToString) -> Self {
43 self.spec_mut().schedule = schedule.to_string();
44 self
45 }
46
47 fn suspend(mut self, yes: bool) -> Self {
48 self.spec_mut().suspend.replace(yes);
49 self
50 }
51
52 fn template(mut self, template: batchv1::JobTemplateSpec) -> Self {
53 self.spec_mut().job_template = template;
54 self
55 }
56}
57
58impl HasSpec for batchv1::CronJob {
59 type Spec = batchv1::CronJobSpec;
60
61 fn spec_mut(&mut self) -> &mut Self::Spec {
62 self.spec.get_or_insert_default()
63 }
64}