k8s_openapi/v1_32/api/apps/v1/
stateful_set_spec.rs

1// Generated from definition io.k8s.api.apps.v1.StatefulSetSpec
2
3/// A StatefulSetSpec is the specification of a StatefulSet.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct StatefulSetSpec {
6    /// Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)
7    pub min_ready_seconds: Option<i32>,
8
9    /// ordinals controls the numbering of replica indices in a StatefulSet. The default ordinals behavior assigns a "0" index to the first replica and increments the index by one for each additional replica requested.
10    pub ordinals: Option<crate::api::apps::v1::StatefulSetOrdinals>,
11
12    /// persistentVolumeClaimRetentionPolicy describes the lifecycle of persistent volume claims created from volumeClaimTemplates. By default, all persistent volume claims are created as needed and retained until manually deleted. This policy allows the lifecycle to be altered, for example by deleting persistent volume claims when their stateful set is deleted, or when their pod is scaled down.
13    pub persistent_volume_claim_retention_policy: Option<crate::api::apps::v1::StatefulSetPersistentVolumeClaimRetentionPolicy>,
14
15    /// podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once.
16    pub pod_management_policy: Option<String>,
17
18    /// replicas is the desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1.
19    pub replicas: Option<i32>,
20
21    /// revisionHistoryLimit is the maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10.
22    pub revision_history_limit: Option<i32>,
23
24    /// selector is a label query over pods that should match the replica count. It must match the pod template's labels. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
25    pub selector: crate::apimachinery::pkg::apis::meta::v1::LabelSelector,
26
27    /// serviceName is the name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller.
28    pub service_name: String,
29
30    /// template is the object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the StatefulSet will fulfill this Template, but have a unique identity from the rest of the StatefulSet. Each pod will be named with the format \<statefulsetname\>-\<podindex\>. For example, a pod in a StatefulSet named "web" with index number "3" would be named "web-3". The only allowed template.spec.restartPolicy value is "Always".
31    pub template: crate::api::core::v1::PodTemplateSpec,
32
33    /// updateStrategy indicates the StatefulSetUpdateStrategy that will be employed to update Pods in the StatefulSet when a revision is made to Template.
34    pub update_strategy: Option<crate::api::apps::v1::StatefulSetUpdateStrategy>,
35
36    /// volumeClaimTemplates is a list of claims that pods are allowed to reference. The StatefulSet controller is responsible for mapping network identities to claims in a way that maintains the identity of a pod. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. A claim in this list takes precedence over any volumes in the template, with the same name.
37    pub volume_claim_templates: Option<Vec<crate::api::core::v1::PersistentVolumeClaim>>,
38}
39
40impl crate::DeepMerge for StatefulSetSpec {
41    fn merge_from(&mut self, other: Self) {
42        crate::DeepMerge::merge_from(&mut self.min_ready_seconds, other.min_ready_seconds);
43        crate::DeepMerge::merge_from(&mut self.ordinals, other.ordinals);
44        crate::DeepMerge::merge_from(&mut self.persistent_volume_claim_retention_policy, other.persistent_volume_claim_retention_policy);
45        crate::DeepMerge::merge_from(&mut self.pod_management_policy, other.pod_management_policy);
46        crate::DeepMerge::merge_from(&mut self.replicas, other.replicas);
47        crate::DeepMerge::merge_from(&mut self.revision_history_limit, other.revision_history_limit);
48        crate::DeepMerge::merge_from(&mut self.selector, other.selector);
49        crate::DeepMerge::merge_from(&mut self.service_name, other.service_name);
50        crate::DeepMerge::merge_from(&mut self.template, other.template);
51        crate::DeepMerge::merge_from(&mut self.update_strategy, other.update_strategy);
52        crate::merge_strategies::list::atomic(&mut self.volume_claim_templates, other.volume_claim_templates);
53    }
54}
55
56impl<'de> crate::serde::Deserialize<'de> for StatefulSetSpec {
57    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
58        #[allow(non_camel_case_types)]
59        enum Field {
60            Key_min_ready_seconds,
61            Key_ordinals,
62            Key_persistent_volume_claim_retention_policy,
63            Key_pod_management_policy,
64            Key_replicas,
65            Key_revision_history_limit,
66            Key_selector,
67            Key_service_name,
68            Key_template,
69            Key_update_strategy,
70            Key_volume_claim_templates,
71            Other,
72        }
73
74        impl<'de> crate::serde::Deserialize<'de> for Field {
75            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
76                struct Visitor;
77
78                impl crate::serde::de::Visitor<'_> for Visitor {
79                    type Value = Field;
80
81                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82                        f.write_str("field identifier")
83                    }
84
85                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
86                        Ok(match v {
87                            "minReadySeconds" => Field::Key_min_ready_seconds,
88                            "ordinals" => Field::Key_ordinals,
89                            "persistentVolumeClaimRetentionPolicy" => Field::Key_persistent_volume_claim_retention_policy,
90                            "podManagementPolicy" => Field::Key_pod_management_policy,
91                            "replicas" => Field::Key_replicas,
92                            "revisionHistoryLimit" => Field::Key_revision_history_limit,
93                            "selector" => Field::Key_selector,
94                            "serviceName" => Field::Key_service_name,
95                            "template" => Field::Key_template,
96                            "updateStrategy" => Field::Key_update_strategy,
97                            "volumeClaimTemplates" => Field::Key_volume_claim_templates,
98                            _ => Field::Other,
99                        })
100                    }
101                }
102
103                deserializer.deserialize_identifier(Visitor)
104            }
105        }
106
107        struct Visitor;
108
109        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
110            type Value = StatefulSetSpec;
111
112            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113                f.write_str("StatefulSetSpec")
114            }
115
116            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
117                let mut value_min_ready_seconds: Option<i32> = None;
118                let mut value_ordinals: Option<crate::api::apps::v1::StatefulSetOrdinals> = None;
119                let mut value_persistent_volume_claim_retention_policy: Option<crate::api::apps::v1::StatefulSetPersistentVolumeClaimRetentionPolicy> = None;
120                let mut value_pod_management_policy: Option<String> = None;
121                let mut value_replicas: Option<i32> = None;
122                let mut value_revision_history_limit: Option<i32> = None;
123                let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
124                let mut value_service_name: Option<String> = None;
125                let mut value_template: Option<crate::api::core::v1::PodTemplateSpec> = None;
126                let mut value_update_strategy: Option<crate::api::apps::v1::StatefulSetUpdateStrategy> = None;
127                let mut value_volume_claim_templates: Option<Vec<crate::api::core::v1::PersistentVolumeClaim>> = None;
128
129                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
130                    match key {
131                        Field::Key_min_ready_seconds => value_min_ready_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
132                        Field::Key_ordinals => value_ordinals = crate::serde::de::MapAccess::next_value(&mut map)?,
133                        Field::Key_persistent_volume_claim_retention_policy => value_persistent_volume_claim_retention_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
134                        Field::Key_pod_management_policy => value_pod_management_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
135                        Field::Key_replicas => value_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
136                        Field::Key_revision_history_limit => value_revision_history_limit = crate::serde::de::MapAccess::next_value(&mut map)?,
137                        Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
138                        Field::Key_service_name => value_service_name = crate::serde::de::MapAccess::next_value(&mut map)?,
139                        Field::Key_template => value_template = crate::serde::de::MapAccess::next_value(&mut map)?,
140                        Field::Key_update_strategy => value_update_strategy = crate::serde::de::MapAccess::next_value(&mut map)?,
141                        Field::Key_volume_claim_templates => value_volume_claim_templates = crate::serde::de::MapAccess::next_value(&mut map)?,
142                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
143                    }
144                }
145
146                Ok(StatefulSetSpec {
147                    min_ready_seconds: value_min_ready_seconds,
148                    ordinals: value_ordinals,
149                    persistent_volume_claim_retention_policy: value_persistent_volume_claim_retention_policy,
150                    pod_management_policy: value_pod_management_policy,
151                    replicas: value_replicas,
152                    revision_history_limit: value_revision_history_limit,
153                    selector: value_selector.unwrap_or_default(),
154                    service_name: value_service_name.unwrap_or_default(),
155                    template: value_template.unwrap_or_default(),
156                    update_strategy: value_update_strategy,
157                    volume_claim_templates: value_volume_claim_templates,
158                })
159            }
160        }
161
162        deserializer.deserialize_struct(
163            "StatefulSetSpec",
164            &[
165                "minReadySeconds",
166                "ordinals",
167                "persistentVolumeClaimRetentionPolicy",
168                "podManagementPolicy",
169                "replicas",
170                "revisionHistoryLimit",
171                "selector",
172                "serviceName",
173                "template",
174                "updateStrategy",
175                "volumeClaimTemplates",
176            ],
177            Visitor,
178        )
179    }
180}
181
182impl crate::serde::Serialize for StatefulSetSpec {
183    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
184        let mut state = serializer.serialize_struct(
185            "StatefulSetSpec",
186            3 +
187            self.min_ready_seconds.as_ref().map_or(0, |_| 1) +
188            self.ordinals.as_ref().map_or(0, |_| 1) +
189            self.persistent_volume_claim_retention_policy.as_ref().map_or(0, |_| 1) +
190            self.pod_management_policy.as_ref().map_or(0, |_| 1) +
191            self.replicas.as_ref().map_or(0, |_| 1) +
192            self.revision_history_limit.as_ref().map_or(0, |_| 1) +
193            self.update_strategy.as_ref().map_or(0, |_| 1) +
194            self.volume_claim_templates.as_ref().map_or(0, |_| 1),
195        )?;
196        if let Some(value) = &self.min_ready_seconds {
197            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minReadySeconds", value)?;
198        }
199        if let Some(value) = &self.ordinals {
200            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ordinals", value)?;
201        }
202        if let Some(value) = &self.persistent_volume_claim_retention_policy {
203            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "persistentVolumeClaimRetentionPolicy", value)?;
204        }
205        if let Some(value) = &self.pod_management_policy {
206            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podManagementPolicy", value)?;
207        }
208        if let Some(value) = &self.replicas {
209            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "replicas", value)?;
210        }
211        if let Some(value) = &self.revision_history_limit {
212            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "revisionHistoryLimit", value)?;
213        }
214        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", &self.selector)?;
215        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serviceName", &self.service_name)?;
216        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "template", &self.template)?;
217        if let Some(value) = &self.update_strategy {
218            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "updateStrategy", value)?;
219        }
220        if let Some(value) = &self.volume_claim_templates {
221            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeClaimTemplates", value)?;
222        }
223        crate::serde::ser::SerializeStruct::end(state)
224    }
225}
226
227#[cfg(feature = "schemars")]
228impl crate::schemars::JsonSchema for StatefulSetSpec {
229    fn schema_name() -> String {
230        "io.k8s.api.apps.v1.StatefulSetSpec".to_owned()
231    }
232
233    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
234        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
235            metadata: Some(Box::new(crate::schemars::schema::Metadata {
236                description: Some("A StatefulSetSpec is the specification of a StatefulSet.".to_owned()),
237                ..Default::default()
238            })),
239            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
240            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
241                properties: [
242                    (
243                        "minReadySeconds".to_owned(),
244                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
245                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
246                                description: Some("Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)".to_owned()),
247                                ..Default::default()
248                            })),
249                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
250                            format: Some("int32".to_owned()),
251                            ..Default::default()
252                        }),
253                    ),
254                    (
255                        "ordinals".to_owned(),
256                        {
257                            let mut schema_obj = __gen.subschema_for::<crate::api::apps::v1::StatefulSetOrdinals>().into_object();
258                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
259                                description: Some("ordinals controls the numbering of replica indices in a StatefulSet. The default ordinals behavior assigns a \"0\" index to the first replica and increments the index by one for each additional replica requested.".to_owned()),
260                                ..Default::default()
261                            }));
262                            crate::schemars::schema::Schema::Object(schema_obj)
263                        },
264                    ),
265                    (
266                        "persistentVolumeClaimRetentionPolicy".to_owned(),
267                        {
268                            let mut schema_obj = __gen.subschema_for::<crate::api::apps::v1::StatefulSetPersistentVolumeClaimRetentionPolicy>().into_object();
269                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
270                                description: Some("persistentVolumeClaimRetentionPolicy describes the lifecycle of persistent volume claims created from volumeClaimTemplates. By default, all persistent volume claims are created as needed and retained until manually deleted. This policy allows the lifecycle to be altered, for example by deleting persistent volume claims when their stateful set is deleted, or when their pod is scaled down.".to_owned()),
271                                ..Default::default()
272                            }));
273                            crate::schemars::schema::Schema::Object(schema_obj)
274                        },
275                    ),
276                    (
277                        "podManagementPolicy".to_owned(),
278                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
279                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
280                                description: Some("podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once.".to_owned()),
281                                ..Default::default()
282                            })),
283                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
284                            ..Default::default()
285                        }),
286                    ),
287                    (
288                        "replicas".to_owned(),
289                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
290                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
291                                description: Some("replicas is the desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1.".to_owned()),
292                                ..Default::default()
293                            })),
294                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
295                            format: Some("int32".to_owned()),
296                            ..Default::default()
297                        }),
298                    ),
299                    (
300                        "revisionHistoryLimit".to_owned(),
301                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
302                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
303                                description: Some("revisionHistoryLimit is the maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10.".to_owned()),
304                                ..Default::default()
305                            })),
306                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
307                            format: Some("int32".to_owned()),
308                            ..Default::default()
309                        }),
310                    ),
311                    (
312                        "selector".to_owned(),
313                        {
314                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
315                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
316                                description: Some("selector is a label query over pods that should match the replica count. It must match the pod template's labels. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors".to_owned()),
317                                ..Default::default()
318                            }));
319                            crate::schemars::schema::Schema::Object(schema_obj)
320                        },
321                    ),
322                    (
323                        "serviceName".to_owned(),
324                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
325                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
326                                description: Some("serviceName is the name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where \"pod-specific-string\" is managed by the StatefulSet controller.".to_owned()),
327                                ..Default::default()
328                            })),
329                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
330                            ..Default::default()
331                        }),
332                    ),
333                    (
334                        "template".to_owned(),
335                        {
336                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::PodTemplateSpec>().into_object();
337                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
338                                description: Some("template is the object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the StatefulSet will fulfill this Template, but have a unique identity from the rest of the StatefulSet. Each pod will be named with the format <statefulsetname>-<podindex>. For example, a pod in a StatefulSet named \"web\" with index number \"3\" would be named \"web-3\". The only allowed template.spec.restartPolicy value is \"Always\".".to_owned()),
339                                ..Default::default()
340                            }));
341                            crate::schemars::schema::Schema::Object(schema_obj)
342                        },
343                    ),
344                    (
345                        "updateStrategy".to_owned(),
346                        {
347                            let mut schema_obj = __gen.subschema_for::<crate::api::apps::v1::StatefulSetUpdateStrategy>().into_object();
348                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
349                                description: Some("updateStrategy indicates the StatefulSetUpdateStrategy that will be employed to update Pods in the StatefulSet when a revision is made to Template.".to_owned()),
350                                ..Default::default()
351                            }));
352                            crate::schemars::schema::Schema::Object(schema_obj)
353                        },
354                    ),
355                    (
356                        "volumeClaimTemplates".to_owned(),
357                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
358                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
359                                description: Some("volumeClaimTemplates is a list of claims that pods are allowed to reference. The StatefulSet controller is responsible for mapping network identities to claims in a way that maintains the identity of a pod. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. A claim in this list takes precedence over any volumes in the template, with the same name.".to_owned()),
360                                ..Default::default()
361                            })),
362                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
363                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
364                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::core::v1::PersistentVolumeClaim>()))),
365                                ..Default::default()
366                            })),
367                            ..Default::default()
368                        }),
369                    ),
370                ].into(),
371                required: [
372                    "selector".to_owned(),
373                    "serviceName".to_owned(),
374                    "template".to_owned(),
375                ].into(),
376                ..Default::default()
377            })),
378            ..Default::default()
379        })
380    }
381}