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
177
178
#[derive(Clone, Debug, Default, PartialEq)]
pub struct DeploymentStatus {
pub available_replicas: Option<i32>,
pub collision_count: Option<i32>,
pub conditions: Option<Vec<crate::api::apps::v1::DeploymentCondition>>,
pub observed_generation: Option<i64>,
pub ready_replicas: Option<i32>,
pub replicas: Option<i32>,
pub unavailable_replicas: Option<i32>,
pub updated_replicas: Option<i32>,
}
impl<'de> serde::Deserialize<'de> for DeploymentStatus {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
enum Field {
Key_available_replicas,
Key_collision_count,
Key_conditions,
Key_observed_generation,
Key_ready_replicas,
Key_replicas,
Key_unavailable_replicas,
Key_updated_replicas,
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 {
"availableReplicas" => Field::Key_available_replicas,
"collisionCount" => Field::Key_collision_count,
"conditions" => Field::Key_conditions,
"observedGeneration" => Field::Key_observed_generation,
"readyReplicas" => Field::Key_ready_replicas,
"replicas" => Field::Key_replicas,
"unavailableReplicas" => Field::Key_unavailable_replicas,
"updatedReplicas" => Field::Key_updated_replicas,
_ => Field::Other,
})
}
}
deserializer.deserialize_identifier(Visitor)
}
}
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = DeploymentStatus;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("DeploymentStatus")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
let mut value_available_replicas: Option<i32> = None;
let mut value_collision_count: Option<i32> = None;
let mut value_conditions: Option<Vec<crate::api::apps::v1::DeploymentCondition>> = None;
let mut value_observed_generation: Option<i64> = None;
let mut value_ready_replicas: Option<i32> = None;
let mut value_replicas: Option<i32> = None;
let mut value_unavailable_replicas: Option<i32> = None;
let mut value_updated_replicas: Option<i32> = None;
while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_available_replicas => value_available_replicas = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_collision_count => value_collision_count = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_conditions => value_conditions = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_observed_generation => value_observed_generation = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_ready_replicas => value_ready_replicas = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_replicas => value_replicas = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_unavailable_replicas => value_unavailable_replicas = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_updated_replicas => value_updated_replicas = serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
}
}
Ok(DeploymentStatus {
available_replicas: value_available_replicas,
collision_count: value_collision_count,
conditions: value_conditions,
observed_generation: value_observed_generation,
ready_replicas: value_ready_replicas,
replicas: value_replicas,
unavailable_replicas: value_unavailable_replicas,
updated_replicas: value_updated_replicas,
})
}
}
deserializer.deserialize_struct(
"DeploymentStatus",
&[
"availableReplicas",
"collisionCount",
"conditions",
"observedGeneration",
"readyReplicas",
"replicas",
"unavailableReplicas",
"updatedReplicas",
],
Visitor,
)
}
}
impl serde::Serialize for DeploymentStatus {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut state = serializer.serialize_struct(
"DeploymentStatus",
self.available_replicas.as_ref().map_or(0, |_| 1) +
self.collision_count.as_ref().map_or(0, |_| 1) +
self.conditions.as_ref().map_or(0, |_| 1) +
self.observed_generation.as_ref().map_or(0, |_| 1) +
self.ready_replicas.as_ref().map_or(0, |_| 1) +
self.replicas.as_ref().map_or(0, |_| 1) +
self.unavailable_replicas.as_ref().map_or(0, |_| 1) +
self.updated_replicas.as_ref().map_or(0, |_| 1),
)?;
if let Some(value) = &self.available_replicas {
serde::ser::SerializeStruct::serialize_field(&mut state, "availableReplicas", value)?;
}
if let Some(value) = &self.collision_count {
serde::ser::SerializeStruct::serialize_field(&mut state, "collisionCount", value)?;
}
if let Some(value) = &self.conditions {
serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
}
if let Some(value) = &self.observed_generation {
serde::ser::SerializeStruct::serialize_field(&mut state, "observedGeneration", value)?;
}
if let Some(value) = &self.ready_replicas {
serde::ser::SerializeStruct::serialize_field(&mut state, "readyReplicas", value)?;
}
if let Some(value) = &self.replicas {
serde::ser::SerializeStruct::serialize_field(&mut state, "replicas", value)?;
}
if let Some(value) = &self.unavailable_replicas {
serde::ser::SerializeStruct::serialize_field(&mut state, "unavailableReplicas", value)?;
}
if let Some(value) = &self.updated_replicas {
serde::ser::SerializeStruct::serialize_field(&mut state, "updatedReplicas", value)?;
}
serde::ser::SerializeStruct::end(state)
}
}