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
175
176
#[derive(Clone, Debug, Default, PartialEq)]
pub struct JobSpec {
pub active_deadline_seconds: Option<i64>,
pub backoff_limit: Option<i32>,
pub completions: Option<i32>,
pub manual_selector: Option<bool>,
pub parallelism: Option<i32>,
pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
pub template: crate::api::core::v1::PodTemplateSpec,
pub ttl_seconds_after_finished: Option<i32>,
}
impl<'de> serde::Deserialize<'de> for JobSpec {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
enum Field {
Key_active_deadline_seconds,
Key_backoff_limit,
Key_completions,
Key_manual_selector,
Key_parallelism,
Key_selector,
Key_template,
Key_ttl_seconds_after_finished,
Other,
}
impl<'de> serde::Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = Field;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("field identifier")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
Ok(match v {
"activeDeadlineSeconds" => Field::Key_active_deadline_seconds,
"backoffLimit" => Field::Key_backoff_limit,
"completions" => Field::Key_completions,
"manualSelector" => Field::Key_manual_selector,
"parallelism" => Field::Key_parallelism,
"selector" => Field::Key_selector,
"template" => Field::Key_template,
"ttlSecondsAfterFinished" => Field::Key_ttl_seconds_after_finished,
_ => Field::Other,
})
}
}
deserializer.deserialize_identifier(Visitor)
}
}
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = JobSpec;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("JobSpec")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
let mut value_active_deadline_seconds: Option<i64> = None;
let mut value_backoff_limit: Option<i32> = None;
let mut value_completions: Option<i32> = None;
let mut value_manual_selector: Option<bool> = None;
let mut value_parallelism: Option<i32> = None;
let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
let mut value_template: Option<crate::api::core::v1::PodTemplateSpec> = None;
let mut value_ttl_seconds_after_finished: Option<i32> = None;
while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_active_deadline_seconds => value_active_deadline_seconds = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_backoff_limit => value_backoff_limit = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_completions => value_completions = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_manual_selector => value_manual_selector = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_parallelism => value_parallelism = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_selector => value_selector = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_template => value_template = Some(serde::de::MapAccess::next_value(&mut map)?),
Field::Key_ttl_seconds_after_finished => value_ttl_seconds_after_finished = serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
}
}
Ok(JobSpec {
active_deadline_seconds: value_active_deadline_seconds,
backoff_limit: value_backoff_limit,
completions: value_completions,
manual_selector: value_manual_selector,
parallelism: value_parallelism,
selector: value_selector,
template: value_template.ok_or_else(|| serde::de::Error::missing_field("template"))?,
ttl_seconds_after_finished: value_ttl_seconds_after_finished,
})
}
}
deserializer.deserialize_struct(
"JobSpec",
&[
"activeDeadlineSeconds",
"backoffLimit",
"completions",
"manualSelector",
"parallelism",
"selector",
"template",
"ttlSecondsAfterFinished",
],
Visitor,
)
}
}
impl serde::Serialize for JobSpec {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut state = serializer.serialize_struct(
"JobSpec",
1 +
self.active_deadline_seconds.as_ref().map_or(0, |_| 1) +
self.backoff_limit.as_ref().map_or(0, |_| 1) +
self.completions.as_ref().map_or(0, |_| 1) +
self.manual_selector.as_ref().map_or(0, |_| 1) +
self.parallelism.as_ref().map_or(0, |_| 1) +
self.selector.as_ref().map_or(0, |_| 1) +
self.ttl_seconds_after_finished.as_ref().map_or(0, |_| 1),
)?;
if let Some(value) = &self.active_deadline_seconds {
serde::ser::SerializeStruct::serialize_field(&mut state, "activeDeadlineSeconds", value)?;
}
if let Some(value) = &self.backoff_limit {
serde::ser::SerializeStruct::serialize_field(&mut state, "backoffLimit", value)?;
}
if let Some(value) = &self.completions {
serde::ser::SerializeStruct::serialize_field(&mut state, "completions", value)?;
}
if let Some(value) = &self.manual_selector {
serde::ser::SerializeStruct::serialize_field(&mut state, "manualSelector", value)?;
}
if let Some(value) = &self.parallelism {
serde::ser::SerializeStruct::serialize_field(&mut state, "parallelism", value)?;
}
if let Some(value) = &self.selector {
serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
}
serde::ser::SerializeStruct::serialize_field(&mut state, "template", &self.template)?;
if let Some(value) = &self.ttl_seconds_after_finished {
serde::ser::SerializeStruct::serialize_field(&mut state, "ttlSecondsAfterFinished", value)?;
}
serde::ser::SerializeStruct::end(state)
}
}