1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
use super::*;
pub trait JobExt: super::ResourceBuilder + Sized {
fn new(name: impl ToString) -> Self;
fn with_labels(
name: impl ToString,
labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self;
fn active_deadline_seconds(self, seconds: i64) -> Self;
fn backoff_limit(self, limit: i32) -> Self;
fn completion_mode<'a>(self, mode: impl Into<Option<&'a str>>) -> Self;
fn non_indexed(self) -> Self {
self.completion_mode("NonIndexed")
}
fn indexed(self) -> Self {
self.completion_mode("Indexed")
}
fn completions(self, completions: i32) -> Self;
fn manual_selector(self, yes: bool) -> Self;
fn parallelism(self, parallelism: i32) -> Self;
fn selector(self, selector: metav1::LabelSelector) -> Self;
fn match_labels(
self,
match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self;
fn suspend(self, yes: bool) -> Self;
fn template(self, template: corev1::PodTemplateSpec) -> Self;
fn pod(self, pod: corev1::PodSpec) -> Self;
fn ttl_seconds_after_finished(self, seconds: i32) -> Self;
}
impl JobExt for batchv1::Job {
fn new(name: impl ToString) -> Self {
let metadata = metadata(name);
Self {
metadata,
..default()
}
}
fn with_labels(
name: impl ToString,
labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self {
Self::new(name).labels(labels)
}
fn active_deadline_seconds(self, seconds: i64) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.active_deadline_seconds = Some(seconds);
Self {
spec: Some(spec),
..self
}
}
fn backoff_limit(self, limit: i32) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.backoff_limit = Some(limit);
Self {
spec: Some(spec),
..self
}
}
fn completion_mode<'a>(self, mode: impl Into<Option<&'a str>>) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.completion_mode = mode.into().map(|mode| mode.to_string());
Self {
spec: Some(spec),
..self
}
}
fn completions(self, completions: i32) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.completions = Some(completions);
Self {
spec: Some(spec),
..self
}
}
fn manual_selector(self, yes: bool) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.manual_selector = Some(yes);
Self {
spec: Some(spec),
..self
}
}
fn parallelism(self, parallelism: i32) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.parallelism = Some(parallelism);
Self {
spec: Some(spec),
..self
}
}
fn selector(self, selector: metav1::LabelSelector) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.selector = Some(selector);
Self {
spec: Some(spec),
..self
}
}
fn match_labels(
self,
match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self {
let mut spec = self.spec.unwrap_or_default();
let selector = spec.selector.unwrap_or_default().match_labels(match_labels);
spec.selector = Some(selector);
Self {
spec: Some(spec),
..self
}
}
fn suspend(self, yes: bool) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.suspend = Some(yes);
Self {
spec: Some(spec),
..self
}
}
fn template(self, template: corev1::PodTemplateSpec) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.template = template;
Self {
spec: Some(spec),
..self
}
}
fn pod(self, pod_spec: corev1::PodSpec) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.template.spec = Some(pod_spec);
Self {
spec: Some(spec),
..self
}
}
fn ttl_seconds_after_finished(self, seconds: i32) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.ttl_seconds_after_finished = Some(seconds);
Self {
spec: Some(spec),
..self
}
}
}