Skip to main content

openshift_openapi/v4_5/api/apps/v1/
exec_new_pod_hook.rs

1// Generated from definition com.github.openshift.api.apps.v1.ExecNewPodHook
2
3/// ExecNewPodHook is a hook implementation which runs a command in a new pod based on the specified container which is assumed to be part of the deployment template.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ExecNewPodHook {
6    /// Command is the action command and its arguments.
7    pub command: Vec<String>,
8
9    /// ContainerName is the name of a container in the deployment pod template whose container image will be used for the hook pod's container.
10    pub container_name: String,
11
12    /// Env is a set of environment variables to supply to the hook pod's container.
13    pub env: Option<Vec<k8s_openapi::api::core::v1::EnvVar>>,
14
15    /// Volumes is a list of named volumes from the pod template which should be copied to the hook pod. Volumes names not found in pod spec are ignored. An empty list means no volumes will be copied.
16    pub volumes: Option<Vec<String>>,
17}
18
19impl<'de> serde::Deserialize<'de> for ExecNewPodHook {
20    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
21        #[allow(non_camel_case_types)]
22        enum Field {
23            Key_command,
24            Key_container_name,
25            Key_env,
26            Key_volumes,
27            Other,
28        }
29
30        impl<'de> serde::Deserialize<'de> for Field {
31            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
32                struct Visitor;
33
34                impl<'de> serde::de::Visitor<'de> for Visitor {
35                    type Value = Field;
36
37                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38                        f.write_str("field identifier")
39                    }
40
41                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
42                        Ok(match v {
43                            "command" => Field::Key_command,
44                            "containerName" => Field::Key_container_name,
45                            "env" => Field::Key_env,
46                            "volumes" => Field::Key_volumes,
47                            _ => Field::Other,
48                        })
49                    }
50                }
51
52                deserializer.deserialize_identifier(Visitor)
53            }
54        }
55
56        struct Visitor;
57
58        impl<'de> serde::de::Visitor<'de> for Visitor {
59            type Value = ExecNewPodHook;
60
61            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62                f.write_str("ExecNewPodHook")
63            }
64
65            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
66                let mut value_command: Option<Vec<String>> = None;
67                let mut value_container_name: Option<String> = None;
68                let mut value_env: Option<Vec<k8s_openapi::api::core::v1::EnvVar>> = None;
69                let mut value_volumes: Option<Vec<String>> = None;
70
71                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
72                    match key {
73                        Field::Key_command => value_command = Some(serde::de::MapAccess::next_value(&mut map)?),
74                        Field::Key_container_name => value_container_name = Some(serde::de::MapAccess::next_value(&mut map)?),
75                        Field::Key_env => value_env = serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_volumes => value_volumes = serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
78                    }
79                }
80
81                Ok(ExecNewPodHook {
82                    command: value_command.ok_or_else(|| serde::de::Error::missing_field("command"))?,
83                    container_name: value_container_name.ok_or_else(|| serde::de::Error::missing_field("containerName"))?,
84                    env: value_env,
85                    volumes: value_volumes,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "ExecNewPodHook",
92            &[
93                "command",
94                "containerName",
95                "env",
96                "volumes",
97            ],
98            Visitor,
99        )
100    }
101}
102
103impl serde::Serialize for ExecNewPodHook {
104    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
105        let mut state = serializer.serialize_struct(
106            "ExecNewPodHook",
107            2 +
108            self.env.as_ref().map_or(0, |_| 1) +
109            self.volumes.as_ref().map_or(0, |_| 1),
110        )?;
111        serde::ser::SerializeStruct::serialize_field(&mut state, "command", &self.command)?;
112        serde::ser::SerializeStruct::serialize_field(&mut state, "containerName", &self.container_name)?;
113        if let Some(value) = &self.env {
114            serde::ser::SerializeStruct::serialize_field(&mut state, "env", value)?;
115        }
116        if let Some(value) = &self.volumes {
117            serde::ser::SerializeStruct::serialize_field(&mut state, "volumes", value)?;
118        }
119        serde::ser::SerializeStruct::end(state)
120    }
121}