k8s_openapi/v1_34/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::borrow::Cow<'static, str> {
160        "io.k8s.api.coordination.v1beta1.LeaseCandidateSpec".into()
161    }
162
163    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
164        crate::schemars::json_schema!({
165            "description": "LeaseCandidateSpec is a specification of a Lease.",
166            "type": "object",
167            "properties": {
168                "binaryVersion": {
169                    "description": "BinaryVersion is the binary version. It must be in a semver format without leading `v`. This field is required.",
170                    "type": "string",
171                },
172                "emulationVersion": {
173                    "description": "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\"",
174                    "type": "string",
175                },
176                "leaseName": {
177                    "description": "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.",
178                    "type": "string",
179                },
180                "pingTime": ({
181                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::MicroTime>();
182                    schema_obj.ensure_object().insert("description".into(), "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());
183                    schema_obj
184                }),
185                "renewTime": ({
186                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::MicroTime>();
187                    schema_obj.ensure_object().insert("description".into(), "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());
188                    schema_obj
189                }),
190                "strategy": {
191                    "description": "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.",
192                    "type": "string",
193                },
194            },
195            "required": [
196                "binaryVersion",
197                "leaseName",
198                "strategy",
199            ],
200        })
201    }
202}