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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#[derive(Clone, Debug, Default, PartialEq)]
pub struct NodeStatus {
pub addresses: Option<Vec<crate::api::core::v1::NodeAddress>>,
pub allocatable: Option<std::collections::BTreeMap<String, crate::apimachinery::pkg::api::resource::Quantity>>,
pub capacity: Option<std::collections::BTreeMap<String, crate::apimachinery::pkg::api::resource::Quantity>>,
pub conditions: Option<Vec<crate::api::core::v1::NodeCondition>>,
pub config: Option<crate::api::core::v1::NodeConfigStatus>,
pub daemon_endpoints: Option<crate::api::core::v1::NodeDaemonEndpoints>,
pub images: Option<Vec<crate::api::core::v1::ContainerImage>>,
pub node_info: Option<crate::api::core::v1::NodeSystemInfo>,
pub phase: Option<String>,
pub volumes_attached: Option<Vec<crate::api::core::v1::AttachedVolume>>,
pub volumes_in_use: Option<Vec<String>>,
}
impl<'de> serde::Deserialize<'de> for NodeStatus {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
enum Field {
Key_addresses,
Key_allocatable,
Key_capacity,
Key_conditions,
Key_config,
Key_daemon_endpoints,
Key_images,
Key_node_info,
Key_phase,
Key_volumes_attached,
Key_volumes_in_use,
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 {
"addresses" => Field::Key_addresses,
"allocatable" => Field::Key_allocatable,
"capacity" => Field::Key_capacity,
"conditions" => Field::Key_conditions,
"config" => Field::Key_config,
"daemonEndpoints" => Field::Key_daemon_endpoints,
"images" => Field::Key_images,
"nodeInfo" => Field::Key_node_info,
"phase" => Field::Key_phase,
"volumesAttached" => Field::Key_volumes_attached,
"volumesInUse" => Field::Key_volumes_in_use,
_ => Field::Other,
})
}
}
deserializer.deserialize_identifier(Visitor)
}
}
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = NodeStatus;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("NodeStatus")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
let mut value_addresses: Option<Vec<crate::api::core::v1::NodeAddress>> = None;
let mut value_allocatable: Option<std::collections::BTreeMap<String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
let mut value_capacity: Option<std::collections::BTreeMap<String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
let mut value_conditions: Option<Vec<crate::api::core::v1::NodeCondition>> = None;
let mut value_config: Option<crate::api::core::v1::NodeConfigStatus> = None;
let mut value_daemon_endpoints: Option<crate::api::core::v1::NodeDaemonEndpoints> = None;
let mut value_images: Option<Vec<crate::api::core::v1::ContainerImage>> = None;
let mut value_node_info: Option<crate::api::core::v1::NodeSystemInfo> = None;
let mut value_phase: Option<String> = None;
let mut value_volumes_attached: Option<Vec<crate::api::core::v1::AttachedVolume>> = None;
let mut value_volumes_in_use: Option<Vec<String>> = None;
while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_addresses => value_addresses = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_allocatable => value_allocatable = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_capacity => value_capacity = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_conditions => value_conditions = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_config => value_config = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_daemon_endpoints => value_daemon_endpoints = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_images => value_images = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_node_info => value_node_info = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_phase => value_phase = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_volumes_attached => value_volumes_attached = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_volumes_in_use => value_volumes_in_use = serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
}
}
Ok(NodeStatus {
addresses: value_addresses,
allocatable: value_allocatable,
capacity: value_capacity,
conditions: value_conditions,
config: value_config,
daemon_endpoints: value_daemon_endpoints,
images: value_images,
node_info: value_node_info,
phase: value_phase,
volumes_attached: value_volumes_attached,
volumes_in_use: value_volumes_in_use,
})
}
}
deserializer.deserialize_struct(
"NodeStatus",
&[
"addresses",
"allocatable",
"capacity",
"conditions",
"config",
"daemonEndpoints",
"images",
"nodeInfo",
"phase",
"volumesAttached",
"volumesInUse",
],
Visitor,
)
}
}
impl serde::Serialize for NodeStatus {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut state = serializer.serialize_struct(
"NodeStatus",
self.addresses.as_ref().map_or(0, |_| 1) +
self.allocatable.as_ref().map_or(0, |_| 1) +
self.capacity.as_ref().map_or(0, |_| 1) +
self.conditions.as_ref().map_or(0, |_| 1) +
self.config.as_ref().map_or(0, |_| 1) +
self.daemon_endpoints.as_ref().map_or(0, |_| 1) +
self.images.as_ref().map_or(0, |_| 1) +
self.node_info.as_ref().map_or(0, |_| 1) +
self.phase.as_ref().map_or(0, |_| 1) +
self.volumes_attached.as_ref().map_or(0, |_| 1) +
self.volumes_in_use.as_ref().map_or(0, |_| 1),
)?;
if let Some(value) = &self.addresses {
serde::ser::SerializeStruct::serialize_field(&mut state, "addresses", value)?;
}
if let Some(value) = &self.allocatable {
serde::ser::SerializeStruct::serialize_field(&mut state, "allocatable", value)?;
}
if let Some(value) = &self.capacity {
serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
}
if let Some(value) = &self.conditions {
serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
}
if let Some(value) = &self.config {
serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
}
if let Some(value) = &self.daemon_endpoints {
serde::ser::SerializeStruct::serialize_field(&mut state, "daemonEndpoints", value)?;
}
if let Some(value) = &self.images {
serde::ser::SerializeStruct::serialize_field(&mut state, "images", value)?;
}
if let Some(value) = &self.node_info {
serde::ser::SerializeStruct::serialize_field(&mut state, "nodeInfo", value)?;
}
if let Some(value) = &self.phase {
serde::ser::SerializeStruct::serialize_field(&mut state, "phase", value)?;
}
if let Some(value) = &self.volumes_attached {
serde::ser::SerializeStruct::serialize_field(&mut state, "volumesAttached", value)?;
}
if let Some(value) = &self.volumes_in_use {
serde::ser::SerializeStruct::serialize_field(&mut state, "volumesInUse", value)?;
}
serde::ser::SerializeStruct::end(state)
}
}