k8s_openapi/v1_30/api/batch/v1/
pod_failure_policy_rule.rs

1// Generated from definition io.k8s.api.batch.v1.PodFailurePolicyRule
2
3/// PodFailurePolicyRule describes how a pod failure is handled when the requirements are met. One of onExitCodes and onPodConditions, but not both, can be used in each rule.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodFailurePolicyRule {
6    /// Specifies the action taken on a pod failure when the requirements are satisfied. Possible values are:
7    ///
8    /// - FailJob: indicates that the pod's job is marked as Failed and all
9    ///   running pods are terminated.
10    /// - FailIndex: indicates that the pod's index is marked as Failed and will
11    ///   not be restarted.
12    ///   This value is beta-level. It can be used when the
13    ///   `JobBackoffLimitPerIndex` feature gate is enabled (enabled by default).
14    /// - Ignore: indicates that the counter towards the .backoffLimit is not
15    ///   incremented and a replacement pod is created.
16    /// - Count: indicates that the pod is handled in the default way - the
17    ///   counter towards the .backoffLimit is incremented.
18    /// Additional values are considered to be added in the future. Clients should react to an unknown action by skipping the rule.
19    pub action: std::string::String,
20
21    /// Represents the requirement on the container exit codes.
22    pub on_exit_codes: Option<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement>,
23
24    /// Represents the requirement on the pod conditions. The requirement is represented as a list of pod condition patterns. The requirement is satisfied if at least one pattern matches an actual pod condition. At most 20 elements are allowed.
25    pub on_pod_conditions: Option<std::vec::Vec<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>>,
26}
27
28impl crate::DeepMerge for PodFailurePolicyRule {
29    fn merge_from(&mut self, other: Self) {
30        crate::DeepMerge::merge_from(&mut self.action, other.action);
31        crate::DeepMerge::merge_from(&mut self.on_exit_codes, other.on_exit_codes);
32        crate::merge_strategies::list::atomic(&mut self.on_pod_conditions, other.on_pod_conditions);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for PodFailurePolicyRule {
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_action,
41            Key_on_exit_codes,
42            Key_on_pod_conditions,
43            Other,
44        }
45
46        impl<'de> crate::serde::Deserialize<'de> for Field {
47            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48                struct Visitor;
49
50                impl crate::serde::de::Visitor<'_> for Visitor {
51                    type Value = Field;
52
53                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
54                        f.write_str("field identifier")
55                    }
56
57                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
58                        Ok(match v {
59                            "action" => Field::Key_action,
60                            "onExitCodes" => Field::Key_on_exit_codes,
61                            "onPodConditions" => Field::Key_on_pod_conditions,
62                            _ => Field::Other,
63                        })
64                    }
65                }
66
67                deserializer.deserialize_identifier(Visitor)
68            }
69        }
70
71        struct Visitor;
72
73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74            type Value = PodFailurePolicyRule;
75
76            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77                f.write_str("PodFailurePolicyRule")
78            }
79
80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81                let mut value_action: Option<std::string::String> = None;
82                let mut value_on_exit_codes: Option<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement> = None;
83                let mut value_on_pod_conditions: Option<std::vec::Vec<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>> = None;
84
85                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
86                    match key {
87                        Field::Key_action => value_action = crate::serde::de::MapAccess::next_value(&mut map)?,
88                        Field::Key_on_exit_codes => value_on_exit_codes = crate::serde::de::MapAccess::next_value(&mut map)?,
89                        Field::Key_on_pod_conditions => value_on_pod_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
90                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
91                    }
92                }
93
94                Ok(PodFailurePolicyRule {
95                    action: value_action.unwrap_or_default(),
96                    on_exit_codes: value_on_exit_codes,
97                    on_pod_conditions: value_on_pod_conditions,
98                })
99            }
100        }
101
102        deserializer.deserialize_struct(
103            "PodFailurePolicyRule",
104            &[
105                "action",
106                "onExitCodes",
107                "onPodConditions",
108            ],
109            Visitor,
110        )
111    }
112}
113
114impl crate::serde::Serialize for PodFailurePolicyRule {
115    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
116        let mut state = serializer.serialize_struct(
117            "PodFailurePolicyRule",
118            1 +
119            self.on_exit_codes.as_ref().map_or(0, |_| 1) +
120            self.on_pod_conditions.as_ref().map_or(0, |_| 1),
121        )?;
122        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "action", &self.action)?;
123        if let Some(value) = &self.on_exit_codes {
124            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "onExitCodes", value)?;
125        }
126        if let Some(value) = &self.on_pod_conditions {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "onPodConditions", value)?;
128        }
129        crate::serde::ser::SerializeStruct::end(state)
130    }
131}
132
133#[cfg(feature = "schemars")]
134impl crate::schemars::JsonSchema for PodFailurePolicyRule {
135    fn schema_name() -> std::borrow::Cow<'static, str> {
136        "io.k8s.api.batch.v1.PodFailurePolicyRule".into()
137    }
138
139    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
140        crate::schemars::json_schema!({
141            "description": "PodFailurePolicyRule describes how a pod failure is handled when the requirements are met. One of onExitCodes and onPodConditions, but not both, can be used in each rule.",
142            "type": "object",
143            "properties": {
144                "action": {
145                    "description": "Specifies the action taken on a pod failure when the requirements are satisfied. Possible values are:\n\n- FailJob: indicates that the pod's job is marked as Failed and all\n  running pods are terminated.\n- FailIndex: indicates that the pod's index is marked as Failed and will\n  not be restarted.\n  This value is beta-level. It can be used when the\n  `JobBackoffLimitPerIndex` feature gate is enabled (enabled by default).\n- Ignore: indicates that the counter towards the .backoffLimit is not\n  incremented and a replacement pod is created.\n- Count: indicates that the pod is handled in the default way - the\n  counter towards the .backoffLimit is incremented.\nAdditional values are considered to be added in the future. Clients should react to an unknown action by skipping the rule.",
146                    "type": "string",
147                },
148                "onExitCodes": ({
149                    let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement>();
150                    schema_obj.ensure_object().insert("description".into(), "Represents the requirement on the container exit codes.".into());
151                    schema_obj
152                }),
153                "onPodConditions": {
154                    "description": "Represents the requirement on the pod conditions. The requirement is represented as a list of pod condition patterns. The requirement is satisfied if at least one pattern matches an actual pod condition. At most 20 elements are allowed.",
155                    "type": "array",
156                    "items": (__gen.subschema_for::<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>()),
157                },
158            },
159            "required": [
160                "action",
161            ],
162        })
163    }
164}