#
k8s_openapi/v1_35/api/scheduling/v1/
priority_class.rs

    1// Generated from definition io.k8s.api.scheduling.v1.PriorityClass
    2
    3/// PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct PriorityClass {
    6    /// description is an arbitrary string that usually provides guidelines on when this priority class should be used.
    7    pub description: Option<std::string::String>,
    8
    9    /// globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.
    10    pub global_default: Option<bool>,
    11
    12    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    14
    15    /// preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.
    16    pub preemption_policy: Option<std::string::String>,
    17
    18    /// value represents the integer value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.
    19    pub value: i32,
    20}
    21
    22impl crate::Resource for PriorityClass {
    23    const API_VERSION: &'static str = "scheduling.k8s.io/v1";
    24    const GROUP: &'static str = "scheduling.k8s.io";
    25    const KIND: &'static str = "PriorityClass";
    26    const VERSION: &'static str = "v1";
    27    const URL_PATH_SEGMENT: &'static str = "priorityclasses";
    28    type Scope = crate::ClusterResourceScope;
    29}
    30
    31impl crate::ListableResource for PriorityClass {
    32    const LIST_KIND: &'static str = "PriorityClassList";
    33}
    34
    35impl crate::Metadata for PriorityClass {
    36    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    37
    38    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    39        &self.metadata
    40    }
    41
    42    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    43        &mut self.metadata
    44    }
    45}
    46
    47impl crate::DeepMerge for PriorityClass {
    48    fn merge_from(&mut self, other: Self) {
    49        crate::DeepMerge::merge_from(&mut self.description, other.description);
    50        crate::DeepMerge::merge_from(&mut self.global_default, other.global_default);
    51        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    52        crate::DeepMerge::merge_from(&mut self.preemption_policy, other.preemption_policy);
    53        crate::DeepMerge::merge_from(&mut self.value, other.value);
    54    }
    55}
    56
    57impl<'de> crate::serde::Deserialize<'de> for PriorityClass {
    58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    59        #[allow(non_camel_case_types)]
    60        enum Field {
    61            Key_api_version,
    62            Key_kind,
    63            Key_description,
    64            Key_global_default,
    65            Key_metadata,
    66            Key_preemption_policy,
    67            Key_value,
    68            Other,
    69        }
    70
    71        impl<'de> crate::serde::Deserialize<'de> for Field {
    72            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    73                struct Visitor;
    74
    75                impl crate::serde::de::Visitor<'_> for Visitor {
    76                    type Value = Field;
    77
    78                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    79                        f.write_str("field identifier")
    80                    }
    81
    82                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    83                        Ok(match v {
    84                            "apiVersion" => Field::Key_api_version,
    85                            "kind" => Field::Key_kind,
    86                            "description" => Field::Key_description,
    87                            "globalDefault" => Field::Key_global_default,
    88                            "metadata" => Field::Key_metadata,
    89                            "preemptionPolicy" => Field::Key_preemption_policy,
    90                            "value" => Field::Key_value,
    91                            _ => Field::Other,
    92                        })
    93                    }
    94                }
    95
    96                deserializer.deserialize_identifier(Visitor)
    97            }
    98        }
    99
    100        struct Visitor;
    101
    102        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    103            type Value = PriorityClass;
    104
    105            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    106                f.write_str(<Self::Value as crate::Resource>::KIND)
    107            }
    108
    109            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    110                let mut value_description: Option<std::string::String> = None;
    111                let mut value_global_default: Option<bool> = None;
    112                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    113                let mut value_preemption_policy: Option<std::string::String> = None;
    114                let mut value_value: Option<i32> = None;
    115
    116                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    117                    match key {
    118                        Field::Key_api_version => {
    119                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    120                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    121                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    122                            }
    123                        },
    124                        Field::Key_kind => {
    125                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    126                            if value_kind != <Self::Value as crate::Resource>::KIND {
    127                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    128                            }
    129                        },
    130                        Field::Key_description => value_description = crate::serde::de::MapAccess::next_value(&mut map)?,
    131                        Field::Key_global_default => value_global_default = crate::serde::de::MapAccess::next_value(&mut map)?,
    132                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    133                        Field::Key_preemption_policy => value_preemption_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
    134                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
    135                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    136                    }
    137                }
    138
    139                Ok(PriorityClass {
    140                    description: value_description,
    141                    global_default: value_global_default,
    142                    metadata: value_metadata.unwrap_or_default(),
    143                    preemption_policy: value_preemption_policy,
    144                    value: value_value.unwrap_or_default(),
    145                })
    146            }
    147        }
    148
    149        deserializer.deserialize_struct(
    150            <Self as crate::Resource>::KIND,
    151            &[
    152                "apiVersion",
    153                "kind",
    154                "description",
    155                "globalDefault",
    156                "metadata",
    157                "preemptionPolicy",
    158                "value",
    159            ],
    160            Visitor,
    161        )
    162    }
    163}
    164
    165impl crate::serde::Serialize for PriorityClass {
    166    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    167        let mut state = serializer.serialize_struct(
    168            <Self as crate::Resource>::KIND,
    169            4 +
    170            self.description.as_ref().map_or(0, |_| 1) +
    171            self.global_default.as_ref().map_or(0, |_| 1) +
    172            self.preemption_policy.as_ref().map_or(0, |_| 1),
    173        )?;
    174        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    175        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    176        if let Some(value) = &self.description {
    177            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "description", value)?;
    178        }
    179        if let Some(value) = &self.global_default {
    180            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "globalDefault", value)?;
    181        }
    182        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    183        if let Some(value) = &self.preemption_policy {
    184            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preemptionPolicy", value)?;
    185        }
    186        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", &self.value)?;
    187        crate::serde::ser::SerializeStruct::end(state)
    188    }
    189}
    190
    191#[cfg(feature = "schemars")]
    192impl crate::schemars::JsonSchema for PriorityClass {
    193    fn schema_name() -> std::borrow::Cow<'static, str> {
    194        "io.k8s.api.scheduling.v1.PriorityClass".into()
    195    }
    196
    197    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    198        crate::schemars::json_schema!({
    199            "description": "PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.",
    200            "type": "object",
    201            "properties": {
    202                "apiVersion": {
    203                    "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",
    204                    "type": "string",
    205                },
    206                "description": {
    207                    "description": "description is an arbitrary string that usually provides guidelines on when this priority class should be used.",
    208                    "type": "string",
    209                },
    210                "globalDefault": {
    211                    "description": "globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.",
    212                    "type": "boolean",
    213                },
    214                "kind": {
    215                    "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",
    216                    "type": "string",
    217                },
    218                "metadata": ({
    219                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    220                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    221                    schema_obj
    222                }),
    223                "preemptionPolicy": {
    224                    "description": "preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
    225                    "type": "string",
    226                },
    227                "value": {
    228                    "description": "value represents the integer value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.",
    229                    "type": "integer",
    230                    "format": "int32",
    231                },
    232            },
    233            "required": [
    234                "metadata",
    235                "value",
    236            ],
    237        })
    238    }
    239}