k8s_openapi/v1_34/api/batch/v1/
pod_failure_policy_rule.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodFailurePolicyRule {
6 pub action: std::string::String,
18
19 pub on_exit_codes: Option<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement>,
21
22 pub on_pod_conditions: Option<std::vec::Vec<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>>,
24}
25
26impl crate::DeepMerge for PodFailurePolicyRule {
27 fn merge_from(&mut self, other: Self) {
28 crate::DeepMerge::merge_from(&mut self.action, other.action);
29 crate::DeepMerge::merge_from(&mut self.on_exit_codes, other.on_exit_codes);
30 crate::merge_strategies::list::atomic(&mut self.on_pod_conditions, other.on_pod_conditions);
31 }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for PodFailurePolicyRule {
35 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36 #[allow(non_camel_case_types)]
37 enum Field {
38 Key_action,
39 Key_on_exit_codes,
40 Key_on_pod_conditions,
41 Other,
42 }
43
44 impl<'de> crate::serde::Deserialize<'de> for Field {
45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46 struct Visitor;
47
48 impl crate::serde::de::Visitor<'_> for Visitor {
49 type Value = Field;
50
51 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 f.write_str("field identifier")
53 }
54
55 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56 Ok(match v {
57 "action" => Field::Key_action,
58 "onExitCodes" => Field::Key_on_exit_codes,
59 "onPodConditions" => Field::Key_on_pod_conditions,
60 _ => Field::Other,
61 })
62 }
63 }
64
65 deserializer.deserialize_identifier(Visitor)
66 }
67 }
68
69 struct Visitor;
70
71 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
72 type Value = PodFailurePolicyRule;
73
74 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
75 f.write_str("PodFailurePolicyRule")
76 }
77
78 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
79 let mut value_action: Option<std::string::String> = None;
80 let mut value_on_exit_codes: Option<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement> = None;
81 let mut value_on_pod_conditions: Option<std::vec::Vec<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>> = None;
82
83 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
84 match key {
85 Field::Key_action => value_action = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Key_on_exit_codes => value_on_exit_codes = crate::serde::de::MapAccess::next_value(&mut map)?,
87 Field::Key_on_pod_conditions => value_on_pod_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
88 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
89 }
90 }
91
92 Ok(PodFailurePolicyRule {
93 action: value_action.unwrap_or_default(),
94 on_exit_codes: value_on_exit_codes,
95 on_pod_conditions: value_on_pod_conditions,
96 })
97 }
98 }
99
100 deserializer.deserialize_struct(
101 "PodFailurePolicyRule",
102 &[
103 "action",
104 "onExitCodes",
105 "onPodConditions",
106 ],
107 Visitor,
108 )
109 }
110}
111
112impl crate::serde::Serialize for PodFailurePolicyRule {
113 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114 let mut state = serializer.serialize_struct(
115 "PodFailurePolicyRule",
116 1 +
117 self.on_exit_codes.as_ref().map_or(0, |_| 1) +
118 self.on_pod_conditions.as_ref().map_or(0, |_| 1),
119 )?;
120 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "action", &self.action)?;
121 if let Some(value) = &self.on_exit_codes {
122 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "onExitCodes", value)?;
123 }
124 if let Some(value) = &self.on_pod_conditions {
125 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "onPodConditions", value)?;
126 }
127 crate::serde::ser::SerializeStruct::end(state)
128 }
129}
130
131#[cfg(feature = "schemars")]
132impl crate::schemars::JsonSchema for PodFailurePolicyRule {
133 fn schema_name() -> std::borrow::Cow<'static, str> {
134 "io.k8s.api.batch.v1.PodFailurePolicyRule".into()
135 }
136
137 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
138 crate::schemars::json_schema!({
139 "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.",
140 "type": "object",
141 "properties": {
142 "action": {
143 "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- 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.",
144 "type": "string",
145 },
146 "onExitCodes": ({
147 let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::PodFailurePolicyOnExitCodesRequirement>();
148 schema_obj.ensure_object().insert("description".into(), "Represents the requirement on the container exit codes.".into());
149 schema_obj
150 }),
151 "onPodConditions": {
152 "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.",
153 "type": "array",
154 "items": (__gen.subschema_for::<crate::api::batch::v1::PodFailurePolicyOnPodConditionsPattern>()),
155 },
156 },
157 "required": [
158 "action",
159 ],
160 })
161 }
162}