k8s_openapi/v1_35/api/core/v1/
image_volume_source.rs

1// Generated from definition io.k8s.api.core.v1.ImageVolumeSource
2
3/// ImageVolumeSource represents a image volume resource.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ImageVolumeSource {
6    /// Policy for pulling OCI objects. Possible values are: Always: the kubelet always attempts to pull the reference. Container creation will fail If the pull fails. Never: the kubelet never pulls the reference and only uses a local image or artifact. Container creation will fail if the reference isn't present. IfNotPresent: the kubelet pulls if the reference isn't already present on disk. Container creation will fail if the reference isn't present and the pull fails. Defaults to Always if :latest tag is specified, or IfNotPresent otherwise.
7    pub pull_policy: Option<std::string::String>,
8
9    /// Required: Image or artifact reference to be used. Behaves in the same way as pod.spec.containers\[*\].image. Pull secrets will be assembled in the same way as for the container image by looking up node credentials, SA image pull secrets, and pod spec image pull secrets. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.
10    pub reference: Option<std::string::String>,
11}
12
13impl crate::DeepMerge for ImageVolumeSource {
14    fn merge_from(&mut self, other: Self) {
15        crate::DeepMerge::merge_from(&mut self.pull_policy, other.pull_policy);
16        crate::DeepMerge::merge_from(&mut self.reference, other.reference);
17    }
18}
19
20impl<'de> crate::serde::Deserialize<'de> for ImageVolumeSource {
21    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
22        #[allow(non_camel_case_types)]
23        enum Field {
24            Key_pull_policy,
25            Key_reference,
26            Other,
27        }
28
29        impl<'de> crate::serde::Deserialize<'de> for Field {
30            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31                struct Visitor;
32
33                impl crate::serde::de::Visitor<'_> for Visitor {
34                    type Value = Field;
35
36                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37                        f.write_str("field identifier")
38                    }
39
40                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
41                        Ok(match v {
42                            "pullPolicy" => Field::Key_pull_policy,
43                            "reference" => Field::Key_reference,
44                            _ => Field::Other,
45                        })
46                    }
47                }
48
49                deserializer.deserialize_identifier(Visitor)
50            }
51        }
52
53        struct Visitor;
54
55        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
56            type Value = ImageVolumeSource;
57
58            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59                f.write_str("ImageVolumeSource")
60            }
61
62            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
63                let mut value_pull_policy: Option<std::string::String> = None;
64                let mut value_reference: Option<std::string::String> = None;
65
66                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
67                    match key {
68                        Field::Key_pull_policy => value_pull_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
69                        Field::Key_reference => value_reference = crate::serde::de::MapAccess::next_value(&mut map)?,
70                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
71                    }
72                }
73
74                Ok(ImageVolumeSource {
75                    pull_policy: value_pull_policy,
76                    reference: value_reference,
77                })
78            }
79        }
80
81        deserializer.deserialize_struct(
82            "ImageVolumeSource",
83            &[
84                "pullPolicy",
85                "reference",
86            ],
87            Visitor,
88        )
89    }
90}
91
92impl crate::serde::Serialize for ImageVolumeSource {
93    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
94        let mut state = serializer.serialize_struct(
95            "ImageVolumeSource",
96            self.pull_policy.as_ref().map_or(0, |_| 1) +
97            self.reference.as_ref().map_or(0, |_| 1),
98        )?;
99        if let Some(value) = &self.pull_policy {
100            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pullPolicy", value)?;
101        }
102        if let Some(value) = &self.reference {
103            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reference", value)?;
104        }
105        crate::serde::ser::SerializeStruct::end(state)
106    }
107}
108
109#[cfg(feature = "schemars")]
110impl crate::schemars::JsonSchema for ImageVolumeSource {
111    fn schema_name() -> std::borrow::Cow<'static, str> {
112        "io.k8s.api.core.v1.ImageVolumeSource".into()
113    }
114
115    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
116        crate::schemars::json_schema!({
117            "description": "ImageVolumeSource represents a image volume resource.",
118            "type": "object",
119            "properties": {
120                "pullPolicy": {
121                    "description": "Policy for pulling OCI objects. Possible values are: Always: the kubelet always attempts to pull the reference. Container creation will fail If the pull fails. Never: the kubelet never pulls the reference and only uses a local image or artifact. Container creation will fail if the reference isn't present. IfNotPresent: the kubelet pulls if the reference isn't already present on disk. Container creation will fail if the reference isn't present and the pull fails. Defaults to Always if :latest tag is specified, or IfNotPresent otherwise.",
122                    "type": "string",
123                },
124                "reference": {
125                    "description": "Required: Image or artifact reference to be used. Behaves in the same way as pod.spec.containers[*].image. Pull secrets will be assembled in the same way as for the container image by looking up node credentials, SA image pull secrets, and pod spec image pull secrets. More info: https://kubernetes.io/docs/concepts/containers/images This field is optional to allow higher level config management to default or override container images in workload controllers like Deployments and StatefulSets.",
126                    "type": "string",
127                },
128            },
129        })
130    }
131}