k8s_openapi_ext/ext/
job.rs1use super::*;
2
3pub trait JobExt: 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 active_deadline_seconds(self, seconds: i64) -> Self;
11
12 fn backoff_limit(self, limit: i32) -> Self;
13
14 fn completion_mode<'a>(self, mode: impl Into<Option<&'a str>>) -> Self;
15
16 fn non_indexed(self) -> Self {
17 self.completion_mode("NonIndexed")
18 }
19
20 fn indexed(self) -> Self {
21 self.completion_mode("Indexed")
22 }
23
24 fn completions(self, completions: i32) -> Self;
25
26 fn manual_selector(self, yes: bool) -> Self;
27 fn parallelism(self, parallelism: i32) -> Self;
28
29 fn selector(self, selector: metav1::LabelSelector) -> Self;
30
31 fn match_labels(
32 self,
33 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
34 ) -> Self;
35
36 fn suspend(self, yes: bool) -> Self;
37
38 fn template(self, template: corev1::PodTemplateSpec) -> Self;
39
40 fn pod(self, pod: corev1::PodSpec) -> Self;
41
42 fn ttl_seconds_after_finished(self, seconds: i32) -> Self;
43}
44
45impl JobExt for batchv1::Job {
46 fn new(name: impl ToString) -> Self {
47 let metadata = metadata(name);
48 Self {
49 metadata,
50 ..default()
53 }
54 }
55
56 fn with_labels(
57 name: impl ToString,
58 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
59 ) -> Self {
60 Self::new(name).labels(labels)
61 }
62
63 fn active_deadline_seconds(mut self, seconds: i64) -> Self {
64 self.spec_mut().active_deadline_seconds.replace(seconds);
65 self
66 }
67
68 fn backoff_limit(mut self, limit: i32) -> Self {
69 self.spec_mut().backoff_limit.replace(limit);
70 self
71 }
72
73 fn completion_mode<'a>(mut self, mode: impl Into<Option<&'a str>>) -> Self {
74 self.spec_mut().completion_mode = mode.into().map(|mode| mode.to_string());
75 self
76 }
77
78 fn completions(mut self, completions: i32) -> Self {
79 self.spec_mut().completions.replace(completions);
80 self
81 }
82
83 fn manual_selector(mut self, yes: bool) -> Self {
84 self.spec_mut().manual_selector.replace(yes);
85 self
86 }
87
88 fn parallelism(mut self, parallelism: i32) -> Self {
89 self.spec_mut().parallelism.replace(parallelism);
90 self
91 }
92
93 fn selector(mut self, selector: metav1::LabelSelector) -> Self {
94 self.spec_mut().selector.replace(selector);
95 self
96 }
97
98 fn match_labels(
99 self,
100 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
101 ) -> Self {
102 let mut spec = self.spec.unwrap_or_default();
103 let selector = spec.selector.unwrap_or_default().match_labels(match_labels);
104 spec.selector = Some(selector);
105 Self {
106 spec: Some(spec),
107 ..self
108 }
109 }
110
111 fn suspend(mut self, yes: bool) -> Self {
112 self.spec_mut().suspend.replace(yes);
113 self
114 }
115
116 fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
117 self.spec_mut().template = template;
118 self
119 }
120
121 fn pod(mut self, pod_spec: corev1::PodSpec) -> Self {
122 self.spec_mut().template.spec.replace(pod_spec);
123 self
124 }
125
126 fn ttl_seconds_after_finished(mut self, seconds: i32) -> Self {
127 self.spec_mut().ttl_seconds_after_finished.replace(seconds);
128 self
129 }
130}
131
132impl HasSpec for batchv1::Job {
133 type Spec = batchv1::JobSpec;
134
135 fn spec_mut(&mut self) -> &mut Self::Spec {
136 self.spec.get_or_insert_default()
137 }
138}