k8s_openapi/v1_32/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: 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 std::fmt::Formatter<'_>) -> std::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 std::fmt::Formatter<'_>) -> std::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<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: 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: 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() -> String {
181        "io.k8s.api.node.v1.RuntimeClass".to_owned()
182    }
183
184    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
185        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
186            metadata: Some(Box::new(crate::schemars::schema::Metadata {
187                description: Some("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/".to_owned()),
188                ..Default::default()
189            })),
190            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
191            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
192                properties: [
193                    (
194                        "apiVersion".to_owned(),
195                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
196                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
197                                description: Some("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".to_owned()),
198                                ..Default::default()
199                            })),
200                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
201                            ..Default::default()
202                        }),
203                    ),
204                    (
205                        "handler".to_owned(),
206                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
207                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
208                                description: Some("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.".to_owned()),
209                                ..Default::default()
210                            })),
211                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
212                            ..Default::default()
213                        }),
214                    ),
215                    (
216                        "kind".to_owned(),
217                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
218                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
219                                description: Some("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".to_owned()),
220                                ..Default::default()
221                            })),
222                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
223                            ..Default::default()
224                        }),
225                    ),
226                    (
227                        "metadata".to_owned(),
228                        {
229                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
230                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
231                                description: Some("More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".to_owned()),
232                                ..Default::default()
233                            }));
234                            crate::schemars::schema::Schema::Object(schema_obj)
235                        },
236                    ),
237                    (
238                        "overhead".to_owned(),
239                        {
240                            let mut schema_obj = __gen.subschema_for::<crate::api::node::v1::Overhead>().into_object();
241                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
242                                description: Some("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/".to_owned()),
243                                ..Default::default()
244                            }));
245                            crate::schemars::schema::Schema::Object(schema_obj)
246                        },
247                    ),
248                    (
249                        "scheduling".to_owned(),
250                        {
251                            let mut schema_obj = __gen.subschema_for::<crate::api::node::v1::Scheduling>().into_object();
252                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
253                                description: Some("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.".to_owned()),
254                                ..Default::default()
255                            }));
256                            crate::schemars::schema::Schema::Object(schema_obj)
257                        },
258                    ),
259                ].into(),
260                required: [
261                    "handler".to_owned(),
262                    "metadata".to_owned(),
263                ].into(),
264                ..Default::default()
265            })),
266            ..Default::default()
267        })
268    }
269}