k8s_openapi/v1_32/api/batch/v1/
success_policy.rs

1// Generated from definition io.k8s.api.batch.v1.SuccessPolicy
2
3/// SuccessPolicy describes when a Job can be declared as succeeded based on the success of some indexes.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct SuccessPolicy {
6    /// rules represents the list of alternative rules for the declaring the Jobs as successful before `.status.succeeded \>= .spec.completions`. Once any of the rules are met, the "SucceededCriteriaMet" condition is added, and the lingering pods are removed. The terminal state for such a Job has the "Complete" condition. Additionally, these rules are evaluated in order; Once the Job meets one of the rules, other rules are ignored. At most 20 elements are allowed.
7    pub rules: Vec<crate::api::batch::v1::SuccessPolicyRule>,
8}
9
10impl crate::DeepMerge for SuccessPolicy {
11    fn merge_from(&mut self, other: Self) {
12        crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
13    }
14}
15
16impl<'de> crate::serde::Deserialize<'de> for SuccessPolicy {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
18        #[allow(non_camel_case_types)]
19        enum Field {
20            Key_rules,
21            Other,
22        }
23
24        impl<'de> crate::serde::Deserialize<'de> for Field {
25            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26                struct Visitor;
27
28                impl crate::serde::de::Visitor<'_> for Visitor {
29                    type Value = Field;
30
31                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32                        f.write_str("field identifier")
33                    }
34
35                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
36                        Ok(match v {
37                            "rules" => Field::Key_rules,
38                            _ => Field::Other,
39                        })
40                    }
41                }
42
43                deserializer.deserialize_identifier(Visitor)
44            }
45        }
46
47        struct Visitor;
48
49        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
50            type Value = SuccessPolicy;
51
52            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53                f.write_str("SuccessPolicy")
54            }
55
56            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
57                let mut value_rules: Option<Vec<crate::api::batch::v1::SuccessPolicyRule>> = None;
58
59                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
60                    match key {
61                        Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
62                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
63                    }
64                }
65
66                Ok(SuccessPolicy {
67                    rules: value_rules.unwrap_or_default(),
68                })
69            }
70        }
71
72        deserializer.deserialize_struct(
73            "SuccessPolicy",
74            &[
75                "rules",
76            ],
77            Visitor,
78        )
79    }
80}
81
82impl crate::serde::Serialize for SuccessPolicy {
83    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
84        let mut state = serializer.serialize_struct(
85            "SuccessPolicy",
86            1,
87        )?;
88        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", &self.rules)?;
89        crate::serde::ser::SerializeStruct::end(state)
90    }
91}
92
93#[cfg(feature = "schemars")]
94impl crate::schemars::JsonSchema for SuccessPolicy {
95    fn schema_name() -> String {
96        "io.k8s.api.batch.v1.SuccessPolicy".to_owned()
97    }
98
99    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
100        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
101            metadata: Some(Box::new(crate::schemars::schema::Metadata {
102                description: Some("SuccessPolicy describes when a Job can be declared as succeeded based on the success of some indexes.".to_owned()),
103                ..Default::default()
104            })),
105            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
106            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
107                properties: [
108                    (
109                        "rules".to_owned(),
110                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
111                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
112                                description: Some("rules represents the list of alternative rules for the declaring the Jobs as successful before `.status.succeeded >= .spec.completions`. Once any of the rules are met, the \"SucceededCriteriaMet\" condition is added, and the lingering pods are removed. The terminal state for such a Job has the \"Complete\" condition. Additionally, these rules are evaluated in order; Once the Job meets one of the rules, other rules are ignored. At most 20 elements are allowed.".to_owned()),
113                                ..Default::default()
114                            })),
115                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
116                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
117                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::batch::v1::SuccessPolicyRule>()))),
118                                ..Default::default()
119                            })),
120                            ..Default::default()
121                        }),
122                    ),
123                ].into(),
124                required: [
125                    "rules".to_owned(),
126                ].into(),
127                ..Default::default()
128            })),
129            ..Default::default()
130        })
131    }
132}