1// Generated from definition io.k8s.api.core.v1.Lifecycle
23/// Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Lifecycle {
6/// PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
7pub post_start: Option<crate::api::core::v1::LifecycleHandler>,
89/// PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The Pod's termination grace period countdown begins before the PreStop hook is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period (unless delayed by finalizers). Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
10pub pre_stop: Option<crate::api::core::v1::LifecycleHandler>,
1112/// StopSignal defines which signal will be sent to a container when it is being stopped. If not specified, the default is defined by the container runtime in use. StopSignal can only be set for Pods with a non-empty .spec.os.name
13pub stop_signal: Option<std::string::String>,
14}
1516impl crate::DeepMerge for Lifecycle {
17fn merge_from(&mut self, other: Self) {
18crate::DeepMerge::merge_from(&mut self.post_start, other.post_start);
19crate::DeepMerge::merge_from(&mut self.pre_stop, other.pre_stop);
20crate::DeepMerge::merge_from(&mut self.stop_signal, other.stop_signal);
21 }
22}
2324impl<'de> crate::serde::Deserialize<'de> for Lifecycle {
25fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26#[allow(non_camel_case_types)]
27enum Field {
28 Key_post_start,
29 Key_pre_stop,
30 Key_stop_signal,
31 Other,
32 }
3334impl<'de> crate::serde::Deserialize<'de> for Field {
35fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36struct Visitor;
3738impl crate::serde::de::Visitor<'_> for Visitor {
39type Value = Field;
4041fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42 f.write_str("field identifier")
43 }
4445fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46Ok(match v {
47"postStart" => Field::Key_post_start,
48"preStop" => Field::Key_pre_stop,
49"stopSignal" => Field::Key_stop_signal,
50_ => Field::Other,
51 })
52 }
53 }
5455 deserializer.deserialize_identifier(Visitor)
56 }
57 }
5859struct Visitor;
6061impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62type Value = Lifecycle;
6364fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 f.write_str("Lifecycle")
66 }
6768fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69let mut value_post_start: Option<crate::api::core::v1::LifecycleHandler> = None;
70let mut value_pre_stop: Option<crate::api::core::v1::LifecycleHandler> = None;
71let mut value_stop_signal: Option<std::string::String> = None;
7273while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74match key {
75 Field::Key_post_start => value_post_start = crate::serde::de::MapAccess::next_value(&mut map)?,
76 Field::Key_pre_stop => value_pre_stop = crate::serde::de::MapAccess::next_value(&mut map)?,
77 Field::Key_stop_signal => value_stop_signal = crate::serde::de::MapAccess::next_value(&mut map)?,
78 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79 }
80 }
8182Ok(Lifecycle {
83 post_start: value_post_start,
84 pre_stop: value_pre_stop,
85 stop_signal: value_stop_signal,
86 })
87 }
88 }
8990 deserializer.deserialize_struct(
91"Lifecycle",
92&[
93"postStart",
94"preStop",
95"stopSignal",
96 ],
97 Visitor,
98 )
99 }
100}
101102impl crate::serde::Serialize for Lifecycle {
103fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104let mut state = serializer.serialize_struct(
105"Lifecycle",
106self.post_start.as_ref().map_or(0, |_| 1) +
107self.pre_stop.as_ref().map_or(0, |_| 1) +
108self.stop_signal.as_ref().map_or(0, |_| 1),
109 )?;
110if let Some(value) = &self.post_start {
111crate::serde::ser::SerializeStruct::serialize_field(&mut state, "postStart", value)?;
112 }
113if let Some(value) = &self.pre_stop {
114crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preStop", value)?;
115 }
116if let Some(value) = &self.stop_signal {
117crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stopSignal", value)?;
118 }
119crate::serde::ser::SerializeStruct::end(state)
120 }
121}
122123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for Lifecycle {
125fn schema_name() -> std::string::String {
126"io.k8s.api.core.v1.Lifecycle".into()
127 }
128129fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
130crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
131 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
132 description: Some("Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.".into()),
133 ..Default::default()
134 })),
135 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
136 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
137 properties: [
138 (
139"postStart".into(),
140 {
141let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LifecycleHandler>().into_object();
142 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
143 description: Some("PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks".into()),
144 ..Default::default()
145 }));
146crate::schemars::schema::Schema::Object(schema_obj)
147 },
148 ),
149 (
150"preStop".into(),
151 {
152let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LifecycleHandler>().into_object();
153 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
154 description: Some("PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The Pod's termination grace period countdown begins before the PreStop hook is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period (unless delayed by finalizers). Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks".into()),
155 ..Default::default()
156 }));
157crate::schemars::schema::Schema::Object(schema_obj)
158 },
159 ),
160 (
161"stopSignal".into(),
162crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
164 description: Some("StopSignal defines which signal will be sent to a container when it is being stopped. If not specified, the default is defined by the container runtime in use. StopSignal can only be set for Pods with a non-empty .spec.os.name".into()),
165 ..Default::default()
166 })),
167 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
168 ..Default::default()
169 }),
170 ),
171 ].into(),
172 ..Default::default()
173 })),
174 ..Default::default()
175 })
176 }
177}