k8s_openapi/v1_33/api/coordination/v1beta1/
lease_candidate_spec.rs

1// Generated from definition io.k8s.api.coordination.v1beta1.LeaseCandidateSpec
2
3/// 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.
7    pub binary_version: std::string::String,
8
9    /// 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"
10    pub emulation_version: Option<std::string::String>,
11
12    /// 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.
13    pub lease_name: std::string::String,
14
15    /// 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.
16    pub ping_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime>,
17
18    /// 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.
19    pub renew_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime>,
20
21    /// 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.
22    pub strategy: std::string::String,
23}
24
25impl crate::DeepMerge for LeaseCandidateSpec {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.binary_version, other.binary_version);
28        crate::DeepMerge::merge_from(&mut self.emulation_version, other.emulation_version);
29        crate::DeepMerge::merge_from(&mut self.lease_name, other.lease_name);
30        crate::DeepMerge::merge_from(&mut self.ping_time, other.ping_time);
31        crate::DeepMerge::merge_from(&mut self.renew_time, other.renew_time);
32        crate::DeepMerge::merge_from(&mut self.strategy, other.strategy);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for LeaseCandidateSpec {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum 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        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(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                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = LeaseCandidateSpec;
81
82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83                f.write_str("LeaseCandidateSpec")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_binary_version: Option<std::string::String> = None;
88                let mut value_emulation_version: Option<std::string::String> = None;
89                let mut value_lease_name: Option<std::string::String> = None;
90                let mut value_ping_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime> = None;
91                let mut value_renew_time: Option<crate::apimachinery::pkg::apis::meta::v1::MicroTime> = None;
92                let mut value_strategy: Option<std::string::String> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match 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                }
105
106                Ok(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        }
116
117        deserializer.deserialize_struct(
118            "LeaseCandidateSpec",
119            &[
120                "binaryVersion",
121                "emulationVersion",
122                "leaseName",
123                "pingTime",
124                "renewTime",
125                "strategy",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl crate::serde::Serialize for LeaseCandidateSpec {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "LeaseCandidateSpec",
136            3 +
137            self.emulation_version.as_ref().map_or(0, |_| 1) +
138            self.ping_time.as_ref().map_or(0, |_| 1) +
139            self.renew_time.as_ref().map_or(0, |_| 1),
140        )?;
141        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "binaryVersion", &self.binary_version)?;
142        if let Some(value) = &self.emulation_version {
143            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "emulationVersion", value)?;
144        }
145        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "leaseName", &self.lease_name)?;
146        if let Some(value) = &self.ping_time {
147            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pingTime", value)?;
148        }
149        if let Some(value) = &self.renew_time {
150            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "renewTime", value)?;
151        }
152        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "strategy", &self.strategy)?;
153        crate::serde::ser::SerializeStruct::end(state)
154    }
155}
156
157#[cfg(feature = "schemars")]
158impl crate::schemars::JsonSchema for LeaseCandidateSpec {
159    fn schema_name() -> std::string::String {
160        "io.k8s.api.coordination.v1beta1.LeaseCandidateSpec".into()
161    }
162
163    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
164        crate::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(),
174                        crate::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(),
185                        crate::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(),
196                        crate::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                        {
208                            let 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                            }));
213                            crate::schemars::schema::Schema::Object(schema_obj)
214                        },
215                    ),
216                    (
217                        "renewTime".into(),
218                        {
219                            let 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                            }));
224                            crate::schemars::schema::Schema::Object(schema_obj)
225                        },
226                    ),
227                    (
228                        "strategy".into(),
229                        crate::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}