1// Generated from definition io.k8s.api.coordination.v1beta1.LeaseCandidateSpec
23/// LeaseCandidateSpec is a specification of a Lease.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct LeaseCandidateSpec {
6/// BinaryVersion is the binary version. It must be in a semver format without leading `v`. This field is required.
7pub binary_version: std::string::String,
89/// EmulationVersion is the emulation version. It must be in a semver format without leading `v`. EmulationVersion must be less than or equal to BinaryVersion. This field is required when strategy is "OldestEmulationVersion"
10pub emulation_version: Option<std::string::String>,
1112/// LeaseName is the name of the lease for which this candidate is contending. The limits on this field are the same as on Lease.name. Multiple lease candidates may reference the same Lease.name. This field is immutable.
13pub lease_name: std::string::String,
1415/// PingTime is the last time that the server has requested the LeaseCandidate to renew. It is only done during leader election to check if any LeaseCandidates have become ineligible. When PingTime is updated, the LeaseCandidate will respond by updating RenewTime.
16pub ping_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime>,
1718/// RenewTime is the time that the LeaseCandidate was last updated. Any time a Lease needs to do leader election, the PingTime field is updated to signal to the LeaseCandidate that they should update the RenewTime. Old LeaseCandidate objects are also garbage collected if it has been hours since the last renew. The PingTime field is updated regularly to prevent garbage collection for still active LeaseCandidates.
19pub renew_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime>,
2021/// Strategy is the strategy that coordinated leader election will use for picking the leader. If multiple candidates for the same Lease return different strategies, the strategy provided by the candidate with the latest BinaryVersion will be used. If there is still conflict, this is a user error and coordinated leader election will not operate the Lease until resolved.
22pub strategy: std::string::String,
23}
2425impl crate::DeepMerge for LeaseCandidateSpec {
26fn merge_from(&mut self, other: Self) {
27crate::DeepMerge::merge_from(&mut self.binary_version, other.binary_version);
28crate::DeepMerge::merge_from(&mut self.emulation_version, other.emulation_version);
29crate::DeepMerge::merge_from(&mut self.lease_name, other.lease_name);
30crate::DeepMerge::merge_from(&mut self.ping_time, other.ping_time);
31crate::DeepMerge::merge_from(&mut self.renew_time, other.renew_time);
32crate::DeepMerge::merge_from(&mut self.strategy, other.strategy);
33 }
34}
3536impl<'de> crate::serde::Deserialize<'de> for LeaseCandidateSpec {
37fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38#[allow(non_camel_case_types)]
39enum Field {
40 Key_binary_version,
41 Key_emulation_version,
42 Key_lease_name,
43 Key_ping_time,
44 Key_renew_time,
45 Key_strategy,
46 Other,
47 }
4849impl<'de> crate::serde::Deserialize<'de> for Field {
50fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51struct Visitor;
5253impl crate::serde::de::Visitor<'_> for Visitor {
54type Value = Field;
5556fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57 f.write_str("field identifier")
58 }
5960fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61Ok(match v {
62"binaryVersion" => Field::Key_binary_version,
63"emulationVersion" => Field::Key_emulation_version,
64"leaseName" => Field::Key_lease_name,
65"pingTime" => Field::Key_ping_time,
66"renewTime" => Field::Key_renew_time,
67"strategy" => Field::Key_strategy,
68_ => Field::Other,
69 })
70 }
71 }
7273 deserializer.deserialize_identifier(Visitor)
74 }
75 }
7677struct Visitor;
7879impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80type Value = LeaseCandidateSpec;
8182fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83 f.write_str("LeaseCandidateSpec")
84 }
8586fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87let mut value_binary_version: Option<std::string::String> = None;
88let mut value_emulation_version: Option<std::string::String> = None;
89let mut value_lease_name: Option<std::string::String> = None;
90let mut value_ping_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime> = None;
91let mut value_renew_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime> = None;
92let mut value_strategy: Option<std::string::String> = None;
9394while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95match key {
96 Field::Key_binary_version => value_binary_version = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_emulation_version => value_emulation_version = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Key_lease_name => value_lease_name = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_ping_time => value_ping_time = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Key_renew_time => value_renew_time = crate::serde::de::MapAccess::next_value(&mut map)?,
101 Field::Key_strategy => value_strategy = crate::serde::de::MapAccess::next_value(&mut map)?,
102 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103 }
104 }
105106Ok(LeaseCandidateSpec {
107 binary_version: value_binary_version.unwrap_or_default(),
108 emulation_version: value_emulation_version,
109 lease_name: value_lease_name.unwrap_or_default(),
110 ping_time: value_ping_time,
111 renew_time: value_renew_time,
112 strategy: value_strategy.unwrap_or_default(),
113 })
114 }
115 }
116117 deserializer.deserialize_struct(
118"LeaseCandidateSpec",
119&[
120"binaryVersion",
121"emulationVersion",
122"leaseName",
123"pingTime",
124"renewTime",
125"strategy",
126 ],
127 Visitor,
128 )
129 }
130}
131132impl crate::serde::Serialize for LeaseCandidateSpec {
133fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134let mut state = serializer.serialize_struct(
135"LeaseCandidateSpec",
1363 +
137self.emulation_version.as_ref().map_or(0, |_| 1) +
138self.ping_time.as_ref().map_or(0, |_| 1) +
139self.renew_time.as_ref().map_or(0, |_| 1),
140 )?;
141crate::serde::ser::SerializeStruct::serialize_field(&mut state, "binaryVersion", &self.binary_version)?;
142if let Some(value) = &self.emulation_version {
143crate::serde::ser::SerializeStruct::serialize_field(&mut state, "emulationVersion", value)?;
144 }
145crate::serde::ser::SerializeStruct::serialize_field(&mut state, "leaseName", &self.lease_name)?;
146if let Some(value) = &self.ping_time {
147crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pingTime", value)?;
148 }
149if let Some(value) = &self.renew_time {
150crate::serde::ser::SerializeStruct::serialize_field(&mut state, "renewTime", value)?;
151 }
152crate::serde::ser::SerializeStruct::serialize_field(&mut state, "strategy", &self.strategy)?;
153crate::serde::ser::SerializeStruct::end(state)
154 }
155}
156157#[cfg(feature = "schemars")]
158impl crate::schemars::JsonSchema for LeaseCandidateSpec {
159fn schema_name() -> std::string::String {
160"io.k8s.api.coordination.v1beta1.LeaseCandidateSpec".into()
161 }
162163fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
164crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
165 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
166 description: Some("LeaseCandidateSpec is a specification of a Lease.".into()),
167 ..Default::default()
168 })),
169 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
170 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
171 properties: [
172 (
173"binaryVersion".into(),
174crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
175 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
176 description: Some("BinaryVersion is the binary version. It must be in a semver format without leading `v`. This field is required.".into()),
177 ..Default::default()
178 })),
179 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
180 ..Default::default()
181 }),
182 ),
183 (
184"emulationVersion".into(),
185crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
186 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
187 description: Some("EmulationVersion is the emulation version. It must be in a semver format without leading `v`. EmulationVersion must be less than or equal to BinaryVersion. This field is required when strategy is \"OldestEmulationVersion\"".into()),
188 ..Default::default()
189 })),
190 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
191 ..Default::default()
192 }),
193 ),
194 (
195"leaseName".into(),
196crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
197 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
198 description: Some("LeaseName is the name of the lease for which this candidate is contending. The limits on this field are the same as on Lease.name. Multiple lease candidates may reference the same Lease.name. This field is immutable.".into()),
199 ..Default::default()
200 })),
201 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
202 ..Default::default()
203 }),
204 ),
205 (
206"pingTime".into(),
207 {
208let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::MicroTime>().into_object();
209 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
210 description: Some("PingTime is the last time that the server has requested the LeaseCandidate to renew. It is only done during leader election to check if any LeaseCandidates have become ineligible. When PingTime is updated, the LeaseCandidate will respond by updating RenewTime.".into()),
211 ..Default::default()
212 }));
213crate::schemars::schema::Schema::Object(schema_obj)
214 },
215 ),
216 (
217"renewTime".into(),
218 {
219let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::MicroTime>().into_object();
220 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
221 description: Some("RenewTime is the time that the LeaseCandidate was last updated. Any time a Lease needs to do leader election, the PingTime field is updated to signal to the LeaseCandidate that they should update the RenewTime. Old LeaseCandidate objects are also garbage collected if it has been hours since the last renew. The PingTime field is updated regularly to prevent garbage collection for still active LeaseCandidates.".into()),
222 ..Default::default()
223 }));
224crate::schemars::schema::Schema::Object(schema_obj)
225 },
226 ),
227 (
228"strategy".into(),
229crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
230 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
231 description: Some("Strategy is the strategy that coordinated leader election will use for picking the leader. If multiple candidates for the same Lease return different strategies, the strategy provided by the candidate with the latest BinaryVersion will be used. If there is still conflict, this is a user error and coordinated leader election will not operate the Lease until resolved.".into()),
232 ..Default::default()
233 })),
234 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
235 ..Default::default()
236 }),
237 ),
238 ].into(),
239 required: [
240"binaryVersion".into(),
241"leaseName".into(),
242"strategy".into(),
243 ].into(),
244 ..Default::default()
245 })),
246 ..Default::default()
247 })
248 }
249}