#
k8s_openapi/v1_35/api/core/v1/
seccomp_profile.rs

    1// Generated from definition io.k8s.api.core.v1.SeccompProfile
    2
    3/// SeccompProfile defines a pod/container's seccomp profile settings. Only one profile source may be set.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct SeccompProfile {
    6    /// localhostProfile indicates a profile defined in a file on the node should be used. The profile must be preconfigured on the node to work. Must be a descending path, relative to the kubelet's configured seccomp profile location. Must be set if type is "Localhost". Must NOT be set for any other type.
    7    pub localhost_profile: Option<std::string::String>,
    8
    9    /// type indicates which kind of seccomp profile will be applied. Valid options are:
    10    ///
    11    /// Localhost - a profile defined in a file on the node should be used. RuntimeDefault - the container runtime default profile should be used. Unconfined - no profile should be applied.
    12    pub type_: std::string::String,
    13}
    14
    15impl crate::DeepMerge for SeccompProfile {
    16    fn merge_from(&mut self, other: Self) {
    17        crate::DeepMerge::merge_from(&mut self.localhost_profile, other.localhost_profile);
    18        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
    19    }
    20}
    21
    22impl<'de> crate::serde::Deserialize<'de> for SeccompProfile {
    23    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    24        #[allow(non_camel_case_types)]
    25        enum Field {
    26            Key_localhost_profile,
    27            Key_type_,
    28            Other,
    29        }
    30
    31        impl<'de> crate::serde::Deserialize<'de> for Field {
    32            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    33                struct Visitor;
    34
    35                impl crate::serde::de::Visitor<'_> for Visitor {
    36                    type Value = Field;
    37
    38                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    39                        f.write_str("field identifier")
    40                    }
    41
    42                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    43                        Ok(match v {
    44                            "localhostProfile" => Field::Key_localhost_profile,
    45                            "type" => Field::Key_type_,
    46                            _ => Field::Other,
    47                        })
    48                    }
    49                }
    50
    51                deserializer.deserialize_identifier(Visitor)
    52            }
    53        }
    54
    55        struct Visitor;
    56
    57        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    58            type Value = SeccompProfile;
    59
    60            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    61                f.write_str("SeccompProfile")
    62            }
    63
    64            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    65                let mut value_localhost_profile: Option<std::string::String> = None;
    66                let mut value_type_: Option<std::string::String> = None;
    67
    68                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    69                    match key {
    70                        Field::Key_localhost_profile => value_localhost_profile = crate::serde::de::MapAccess::next_value(&mut map)?,
    71                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
    72                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    73                    }
    74                }
    75
    76                Ok(SeccompProfile {
    77                    localhost_profile: value_localhost_profile,
    78                    type_: value_type_.unwrap_or_default(),
    79                })
    80            }
    81        }
    82
    83        deserializer.deserialize_struct(
    84            "SeccompProfile",
    85            &[
    86                "localhostProfile",
    87                "type",
    88            ],
    89            Visitor,
    90        )
    91    }
    92}
    93
    94impl crate::serde::Serialize for SeccompProfile {
    95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    96        let mut state = serializer.serialize_struct(
    97            "SeccompProfile",
    98            1 +
    99            self.localhost_profile.as_ref().map_or(0, |_| 1),
    100        )?;
    101        if let Some(value) = &self.localhost_profile {
    102            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "localhostProfile", value)?;
    103        }
    104        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
    105        crate::serde::ser::SerializeStruct::end(state)
    106    }
    107}
    108
    109#[cfg(feature = "schemars")]
    110impl crate::schemars::JsonSchema for SeccompProfile {
    111    fn schema_name() -> std::borrow::Cow<'static, str> {
    112        "io.k8s.api.core.v1.SeccompProfile".into()
    113    }
    114
    115    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    116        crate::schemars::json_schema!({
    117            "description": "SeccompProfile defines a pod/container's seccomp profile settings. Only one profile source may be set.",
    118            "type": "object",
    119            "properties": {
    120                "localhostProfile": {
    121                    "description": "localhostProfile indicates a profile defined in a file on the node should be used. The profile must be preconfigured on the node to work. Must be a descending path, relative to the kubelet's configured seccomp profile location. Must be set if type is \"Localhost\". Must NOT be set for any other type.",
    122                    "type": "string",
    123                },
    124                "type": {
    125                    "description": "type indicates which kind of seccomp profile will be applied. Valid options are:\n\nLocalhost - a profile defined in a file on the node should be used. RuntimeDefault - the container runtime default profile should be used. Unconfined - no profile should be applied.",
    126                    "type": "string",
    127                },
    128            },
    129            "required": [
    130                "type",
    131            ],
    132        })
    133    }
    134}