#
k8s_openapi/v1_35/api/scheduling/v1alpha1/
workload.rs

    1// Generated from definition io.k8s.api.scheduling.v1alpha1.Workload
    2
    3/// Workload allows for expressing scheduling constraints that should be used when managing lifecycle of workloads from scheduling perspective, including scheduling, preemption, eviction and other phases.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Workload {
    6    /// Standard object's metadata. Name must be a DNS subdomain.
    7    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    8
    9    /// Spec defines the desired behavior of a Workload.
    10    pub spec: crate::api::scheduling::v1alpha1::WorkloadSpec,
    11}
    12
    13impl crate::Resource for Workload {
    14    const API_VERSION: &'static str = "scheduling.k8s.io/v1alpha1";
    15    const GROUP: &'static str = "scheduling.k8s.io";
    16    const KIND: &'static str = "Workload";
    17    const VERSION: &'static str = "v1alpha1";
    18    const URL_PATH_SEGMENT: &'static str = "workloads";
    19    type Scope = crate::NamespaceResourceScope;
    20}
    21
    22impl crate::ListableResource for Workload {
    23    const LIST_KIND: &'static str = "WorkloadList";
    24}
    25
    26impl crate::Metadata for Workload {
    27    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    28
    29    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    30        &self.metadata
    31    }
    32
    33    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    34        &mut self.metadata
    35    }
    36}
    37
    38impl crate::DeepMerge for Workload {
    39    fn merge_from(&mut self, other: Self) {
    40        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    41        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
    42    }
    43}
    44
    45impl<'de> crate::serde::Deserialize<'de> for Workload {
    46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    47        #[allow(non_camel_case_types)]
    48        enum Field {
    49            Key_api_version,
    50            Key_kind,
    51            Key_metadata,
    52            Key_spec,
    53            Other,
    54        }
    55
    56        impl<'de> crate::serde::Deserialize<'de> for Field {
    57            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    58                struct Visitor;
    59
    60                impl crate::serde::de::Visitor<'_> for Visitor {
    61                    type Value = Field;
    62
    63                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    64                        f.write_str("field identifier")
    65                    }
    66
    67                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    68                        Ok(match v {
    69                            "apiVersion" => Field::Key_api_version,
    70                            "kind" => Field::Key_kind,
    71                            "metadata" => Field::Key_metadata,
    72                            "spec" => Field::Key_spec,
    73                            _ => Field::Other,
    74                        })
    75                    }
    76                }
    77
    78                deserializer.deserialize_identifier(Visitor)
    79            }
    80        }
    81
    82        struct Visitor;
    83
    84        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    85            type Value = Workload;
    86
    87            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    88                f.write_str(<Self::Value as crate::Resource>::KIND)
    89            }
    90
    91            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    92                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    93                let mut value_spec: Option<crate::api::scheduling::v1alpha1::WorkloadSpec> = None;
    94
    95                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    96                    match key {
    97                        Field::Key_api_version => {
    98                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    99                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    100                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    101                            }
    102                        },
    103                        Field::Key_kind => {
    104                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    105                            if value_kind != <Self::Value as crate::Resource>::KIND {
    106                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    107                            }
    108                        },
    109                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
    111                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    112                    }
    113                }
    114
    115                Ok(Workload {
    116                    metadata: value_metadata.unwrap_or_default(),
    117                    spec: value_spec.unwrap_or_default(),
    118                })
    119            }
    120        }
    121
    122        deserializer.deserialize_struct(
    123            <Self as crate::Resource>::KIND,
    124            &[
    125                "apiVersion",
    126                "kind",
    127                "metadata",
    128                "spec",
    129            ],
    130            Visitor,
    131        )
    132    }
    133}
    134
    135impl crate::serde::Serialize for Workload {
    136    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    137        let mut state = serializer.serialize_struct(
    138            <Self as crate::Resource>::KIND,
    139            4,
    140        )?;
    141        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    142        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    143        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    144        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
    145        crate::serde::ser::SerializeStruct::end(state)
    146    }
    147}
    148
    149#[cfg(feature = "schemars")]
    150impl crate::schemars::JsonSchema for Workload {
    151    fn schema_name() -> std::borrow::Cow<'static, str> {
    152        "io.k8s.api.scheduling.v1alpha1.Workload".into()
    153    }
    154
    155    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    156        crate::schemars::json_schema!({
    157            "description": "Workload allows for expressing scheduling constraints that should be used when managing lifecycle of workloads from scheduling perspective, including scheduling, preemption, eviction and other phases.",
    158            "type": "object",
    159            "properties": {
    160                "apiVersion": {
    161                    "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",
    162                    "type": "string",
    163                },
    164                "kind": {
    165                    "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",
    166                    "type": "string",
    167                },
    168                "metadata": ({
    169                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    170                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. Name must be a DNS subdomain.".into());
    171                    schema_obj
    172                }),
    173                "spec": ({
    174                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha1::WorkloadSpec>();
    175                    schema_obj.ensure_object().insert("description".into(), "Spec defines the desired behavior of a Workload.".into());
    176                    schema_obj
    177                }),
    178            },
    179            "required": [
    180                "metadata",
    181                "spec",
    182            ],
    183        })
    184    }
    185}