#
k8s_openapi/v1_35/api/node/v1/
runtime_class.rs

    1// Generated from definition io.k8s.api.node.v1.RuntimeClass
    2
    3/// RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod.  For more details, see https://kubernetes.io/docs/concepts/containers/runtime-class/
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct RuntimeClass {
    6    /// handler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration.  It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called "runc" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The Handler must be lowercase, conform to the DNS Label (RFC 1123) requirements, and is immutable.
    7    pub handler: std::string::String,
    8
    9    /// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    10    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    11
    12    /// overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see
    13    ///  https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/
    14    pub overhead: Option<crate::api::node::v1::Overhead>,
    15
    16    /// scheduling holds the scheduling constraints to ensure that pods running with this RuntimeClass are scheduled to nodes that support it. If scheduling is nil, this RuntimeClass is assumed to be supported by all nodes.
    17    pub scheduling: Option<crate::api::node::v1::Scheduling>,
    18}
    19
    20impl crate::Resource for RuntimeClass {
    21    const API_VERSION: &'static str = "node.k8s.io/v1";
    22    const GROUP: &'static str = "node.k8s.io";
    23    const KIND: &'static str = "RuntimeClass";
    24    const VERSION: &'static str = "v1";
    25    const URL_PATH_SEGMENT: &'static str = "runtimeclasses";
    26    type Scope = crate::ClusterResourceScope;
    27}
    28
    29impl crate::ListableResource for RuntimeClass {
    30    const LIST_KIND: &'static str = "RuntimeClassList";
    31}
    32
    33impl crate::Metadata for RuntimeClass {
    34    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    35
    36    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    37        &self.metadata
    38    }
    39
    40    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    41        &mut self.metadata
    42    }
    43}
    44
    45impl crate::DeepMerge for RuntimeClass {
    46    fn merge_from(&mut self, other: Self) {
    47        crate::DeepMerge::merge_from(&mut self.handler, other.handler);
    48        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    49        crate::DeepMerge::merge_from(&mut self.overhead, other.overhead);
    50        crate::DeepMerge::merge_from(&mut self.scheduling, other.scheduling);
    51    }
    52}
    53
    54impl<'de> crate::serde::Deserialize<'de> for RuntimeClass {
    55    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    56        #[allow(non_camel_case_types)]
    57        enum Field {
    58            Key_api_version,
    59            Key_kind,
    60            Key_handler,
    61            Key_metadata,
    62            Key_overhead,
    63            Key_scheduling,
    64            Other,
    65        }
    66
    67        impl<'de> crate::serde::Deserialize<'de> for Field {
    68            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    69                struct Visitor;
    70
    71                impl crate::serde::de::Visitor<'_> for Visitor {
    72                    type Value = Field;
    73
    74                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    75                        f.write_str("field identifier")
    76                    }
    77
    78                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    79                        Ok(match v {
    80                            "apiVersion" => Field::Key_api_version,
    81                            "kind" => Field::Key_kind,
    82                            "handler" => Field::Key_handler,
    83                            "metadata" => Field::Key_metadata,
    84                            "overhead" => Field::Key_overhead,
    85                            "scheduling" => Field::Key_scheduling,
    86                            _ => Field::Other,
    87                        })
    88                    }
    89                }
    90
    91                deserializer.deserialize_identifier(Visitor)
    92            }
    93        }
    94
    95        struct Visitor;
    96
    97        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    98            type Value = RuntimeClass;
    99
    100            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    101                f.write_str(<Self::Value as crate::Resource>::KIND)
    102            }
    103
    104            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    105                let mut value_handler: Option<std::string::String> = None;
    106                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    107                let mut value_overhead: Option<crate::api::node::v1::Overhead> = None;
    108                let mut value_scheduling: Option<crate::api::node::v1::Scheduling> = None;
    109
    110                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    111                    match key {
    112                        Field::Key_api_version => {
    113                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    114                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    115                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    116                            }
    117                        },
    118                        Field::Key_kind => {
    119                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    120                            if value_kind != <Self::Value as crate::Resource>::KIND {
    121                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    122                            }
    123                        },
    124                        Field::Key_handler => value_handler = crate::serde::de::MapAccess::next_value(&mut map)?,
    125                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    126                        Field::Key_overhead => value_overhead = crate::serde::de::MapAccess::next_value(&mut map)?,
    127                        Field::Key_scheduling => value_scheduling = crate::serde::de::MapAccess::next_value(&mut map)?,
    128                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    129                    }
    130                }
    131
    132                Ok(RuntimeClass {
    133                    handler: value_handler.unwrap_or_default(),
    134                    metadata: value_metadata.unwrap_or_default(),
    135                    overhead: value_overhead,
    136                    scheduling: value_scheduling,
    137                })
    138            }
    139        }
    140
    141        deserializer.deserialize_struct(
    142            <Self as crate::Resource>::KIND,
    143            &[
    144                "apiVersion",
    145                "kind",
    146                "handler",
    147                "metadata",
    148                "overhead",
    149                "scheduling",
    150            ],
    151            Visitor,
    152        )
    153    }
    154}
    155
    156impl crate::serde::Serialize for RuntimeClass {
    157    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    158        let mut state = serializer.serialize_struct(
    159            <Self as crate::Resource>::KIND,
    160            4 +
    161            self.overhead.as_ref().map_or(0, |_| 1) +
    162            self.scheduling.as_ref().map_or(0, |_| 1),
    163        )?;
    164        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    165        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    166        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "handler", &self.handler)?;
    167        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    168        if let Some(value) = &self.overhead {
    169            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "overhead", value)?;
    170        }
    171        if let Some(value) = &self.scheduling {
    172            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scheduling", value)?;
    173        }
    174        crate::serde::ser::SerializeStruct::end(state)
    175    }
    176}
    177
    178#[cfg(feature = "schemars")]
    179impl crate::schemars::JsonSchema for RuntimeClass {
    180    fn schema_name() -> std::borrow::Cow<'static, str> {
    181        "io.k8s.api.node.v1.RuntimeClass".into()
    182    }
    183
    184    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    185        crate::schemars::json_schema!({
    186            "description": "RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod.  For more details, see https://kubernetes.io/docs/concepts/containers/runtime-class/",
    187            "type": "object",
    188            "properties": {
    189                "apiVersion": {
    190                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    191                    "type": "string",
    192                },
    193                "handler": {
    194                    "description": "handler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration.  It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The Handler must be lowercase, conform to the DNS Label (RFC 1123) requirements, and is immutable.",
    195                    "type": "string",
    196                },
    197                "kind": {
    198                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    199                    "type": "string",
    200                },
    201                "metadata": ({
    202                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    203                    schema_obj.ensure_object().insert("description".into(), "More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    204                    schema_obj
    205                }),
    206                "overhead": ({
    207                    let mut schema_obj = __gen.subschema_for::<crate::api::node::v1::Overhead>();
    208                    schema_obj.ensure_object().insert("description".into(), "overhead represents the resource overhead associated with running a pod for a given RuntimeClass. For more details, see\n https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/".into());
    209                    schema_obj
    210                }),
    211                "scheduling": ({
    212                    let mut schema_obj = __gen.subschema_for::<crate::api::node::v1::Scheduling>();
    213                    schema_obj.ensure_object().insert("description".into(), "scheduling holds the scheduling constraints to ensure that pods running with this RuntimeClass are scheduled to nodes that support it. If scheduling is nil, this RuntimeClass is assumed to be supported by all nodes.".into());
    214                    schema_obj
    215                }),
    216            },
    217            "required": [
    218                "handler",
    219                "metadata",
    220            ],
    221        })
    222    }
    223}